merge to master

This commit is contained in:
Joel Sanguenza 2022-09-14 23:34:59 +08:00
parent a85a3d40a7
commit 6ea34f9bda
12 changed files with 6102 additions and 12746 deletions

View file

@ -17,7 +17,7 @@ async function plutioApiRequestToken(this: IExecuteFunctions | ILoadOptionsFunct
const clientId = `${credentials.clientId}`;
const clientSecret = `${credentials.clientSecret}`;
const business = `${credentials.business}`;
const endpoint = 'api.plutio.com/v1.9';
const endpoint = 'api.plutio.com/v1.10';
const returnData: IDataObject[] = [];
let responseData;
@ -58,7 +58,7 @@ async function plutioApiRequestToken(this: IExecuteFunctions | ILoadOptionsFunct
// Rest API function for plutio node.
export async function plutioApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const endpoint = 'api.plutio.com/v1.9';
const endpoint = 'api.plutio.com/v1.10';
const credentials = await this.getCredentials('plutioApi');
const plutioApiToken = await plutioApiRequestToken.call(this);
const business = `${credentials.business}`;

View file

@ -50,6 +50,7 @@ interface ICreatePlutioBody {
currency?: string;
discount?: string;
index?: number;
contributors?: [string];
}
export class Plutio implements INodeType {
@ -93,7 +94,7 @@ export class Plutio implements INodeType {
value: 'invoice',
},
{
name: 'Project-CKLPH',
name: 'Project',
value: 'project',
},
],
@ -208,6 +209,21 @@ export class Plutio implements INodeType {
return returnData;
},
async getProjectTemplateId(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const ids = await plutioApiRequest.call(this, 'GET', '/templates', {}, {'entityType': 'project'});
for (const id of ids) {
const templateName = id.title;
const templateId = id._id;
returnData.push({
name: templateName,
value: templateId,
});
}
return returnData;
},
async getProjectId(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const ids = await plutioApiRequest.call(this, 'GET', '/projects');
@ -227,7 +243,7 @@ export class Plutio implements INodeType {
// select them easily
async getCustomFieldTitle(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const fields = await plutioApiRequest.call(this, 'GET', '/custom-fields');
const fields = await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, {'entityType': 'task'});
for (const field of fields) {
if ('task' === field.entityType) {
const fieldName = field.title;
@ -241,6 +257,21 @@ export class Plutio implements INodeType {
}
return returnData;
},
async getProjectCustomField(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const fields = await plutioApiRequest.call(this, 'GET', '/custom-fields', {}, {'entityType': 'project'});
for (const field of fields) {
const fieldName = field.title;
const fieldValue = field._id;
returnData.push({
name: fieldName,
value: fieldValue,
});
}
return returnData;
},
},
};
@ -326,20 +357,22 @@ export class Plutio implements INodeType {
}
if (options.customFields) {
const metadata = (options.customFields as IDataObject).customField as IDataObject[];
const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"task"};
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);
if (metadata) {
const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"task"};
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;
}
@ -813,6 +846,159 @@ export class Plutio implements INodeType {
responseData = {'name': 'default'};
}
}
if ('get' === operation) {
const options = this.getNodeParameter('options', i) as IDataObject;
if (options.contributor) {
let contributorId;
const users = await plutioApiRequest.call(this, 'GET', '/people');
for (const user of users) {
if (user.contactEmails[0].address === options.contributor || options.contributor === user._id) {
contributorId = user._id;
}
}
qs.contributors = contributorId as string;
}
if (options._id) {
qs._id = options._id as string;
}
responseData = await plutioApiRequest.call(this, 'GET', '/projects', {}, qs);
}
if ('create' === operation) {
const options = this.getNodeParameter('options', i) as IDataObject;
const customFields = this.getNodeParameter('customFields', i) as IDataObject;
const contributors = this.getNodeParameter('contributorsUi', i) as IDataObject;
if (options.name) {
body.name = options.name as string;
}
if (options.templateId) {
body.templateId = options.templateId as string;
}
if (customFields) {
const metadata = (customFields as IDataObject).customField as IDataObject[];
if (metadata) {
const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"project"};
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[];
}
if (contributors) {
const metadata = (contributors as IDataObject).contributors as IDataObject[];
let contributor: IProperyId[] = [];
const users: IProperyId[] = [];
if (metadata) {
for (const data of metadata) {
contributor.push(data.value as IDataObject);
}
// flatten contributor array.
contributor = contributor.flatMap(a => a);
const customQs = {'status': 'active'};
await plutioApiRequest.call(this, 'GET', '/people', {}, customQs).then(people => {
for (const id of contributor) {
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.
contributor = users.filter((c, index) => {
return users.indexOf(c) === index;
});
body.contributors = contributor as [string];
}
responseData = await plutioApiRequest.call(this, 'POST', '/projects', body);
}
if ('update' === operation) {
const _id = this.getNodeParameter('_id', 0) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const customFields = this.getNodeParameter('customFields', i) as IDataObject;
const contributors = this.getNodeParameter('contributorsUi', i) as IDataObject;
if (_id) {
body._id = _id as string;
}
if (options.name) {
body.name = options.name as string;
}
if (options.templateId) {
body.templateId = options.templateId as string;
}
if (customFields) {
const metadata = (customFields as IDataObject).customField as IDataObject[];
if (metadata) {
const customQs = {"$or":[{"inputType": "select"}, {"inputType": "multi"}],"entityType":"project"};
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[];
}
if (contributors) {
const metadata = (contributors as IDataObject).contributors as IDataObject[];
let contributor: IProperyId[] = [];
const users: IProperyId[] = [];
if (metadata) {
for (const data of metadata) {
contributor.push(data.value as IDataObject);
}
// flatten contributor array.
contributor = contributor.flatMap(a => a);
const customQs = {'status': 'active'};
await plutioApiRequest.call(this, 'GET', '/people', {}, customQs).then(people => {
for (const id of contributor) {
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.
contributor = users.filter((c, index) => {
return users.indexOf(c) === index;
});
body.contributors = contributor as [string];
}
responseData = await plutioApiRequest.call(this, 'PUT', '/projects', body);;
}
if ('move' === operation) {
const _id = this.getNodeParameter('_id', 0) as string;
const index = this.getNodeParameter('index', 0) as number;

View file

@ -41,12 +41,12 @@ export const projectOperations: INodeProperties[] = [
description: 'Get projects',
action: 'Get a project',
},
{
name: 'Get CKLPH',
value: 'getCklph',
description: 'Get projects by contributor\'s email for CKLPH',
action: 'Get a project',
},
// {
// name: 'Chykalophia',
// value: 'getCklph',
// description: 'Get projects by contributor\'s email for CKLPH',
// action: 'Get a project',
// },
{
name: 'Move',
value: 'move',
@ -85,6 +85,130 @@ export const projectDescription: INodeProperties[] = [
},
description: 'ID of Project',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
resource: [
'project',
],
operation: [
'update',
'create',
],
},
},
options: [
{
displayName: 'Project Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of Project',
},
{
displayName: 'Template Name or ID',
name: 'templateId',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
default: '',
typeOptions: {
loadOptionsMethod: 'getProjectTemplateId',
},
},
],
},
{
displayName: 'Custom Fields',
name: 'customFields',
type: 'fixedCollection',
placeholder: 'Add Custom Field',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
resource: [
'project',
],
operation: [
'create',
'update',
],
},
},
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 <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
default: '',
typeOptions: {
loadOptionsMethod: 'getProjectCustomField',
},
},
{
displayName: 'Value Name or ID',
name: 'value',
type: 'string',
default: '',
description: 'Custom Field\'s values',
},
],
},
],
},
{
displayName: 'Contributors',
name: 'contributorsUi',
type: 'fixedCollection',
default: [],
placeholder: 'Add Person',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
resource: [
'project',
],
operation: [
'update',
'create',
],
},
},
options: [
{
displayName: 'Contributors',
name: 'contributors',
values: [
{
displayName: 'Contributors: Name or ID',
name: 'value',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
default: '',
typeOptions: {
loadOptionsMethod: 'getUsers',
},
},
],
},
],
description: 'Name or ID of the user to whom the task has been assigned. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/nodes/expressions.html#expressions">expression</a>.',
},
{
displayName: 'Index',
name: 'index',
@ -132,17 +256,7 @@ export const projectDescription: INodeProperties[] = [
},
{
displayName: 'Project Name or ID',
name: 'name',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
default: '',
typeOptions: {
loadOptionsMethod: 'getProjectId',
},
},
{
displayName: 'Client Name or ID',
name: 'name',
name: '_id',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
default: '',