diff --git a/nodes/Plutio/Plutio.node.ts b/nodes/Plutio/Plutio.node.ts index de6083f..4d82ad6 100644 --- a/nodes/Plutio/Plutio.node.ts +++ b/nodes/Plutio/Plutio.node.ts @@ -19,11 +19,7 @@ import { projectDescription, projectOperations, taskDescription, - taskOperations, - companiesDescription, - companiesOperations, - peopleDescription, - peopleOperations + taskOperations } from './descriptions'; import { @@ -34,15 +30,12 @@ interface IProperyId {} interface ICreatePlutioBody { assignedTo?: [string]; - followers?: [string]; title?: string; name?: string; taskGroupId?: string; createdBy?: string; templateId?: string; _id?: string; - industry?: string; - address?: IDataObject; descriptionHTML?: string; entityId?: string; entityType?: string; @@ -52,10 +45,6 @@ interface ICreatePlutioBody { taskBoardId?: string; projectId?: string; customFields?: IDataObject[]; - billingCustomFields?: IDataObject[]; - contactPhones?: IDataObject[]; - contactEmails?: IDataObject[]; - people?: IDataObject[]; tax?: IDataObject[]; client?: IDataObject; currency?: string; @@ -64,17 +53,6 @@ interface ICreatePlutioBody { contributors?: [string]; } -interface ICreatePeopleBody { - _id?: string; - name?: IDataObject[]; - role?: string; - status?: string; - company?: string; - contactPhones?: IDataObject[]; - contactEmails?: IDataObject[]; - customFields?: IDataObject[]; -} - export class Plutio implements INodeType { description: INodeTypeDescription = { displayName: 'Plutio', @@ -119,14 +97,6 @@ export class Plutio implements INodeType { name: 'Project', value: 'project', }, - { - name: 'Company', - value: 'company', - }, - { - name: 'People', - value: 'people', - }, ], default: 'task', }, @@ -138,10 +108,6 @@ export class Plutio implements INodeType { ...invoiceDescription, ...projectOperations, ...projectDescription, - ...companiesOperations, - ...companiesDescription, - ...peopleOperations, - ...peopleDescription, ], }; @@ -165,7 +131,7 @@ export class Plutio implements INodeType { return returnData; }, - // Get all the emails to display them to user so that he can + // Get all the people to display them to user so that he can // select them easily async getEmails(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; @@ -183,8 +149,6 @@ export class Plutio implements INodeType { return returnData; }, - // Get all the Task groups to display them to user so that he can - // select them easily async getTaskGroupId(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const ids = await plutioApiRequest.call(this, 'GET', '/task-groups'); @@ -200,8 +164,6 @@ export class Plutio implements INodeType { return returnData; }, - // Get all the Task boards to display them to user so that he can - // select them easily async getTaskBoardId(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const ids = await plutioApiRequest.call(this, 'GET', '/task-boards', {}, ); @@ -217,8 +179,6 @@ export class Plutio implements INodeType { return returnData; }, - // Get all the Task templates to display them to user so that he can - // select them easily async getTaskTemplateId(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const ids = await plutioApiRequest.call(this, 'GET', '/templates', {}, {'entityType': 'task'}); @@ -234,8 +194,6 @@ export class Plutio implements INodeType { return returnData; }, - // Get all the invoice templates to display them to user so that he can - // select them easily async getInvoiceTemplateId(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const ids = await plutioApiRequest.call(this, 'GET', '/templates', {}, {'entityType': 'invoice'}); @@ -251,8 +209,6 @@ export class Plutio implements INodeType { return returnData; }, - // Get all the Project templates to display them to user so that he can - // select them easily async getProjectTemplateId(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const ids = await plutioApiRequest.call(this, 'GET', '/templates', {}, {'entityType': 'project'}); @@ -268,8 +224,6 @@ export class Plutio implements INodeType { return returnData; }, - // Get all the project ID/Name to display them to user so that he can - // select them easily async getProjectId(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const ids = await plutioApiRequest.call(this, 'GET', '/projects'); @@ -287,7 +241,7 @@ export class Plutio implements INodeType { // Get all the custom fields to display them to user so that he can // select them easily - async getTaskCustomField(this: ILoadOptionsFunctions): Promise { + async getCustomFieldTitle(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const fields = await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, {'entityType': 'task'}); for (const field of fields) { @@ -304,46 +258,6 @@ export class Plutio implements INodeType { return returnData; }, - // Get all the company custom fields to display them to user so that he can - // select them easily - async getCompanyCustomField(this: ILoadOptionsFunctions): Promise { - const returnData: INodePropertyOptions[] = []; - const fields = await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, {'entityType': 'company'}); - for (const field of fields) { - if ('company' === field.entityType) { - const fieldName = field.title; - const fieldValue = field._id; - - returnData.push({ - name: fieldName, - value: fieldValue, - }); - } - } - return returnData; - }, - - // Get all the custom fields to display them to user so that he can - // select them easily - async getPeopleCustomField(this: ILoadOptionsFunctions): Promise { - const returnData: INodePropertyOptions[] = []; - const fields = await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, {'entityType': 'person'}); - for (const field of fields) { - if ('person' === field.entityType) { - const fieldName = field.title; - const fieldValue = field._id; - - returnData.push({ - name: fieldName, - value: fieldValue, - }); - } - } - return returnData; - }, - - // Get all the project custom fields to display them to user so that he can - // select them easily async getProjectCustomField(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const fields = await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, {'entityType': 'project'}); @@ -373,14 +287,9 @@ export class Plutio implements INodeType { for (let i = 0; i < items.length; i++) { try { - - // Execute Task. if ('task' === resource) { - - // Create Task if ('create' === operation) { const assignees = this.getNodeParameter('assignees', i) as IDataObject; - const followedBy = this.getNodeParameter('followers', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject; if (options.projectId) { @@ -473,6 +382,7 @@ export class Plutio implements INodeType { const metadata = (assignees as IDataObject).assignee as IDataObject[]; let assignedTo: IProperyId[] = []; const users: IProperyId[] = []; + if (metadata) { // Push all assignees to a single array. @@ -503,52 +413,11 @@ export class Plutio implements INodeType { body.assignedTo = assignedTo as [string]; } - - // add followers to user - if (followedBy) { - const metadata = (followedBy as IDataObject).follower as IDataObject[]; - let followers: IProperyId[] = []; - const users: IProperyId[] = []; - - if (metadata) { - - // Push all assignees to a single array. - for (const data of metadata) { - followers.push(data.value as IDataObject); - } - - // flatten followers array. - followers = followers.flatMap(a => a); - - const customQs = {'status': 'active'}; - await plutioApiRequest.call(this, 'GET', '/people', {}, customQs).then(people => { - for (const id of followers) { - for (const person of people) { - const userName = (person.name.last) ? `${person.name.first} ${person.name.last}` : `${person.name.first}`; - if (id === person._id || id === userName) { - users.push(person._id); - } - } - } - }); - } - - // remove duplicates. - followers = users.filter((c, index) => { - return users.indexOf(c) === index; - }); - - body.followers = followers as [string]; - } - responseData = await plutioApiRequest.call(this, 'POST', '/tasks', body); } - - // Update Task. if ('update' === operation) { const _id = this.getNodeParameter('_id', 0) as string; const assignees = this.getNodeParameter('assignees', i) as IDataObject; - const followedBy = this.getNodeParameter('followers', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject; if (_id) { @@ -641,27 +510,25 @@ export class Plutio implements INodeType { let assignedTo: IProperyId[] = []; const users: IProperyId[] = []; - if (metadata) { - // Push all assignees to a single array. - for (const data of metadata) { - assignedTo.push(data.value as IDataObject); - } + // Push all assignees to a single array. + for (const data of metadata) { + assignedTo.push(data.value as IDataObject); + } - // flatten assignedTo array. - assignedTo = assignedTo.flatMap(a => a); + // flatten assignedTo array. + assignedTo = assignedTo.flatMap(a => a); - const customQs = {'status': 'active'}; - await plutioApiRequest.call(this, 'GET', '/people', {}, customQs).then(people => { - for (const id of assignedTo) { - for (const person of people) { - const userName = (person.name.last) ? `${person.name.first} ${person.name.last}` : `${person.name.first}`; - if (id === person._id || id === userName) { - users.push(person._id); - } + const customQs = {'status': 'active'}; + await plutioApiRequest.call(this, 'GET', '/people', {}, customQs).then(people => { + for (const id of assignedTo) { + for (const person of people) { + const userName = (person.name.last) ? `${person.name.first} ${person.name.last}` : `${person.name.first}`; + if (id === person._id || id === userName) { + users.push(person._id); } } - }); - } + } + }); // remove duplicates. assignedTo = users.filter((c, index) => { @@ -670,48 +537,8 @@ export class Plutio implements INodeType { body.assignedTo = assignedTo as [string]; } - - // add followers to user - if (followedBy) { - const metadata = (followedBy as IDataObject).follower as IDataObject[]; - let followers: IProperyId[] = []; - const users: IProperyId[] = []; - - if (metadata) { - - // Push all assignees to a single array. - for (const data of metadata) { - followers.push(data.value as IDataObject); - } - - // flatten followers array. - followers = followers.flatMap(a => a); - - const customQs = {'status': 'active'}; - await plutioApiRequest.call(this, 'GET', '/people', {}, customQs).then(people => { - for (const id of followers) { - for (const person of people) { - const userName = (person.name.last) ? `${person.name.first} ${person.name.last}` : `${person.name.first}`; - if (id === person._id || id === userName) { - users.push(person._id); - } - } - } - }); - } - - // remove duplicates. - followers = users.filter((c, index) => { - return users.indexOf(c) === index; - }); - - body.followers = followers as [string]; - } - responseData = await plutioApiRequest.call(this, 'PUT', '/tasks', body); } - - // Get Task. if ('get' === operation) { const options = this.getNodeParameter('options', i) as IDataObject; @@ -766,8 +593,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'GET', '/tasks', {}, qs); } - - // Copy Task. if ('copy' === operation) { const _id = this.getNodeParameter('_id', 0) as string; const taskGroupId = this.getNodeParameter('taskGroupId', 0) as string; @@ -791,8 +616,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'POST', '/tasks/copy', body); } - - // Move Task. if ('move' === operation) { const _id = this.getNodeParameter('_id', 0) as string; const taskGroupId = this.getNodeParameter('taskGroupId', 0) as string; @@ -816,8 +639,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'POST', '/tasks/move', body); } - - // Delete Task. if ('delete' === operation) { const _id = this.getNodeParameter('_id', 0) as string; if (_id) { @@ -826,11 +647,7 @@ export class Plutio implements INodeType { responseData = await plutioApiRequest.call(this, 'DELETE', '/tasks', body); } } - - // Execute Comments. if ('comment' === resource) { - - // Create Comment. if ('create' === operation) { const entityId = this.getNodeParameter('entityId', i) as string; const entityType = this.getNodeParameter('entityType', i) as string; @@ -847,8 +664,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'POST', '/comments', body); } - - // Get Comment. if ('get' === operation) { const entityId = this.getNodeParameter('entityId', i) as string; const entityType = this.getNodeParameter('entityType', i) as string; @@ -861,8 +676,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'GET', '/comments', {}, qs); } - - // Update Comment. if ('update' === operation) { const _id = this.getNodeParameter('_id', i) as string; const bodyHTML = this.getNodeParameter('bodyHTML', i) as string; @@ -875,8 +688,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'PUT', '/comments', body); } - - // Delete Comment. if ('delete' === operation) { const _id = this.getNodeParameter('_id', 0) as string; @@ -886,11 +697,7 @@ export class Plutio implements INodeType { responseData = await plutioApiRequest.call(this, 'DELETE', '/comments', body); } } - - // execute Invoice. if ('invoice' === resource) { - - // Create Invoice. if ('create' === operation) { const taxUi = this.getNodeParameter('taxUi', i) as IDataObject; const clientUi = this.getNodeParameter('clientUi', i) as IDataObject; @@ -941,8 +748,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'POST', '/invoices', body); } - - // Get Invoice. if ('get' === operation) { const options = this.getNodeParameter('options', i) as IDataObject; @@ -963,8 +768,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'GET', '/invoices', {}, qs); } - - // Update Invoice. if ('update' === operation) { const _id = this.getNodeParameter('_id', 0) as string; const options = this.getNodeParameter('options', i) as IDataObject; @@ -1014,8 +817,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'PUT', '/invoices', body); } - - // Delete Invoice. if ('delete' === operation) { const _id = this.getNodeParameter('_id', 0) as string; if (_id) { @@ -1024,11 +825,7 @@ export class Plutio implements INodeType { responseData = await plutioApiRequest.call(this, 'DELETE', '/invoices', body); } } - - // Execute Project. if ('project' === resource) { - - // Get Project. if ('get' === operation) { const options = this.getNodeParameter('options', i) as IDataObject; @@ -1047,8 +844,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'GET', '/projects', {}, qs); } - - // Create Project. if ('create' === operation) { const options = this.getNodeParameter('options', i) as IDataObject; const customFields = this.getNodeParameter('customFields', i) as IDataObject; @@ -1115,8 +910,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'POST', '/projects', body); } - - // Update Project. if ('update' === operation) { const _id = this.getNodeParameter('_id', 0) as string; const options = this.getNodeParameter('options', i) as IDataObject; @@ -1186,8 +979,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'PUT', '/projects', body); } - - // Move project. if ('move' === operation) { const _id = this.getNodeParameter('_id', 0) as string; const index = this.getNodeParameter('index', 0) as number; @@ -1200,8 +991,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'POST', '/projects/move', body); } - - // Copy Project. if ('copy' === operation) { const _id = this.getNodeParameter('_id', 0) as string; const index = this.getNodeParameter('index', 0) as number; @@ -1214,8 +1003,6 @@ export class Plutio implements INodeType { } responseData = await plutioApiRequest.call(this, 'POST', '/projects/copy', body); } - - // Delete Project. if ('delete' === operation) { const _id = this.getNodeParameter('_id', 0) as string; @@ -1226,358 +1013,6 @@ export class Plutio implements INodeType { } } - // Execute company. - if ('company' === resource) { - - // Create company. - if ('create' === operation) { - const title = this.getNodeParameter('title', 0) as string; - const addresses = this.getNodeParameter('address', i) as IDataObject; - const options = this.getNodeParameter('options', i) as IDataObject; - const people = this.getNodeParameter('people', i) as IDataObject; - - if (title) { - body.title = title as string; - } - if (addresses) { - const metadata = (addresses as IDataObject).address as IDataObject; - body.address = metadata as IDataObject; - } - if (options.industry) { - body.industry = options.industry as string; - } - if (options.customFields) { - const metadata = (options.customFields as IDataObject).customField as IDataObject[]; - if (metadata) { - const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"company"}; - await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, customQs).then(responses => { - for (const data of metadata) { - for (const response of responses) { - if (response._id === data._id) { - for (const option of response.options) { - if (option.name === data.value) { - data.value = (option.name as string).replace(/^[(a-zA-Z\s)]*$/g, option._id); - } - } - } - } - } - }); - } - body.customFields = metadata; - delete options.customFields; - } - if (options.billingCustomFields) { - const metadata = (options.billingCustomFields as IDataObject).customField as IDataObject[]; - if (metadata) { - const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"company"}; - await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, customQs).then(responses => { - for (const data of metadata) { - for (const response of responses) { - if (response._id === data._id) { - for (const option of response.options) { - if (option.name === data.value) { - data.value = (option.name as string).replace(/^[(a-zA-Z\s)]*$/g, option._id); - } - } - } - } - } - }); - } - body.billingCustomFields = metadata; - delete options.customFields; - } - if (options.phones) { - const metadata = (options.phones as IDataObject).phone as IDataObject[]; - body.contactPhones = metadata; - } - if (options.emails) { - const metadata = (options.emails as IDataObject).email as IDataObject[]; - body.contactEmails = metadata; - } - if (people) { - const metadata = (people as IDataObject).person as IDataObject[]; - const customQs = {'status': 'active'}; - await plutioApiRequest.call(this, 'GET', '/people', {}, customQs).then(people => { - for (const data of metadata) { - for (const person of people) { - const userName = (person.name.last) ? `${person.name.first} ${person.name.last}` : `${person.name.first}`; - if (data._id === person._id || data._id === userName) { - data._id = (data._id as string).replace(/^[(a-zA-Z\s)]*$/g, person._id); - } - } - if (!data.role) { - delete data.role; - } - } - }); - body.people = metadata; - } - responseData = await plutioApiRequest.call(this, 'POST', '/companies', body); - } - - // Update company. - if ('update' === operation) { - const id = this.getNodeParameter('_id', 0) as string; - const title = this.getNodeParameter('title', i) as string; - const addresses = this.getNodeParameter('address', i) as IDataObject; - const options = this.getNodeParameter('options', i) as IDataObject; - const people = this.getNodeParameter('people', i) as IDataObject; - - if (id) { - body._id = id as string; - } - if (title) { - body.title = title as string; - } - if (addresses) { - const metadata = (addresses as IDataObject).address as IDataObject; - body.address = metadata as IDataObject; - } - if (options.industry) { - body.industry = options.industry as string; - } - if (options.customFields) { - const metadata = (options.customFields as IDataObject).customField as IDataObject[]; - if (metadata) { - const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"company"}; - await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, customQs).then(responses => { - for (const data of metadata) { - for (const response of responses) { - if (response._id === data._id) { - for (const option of response.options) { - if (option.name === data.value) { - data.value = (option.name as string).replace(/^[(a-zA-Z\s)]*$/g, option._id); - } - } - } - } - } - }); - } - body.customFields = metadata; - delete options.customFields; - } - if (options.billingCustomFields) { - const metadata = (options.billingCustomFields as IDataObject).customField as IDataObject[]; - if (metadata) { - const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"company"}; - await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, customQs).then(responses => { - for (const data of metadata) { - for (const response of responses) { - if (response._id === data._id) { - for (const option of response.options) { - if (option.name === data.value) { - data.value = (option.name as string).replace(/^[(a-zA-Z\s)]*$/g, option._id); - } - } - } - } - } - }); - } - body.billingCustomFields = metadata; - delete options.billingCustomFields; - } - if (options.phones) { - const metadata = (options.phones as IDataObject).phone as IDataObject[]; - body.contactPhones = metadata; - } - if (options.emails) { - const metadata = (options.emails as IDataObject).email as IDataObject[]; - body.contactEmails = metadata; - } - if (people) { - const metadata = (people as IDataObject).person as IDataObject[]; - const customQs = {'status': 'active'}; - await plutioApiRequest.call(this, 'GET', '/people', {}, customQs).then(people => { - for (const data of metadata) { - for (const person of people) { - const userName = (person.name.last) ? `${person.name.first} ${person.name.last}` : `${person.name.first}`; - if (data._id === person._id || data._id === userName) { - data._id = (data._id as string).replace(/^[(a-zA-Z\s)]*$/g, person._id); - } - } - if (!data.role) { - delete data.role; - } - } - }); - body.people = metadata; - } - responseData = body; - // responseData = await plutioApiRequest.call(this, 'PUT', '/companies', body); - } - - // Get company. - if ('get' === operation) { - const _id = this.getNodeParameter('_id', i) as string; - const title = this.getNodeParameter('title', i) as string; - const industry = this.getNodeParameter('industry', i) as string; - - if (_id) { - qs._id = _id as string; - } - if (title) { - qs.title = title as string; - } - if (industry) { - qs.industry = industry as string; - } - responseData = await plutioApiRequest.call(this, 'GET', '/companies', {}, qs); - } - - // Delete company. - if ('delete' === operation) { - const _id = this.getNodeParameter('_id', 0) as string; - - if (_id) { - body._id = _id as string; - } - responseData = await plutioApiRequest.call(this, 'DELETE', '/companies', body); - } - } - - // Execute People function. - if ('people' === resource) { - - // create people accounts. - if ('create' === operation) { - const name = this.getNodeParameter('name', 0) as IDataObject; - const role = this.getNodeParameter('role', 0) as string; - const options = this.getNodeParameter('options', i) as IDataObject; - const body: ICreatePeopleBody = {}; - - if (name) { - const metadata = (name as IDataObject).customName as IDataObject[]; - body.name = metadata as IDataObject[]; - } - if (role) { - body.role = role as string; - } - if (options.company) { - body.company = options.company as string; - } - if (options.status) { - body.status = options.status as string; - } - if (options.customFields) { - const metadata = (options.customFields as IDataObject).customField as IDataObject[]; - if (metadata) { - const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"person"}; - await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, customQs).then(responses => { - for (const data of metadata) { - for (const response of responses) { - if (response._id === data._id) { - for (const option of response.options) { - if (option.name === data.value) { - data.value = (option.name as string).replace(/^[(a-zA-Z\s)]*$/g, option._id); - } - } - } - } - } - }); - } - body.customFields = metadata as IDataObject[]; - delete options.customFields; - } - if (options.phones) { - const metadata = (options.phones as IDataObject).phone as IDataObject[]; - body.contactPhones = metadata; - } - if (options.emails) { - const metadata = (options.emails as IDataObject).email as IDataObject[]; - body.contactEmails = metadata; - } - responseData = await plutioApiRequest.call(this, 'POST', '/people', body); - } - - // Update people accounts. - if ('update' === operation) { - const _id = this.getNodeParameter('_id', 0) as string; - const name = this.getNodeParameter('name', 0) as IDataObject; - const role = this.getNodeParameter('role', 0) as string; - const options = this.getNodeParameter('options', i) as IDataObject; - const body: ICreatePeopleBody = {}; - - if (_id) { - body._id = _id as string; - } - if (name) { - const metadata = (name as IDataObject).customName as IDataObject[]; - body.name = metadata as IDataObject[]; - } - if (role) { - body.role = role as string; - } - if (options.company) { - body.company = options.company as string; - } - if (options.status) { - body.status = options.status as string; - } - if (options.customFields) { - const metadata = (options.customFields as IDataObject).customField as IDataObject[]; - if (metadata) { - const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"person"}; - await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, customQs).then(responses => { - for (const data of metadata) { - for (const response of responses) { - if (response._id === data._id) { - for (const option of response.options) { - if (option.name === data.value) { - data.value = (option.name as string).replace(/^[(a-zA-Z\s)]*$/g, option._id); - } - } - } - } - } - }); - } - body.customFields = metadata as IDataObject[]; - delete options.customFields; - } - if (options.phones) { - const metadata = (options.phones as IDataObject).phone as IDataObject[]; - body.contactPhones = metadata; - } - if (options.emails) { - const metadata = (options.emails as IDataObject).email as IDataObject[]; - body.contactEmails = metadata; - } - responseData = await plutioApiRequest.call(this, 'PUT', '/people', body); - } - - // Get people. - if ('get' === operation) { - const _id = this.getNodeParameter('_id', i) as string; - const role = this.getNodeParameter('role', i) as string; - - if (_id) { - qs._id = _id as string; - } - if (role) { - qs.role = role as string; - } - responseData = await plutioApiRequest.call(this, 'GET', '/people', {}, qs); - } - - // Delete people. - if ('delete' === operation) { - const _id = this.getNodeParameter('_id', 0) as string; - - if (_id) { - body._id = _id as string; - } - responseData = await plutioApiRequest.call(this, 'DELETE', '/people', body); - } - } - - // END OF EXECUTE FUNCTION. - - // Process Response data. if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]); } else { diff --git a/nodes/Plutio/descriptions/CompaniesDescription.ts b/nodes/Plutio/descriptions/CompaniesDescription.ts deleted file mode 100644 index 20b6b7d..0000000 --- a/nodes/Plutio/descriptions/CompaniesDescription.ts +++ /dev/null @@ -1,372 +0,0 @@ -import { - INodeProperties, -} from 'n8n-workflow'; - -export const companiesOperations: INodeProperties[] = [ - { - displayName: 'Operation', - name: 'operation', - type: 'options', - noDataExpression: true, - required: true, - displayOptions: { - show: { - resource: [ - 'company', - ], - }, - }, - options: [ - { - name: 'Create', - value: 'create', - description: 'Create a new company', - action: 'Create a company', - }, - { - name: 'Get', - value: 'get', - description: 'Get companies', - action: 'Get a company', - }, - { - name: 'Update', - value: 'update', - description: 'Update a company', - action: 'Update a company', - }, - { - name: 'Delete', - value: 'delete', - description: 'Delete a company', - action: 'Delete a company', - }, - ], - default: 'create', - }, -]; - -export const companiesDescription: INodeProperties[] = [ - { - displayName: 'Company ID', - name: '_id', - type: 'string', - default: '', - displayOptions: { - show: { - resource: [ - 'company', - ], - operation: [ - 'update', - 'delete', - 'get', - ], - }, - }, - description: 'ID of Company', - }, - { - displayName: 'Title', - name: 'title', - type: 'string', - default: '', - displayOptions: { - show: { - resource: [ - 'company', - ], - operation: [ - 'create', - 'update', - 'get', - ], - }, - }, - description: 'Company Name or Title', - }, - { - displayName: 'Industry', - name: 'industry', - type: 'string', - default: '', - description: 'Company Industry', - displayOptions: { - show: { - resource: [ - 'company', - ], - operation: [ - 'get', - ], - }, - }, - }, - { - displayName: 'Options', - name: 'options', - type: 'collection', - placeholder: 'Add Option', - default: {}, - displayOptions: { - show: { - resource: [ - 'company', - ], - operation: [ - 'create', - 'update', - ], - }, - }, - options: [ - { - displayName: 'Industry', - name: 'industry', - type: 'string', - default: '', - description: 'Company Industry', - }, - { - displayName: 'Custom Fields', - name: 'customFields', - type: 'fixedCollection', - placeholder: 'Add Custom Field', - typeOptions: { - multipleValues: true, - }, - description: 'Key value pairs containing the name and value of the custom field. Only dates in the format YYYY-MM-DD are accepted as input for custom date fields.', - default: [], - options: [ - { - displayName: 'Custom Field', - name: 'customField', - values: [ - { - displayName: 'Custom Field Name or ID', - name: '_id', - type: 'options', - description: 'Choose from the list, or specify an ID using an expression', - default: '', - typeOptions: { - loadOptionsMethod: 'getCompanyCustomField', - }, - }, - { - displayName: 'Value Name or ID', - name: 'value', - type: 'string', - default: '', - description: 'Custom Field\'s values', - }, - ], - }, - ], - }, - { - displayName: 'Billing Custom Fields', - name: 'billingCustomFields', - type: 'fixedCollection', - placeholder: 'Add Billing Custom Field', - typeOptions: { - multipleValues: true, - }, - description: 'Key value pairs containing the name and value of the custom field. Only dates in the format YYYY-MM-DD are accepted as input for custom date fields.', - default: [], - options: [ - { - displayName: 'Custom Field', - name: 'customField', - values: [ - { - displayName: 'Key', - name: 'key', - type: 'string', - description: 'Billing Custom Field Key', - default: '', - }, - { - displayName: 'Value', - name: 'value', - type: 'string', - default: '', - description: 'Billing Custom Field values', - }, - ], - }, - ], - }, - { - displayName: 'Contact Phones', - name: 'phones', - type: 'fixedCollection', - default: [], - placeholder: 'Add Contact Phones', - typeOptions: { - multipleValues: true, - }, - options: [ - { - displayName: 'Contact Phone', - name: 'phone', - values: [ - { - displayName: 'Phone Number', - name: 'number', - type: 'string', - description: 'Enter Phone Number', - default: '', - }, - { - displayName: 'Type', - name: 'type', - type: 'string', - description: 'Phone Number Type', - default: 'phone', - }, - ], - }, - ], - description: 'Company phone number. Choose from the list, or specify an ID using an expression.', - }, - { - displayName: 'Contact Emails', - name: 'emails', - type: 'fixedCollection', - default: [], - placeholder: 'Add Contact Emails', - typeOptions: { - multipleValues: true, - }, - options: [ - { - displayName: 'Contact Email', - name: 'email', - values: [ - { - displayName: 'Email Address', - name: 'address', - type: 'string', - description: 'Choose from the list, or specify an ID using an expression', - default: '', - }, - { - displayName: 'Type', - name: 'type', - type: 'string', - description: 'Email Type', - default: 'email', - }, - ], - }, - ], - description: 'Company Email Address. Choose from the list, or specify an ID using an expression.', - }, - ], - }, - { - displayName: 'Address', - name: 'address', - type: 'fixedCollection', - placeholder: 'Enter Address', - typeOptions: { - multipleValues: false, - }, - displayOptions: { - show: { - resource: [ - 'company', - ], - operation: [ - 'create', - 'update', - ], - }, - }, - description: 'Enter Street, City, Country, Zip-Code', - default: [], - options: [ - { - displayName: 'Address', - name: 'address', - values: [ - { - displayName: 'Street', - name: 'street', - type: 'string', - description: 'Enter Street', - default: '', - }, - { - displayName: 'City', - name: 'city', - type: 'string', - default: '', - description: 'Enter City', - }, - { - displayName: 'Country', - name: 'country', - type: 'string', - default: '', - description: 'Enter Country', - }, - { - displayName: 'Zip Code', - name: 'zipCode', - type: 'string', - default: '', - description: 'Enter Zip Code', - }, - ], - }, - ], - }, - { - displayName: 'People', - name: 'people', - type: 'fixedCollection', - placeholder: 'Add People', - typeOptions: { - multipleValues: true, - }, - displayOptions: { - show: { - resource: [ - 'company', - ], - operation: [ - 'create', - 'update', - ], - }, - }, - description: 'Add People', - default: [], - options: [ - { - displayName: 'People', - name: 'person', - values: [ - { - displayName: 'Name or ID', - name: '_id', - type: 'options', - description: 'Choose from the list, or specify an ID using an expression', - default: '', - typeOptions: { - loadOptionsMethod: 'getUsers', - }, - }, - { - displayName: 'Role', - name: 'role', - type: 'string', - default: '', - description: 'Person\'s Role', - }, - ], - }, - ], - }, -]; diff --git a/nodes/Plutio/descriptions/TaskDescription.ts b/nodes/Plutio/descriptions/TaskDescription.ts index af1a1ff..3cb536c 100644 --- a/nodes/Plutio/descriptions/TaskDescription.ts +++ b/nodes/Plutio/descriptions/TaskDescription.ts @@ -102,7 +102,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Project Name or ID', name: 'projectId', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { @@ -113,7 +113,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Task Board Name or ID', name: 'taskBoardId', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getTaskBoardId', @@ -123,7 +123,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Task Group Name or ID', name: 'taskGroupId', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getTaskGroupId', @@ -133,7 +133,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Template Name or ID', name: 'templateId', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getTaskTemplateId', @@ -143,7 +143,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Creator Name or ID', name: 'createdBy', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getUsers', @@ -182,10 +182,10 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Custom Field Name or ID', name: '_id', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { - loadOptionsMethod: 'getTaskCustomField', + loadOptionsMethod: 'getCustomFieldTitle', }, }, @@ -231,7 +231,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Assigned To: Name or ID', name: 'value', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getUsers', @@ -242,52 +242,12 @@ export const taskDescription: INodeProperties[] = [ ], description: 'Name or ID of the user to whom the task has been assigned. Choose from the list, or specify an ID using an expression.', }, - { - displayName: 'Followers: Name or ID', - name: 'followers', - type: 'fixedCollection', - default: [], - placeholder: 'Add Person', - typeOptions: { - multipleValues: true, - }, - displayOptions: { - show: { - resource: [ - 'task', - ], - operation: [ - 'update', - 'create', - ], - }, - }, - options: [ - { - displayName: 'Follower', - name: 'follower', - values: [ - { - displayName: 'Followers: Name or ID', - name: 'value', - type: 'options', - description: 'Choose from the list, or specify an ID using an expression', - default: '', - typeOptions: { - loadOptionsMethod: 'getUsers', - }, - }, - ], - }, - ], - description: 'Name or ID of the user to who follows this task. Choose from the list, or specify an ID using an expression.', - }, // move & copy task operation { displayName: 'Task Group Name or ID', name: 'taskGroupId', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getTaskGroupId', @@ -351,7 +311,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Project Name or ID', name: 'projectId', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getProjectId', @@ -361,7 +321,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Task Board Name or ID', name: 'taskBoardId', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getTaskBoardId', @@ -371,7 +331,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Task Group Name or ID', name: 'taskGroupId', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getTaskGroupId', @@ -381,7 +341,7 @@ export const taskDescription: INodeProperties[] = [ displayName: 'Creator Name or ID', name: 'createdBy', type: 'options', - description: 'Choose from the list, or specify an ID using an expression', + description: 'Choose from the list, or specify an ID using an expression', default: '', typeOptions: { loadOptionsMethod: 'getUsers', diff --git a/nodes/Plutio/descriptions/index.ts b/nodes/Plutio/descriptions/index.ts index b1d0789..2c244c2 100644 --- a/nodes/Plutio/descriptions/index.ts +++ b/nodes/Plutio/descriptions/index.ts @@ -2,8 +2,6 @@ import { taskDescription, taskOperations } from './TaskDescription'; import { commentDescription, commentOperations } from './CommentDescription'; import { invoiceDescription, invoiceOperations } from './InvoiceDescription'; import { projectDescription, projectOperations } from './ProjectDescription'; -import { companiesDescription, companiesOperations } from './CompaniesDescription'; -import { peopleDescription, peopleOperations } from './PeopleDescription'; export { taskOperations, @@ -14,8 +12,4 @@ export { invoiceDescription, projectOperations, projectDescription, - companiesOperations, - companiesDescription, - peopleOperations, - peopleDescription, }; diff --git a/nodes/Plutio/descriptions/peopleDescription.ts b/nodes/Plutio/descriptions/peopleDescription.ts deleted file mode 100644 index 22f6f2e..0000000 --- a/nodes/Plutio/descriptions/peopleDescription.ts +++ /dev/null @@ -1,318 +0,0 @@ -import { - INodeProperties, -} from 'n8n-workflow'; - -export const peopleOperations: INodeProperties[] = [ - { - displayName: 'Operation', - name: 'operation', - type: 'options', - noDataExpression: true, - required: true, - displayOptions: { - show: { - resource: [ - 'people', - ], - }, - }, - options: [ - { - name: 'Create', - value: 'create', - description: 'Create a new people', - action: 'Create a people', - }, - { - name: 'Get', - value: 'get', - description: 'Get people', - action: 'Get a people', - }, - { - name: 'Update', - value: 'update', - description: 'Update a people', - action: 'Update a people', - }, - { - name: 'Delete', - value: 'delete', - description: 'Delete a people', - action: 'Delete a people', - }, - ], - default: 'create', - }, -]; - -export const peopleDescription: INodeProperties[] = [ - { - displayName: 'ID', - name: '_id', - type: 'string', - default: '', - displayOptions: { - show: { - resource: [ - 'people', - ], - operation: [ - 'update', - 'delete', - 'get', - ], - }, - }, - description: 'ID of Person', - }, - { - displayName: 'Name', - name: 'name', - type: 'fixedCollection', - placeholder: 'Enter Name', - typeOptions: { - multipleValues: false, - }, - description: 'Enter First name & Last name', - default: [], - displayOptions: { - show: { - resource: [ - 'people', - ], - operation: [ - 'create', - 'update', - ], - }, - }, - options: [ - { - displayName: 'Name', - name: 'customName', - values: [ - { - displayName: 'First Name', - name: 'first', - type: 'string', - description: 'Enter First Name', - default: '', - }, - { - displayName: 'Last Name', - name: 'last', - type: 'string', - default: '', - description: 'Enter Last Name', - }, - ], - }, - ], - }, - { - displayName: 'Role', - name: 'role', - type: 'string', - default: '', - description: 'Enter Role', - displayOptions: { - show: { - resource: [ - 'people', - ], - operation: [ - 'create', - 'update', - 'get', - ], - }, - }, - }, - { - displayName: 'Options', - name: 'options', - type: 'collection', - placeholder: 'Add Option', - default: {}, - displayOptions: { - show: { - resource: [ - 'people', - ], - operation: [ - 'create', - 'update', - ], - }, - }, - options: [ - { - displayName: 'Company', - name: 'company', - type: 'string', - default: '', - description: 'Company Name', - }, - { - displayName: 'Status', - name: 'status', - type: 'options', - description: 'Enter Status', - default: 'active', - options: [ - { - name: 'Active', - value: 'active', - }, - { - name: 'Inactive', - value: 'inactive', - }, - { - name: 'Archive', - value: 'archive', - }, - { - name: 'Pending', - value: 'pending', - }, - ], - }, - { - displayName: 'Custom Fields', - name: 'customFields', - type: 'fixedCollection', - placeholder: 'Add Custom Field', - typeOptions: { - multipleValues: true, - }, - description: 'Key value pairs containing the name and value of the custom field. Only dates in the format YYYY-MM-DD are accepted as input for custom date fields.', - default: [], - options: [ - { - displayName: 'Custom Field', - name: 'customField', - values: [ - { - displayName: 'Custom Field Name or ID', - name: '_id', - type: 'options', - description: 'Choose from the list, or specify an ID using an expression', - default: '', - typeOptions: { - loadOptionsMethod: 'getPeopleCustomField', - }, - }, - { - displayName: 'Value Name or ID', - name: 'value', - type: 'string', - default: '', - description: 'Custom Field\'s values', - }, - ], - }, - ], - }, - { - displayName: 'Contact Phones', - name: 'phones', - type: 'fixedCollection', - default: [], - placeholder: 'Add Contact Phones', - typeOptions: { - multipleValues: true, - }, - options: [ - { - displayName: 'Contact Phone', - name: 'phone', - values: [ - { - displayName: 'Phone Number', - name: 'number', - type: 'string', - description: 'Enter Phone Number', - default: '', - }, - { - displayName: 'Type', - name: 'type', - type: 'options', - description: 'Email Type', - default: 'phone', - options: [ - { - name: 'Phone', - value: 'phone', - }, - { - name: 'Work', - value: 'work', - }, - { - name: 'Alternative', - value: 'alternative', - }, - { - name: 'Mobile', - value: 'mobile', - }, - ], - }, - ], - }, - ], - description: 'Emter phone number', - }, - { - displayName: 'Contact Emails', - name: 'emails', - type: 'fixedCollection', - default: [], - placeholder: 'Add Contact Emails', - typeOptions: { - multipleValues: true, - }, - options: [ - { - displayName: 'Contact Email', - name: 'email', - values: [ - { - displayName: 'Email Address', - name: 'address', - type: 'string', - description: 'Enter Email Address', - default: '', - }, - { - displayName: 'Type', - name: 'type', - type: 'options', - description: 'Email Type', - default: 'email', - options: [ - { - name: 'Email', - value: 'email', - }, - { - name: 'Work', - value: 'work', - }, - { - name: 'Alternative', - value: 'alternative', - }, - ], - }, - ], - }, - ], - description: 'Enter Email Address', - }, - ], - }, -]; diff --git a/package.json b/package.json index 6b84800..733e79d 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,25 @@ { "name": "n8n-nodes-plutio", - "version": "0.1.1", + "version": "0.1.0", "description": "Custom n8n node module for Plutio.", "keywords": [ "n8n-community-node-package" ], "license": "MIT", "homepage": "https://chykalophia.com", - "contributors": [ - { - "name": "Peter Krzyzek", - "email": "peter@chykalophia.com", - "url": "https://chykalophia.com" - }, - { - "name": "Joel Sanguenza", - "email": "joel@chykalophia.com", - "url": "https://chykalophia.com" - } - ], + "contributors": + [ + { + "name": "Peter Krzyzek", + "email": "peter@chykalophia.com", + "url": "https://chykalophia.com" + }, + { + "name": "Joel Sanguenza", + "email": "joel@chykalophia.com", + "url": "https://chykalophia.com" + } + ], "repository": { "type": "git", "url": "https://git.cklph.dev/Chykalophia/n8n-nodes-plutio.git"