added-followers-functions

This commit is contained in:
Joel Sanguenza 2022-10-04 18:37:59 +08:00
parent 6a17ab840b
commit 9057d8b2cf
3 changed files with 153 additions and 29 deletions

View File

@ -30,6 +30,7 @@ interface IProperyId {}
interface ICreatePlutioBody { interface ICreatePlutioBody {
assignedTo?: [string]; assignedTo?: [string];
followers?: [string];
title?: string; title?: string;
name?: string; name?: string;
taskGroupId?: string; taskGroupId?: string;
@ -290,6 +291,7 @@ export class Plutio implements INodeType {
if ('task' === resource) { if ('task' === resource) {
if ('create' === operation) { if ('create' === operation) {
const assignees = this.getNodeParameter('assignees', i) as IDataObject; const assignees = this.getNodeParameter('assignees', i) as IDataObject;
const followedBy = this.getNodeParameter('followers', i) as IDataObject;
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
if (options.projectId) { if (options.projectId) {
@ -382,7 +384,6 @@ export class Plutio implements INodeType {
const metadata = (assignees as IDataObject).assignee as IDataObject[]; const metadata = (assignees as IDataObject).assignee as IDataObject[];
let assignedTo: IProperyId[] = []; let assignedTo: IProperyId[] = [];
const users: IProperyId[] = []; const users: IProperyId[] = [];
if (metadata) { if (metadata) {
// Push all assignees to a single array. // Push all assignees to a single array.
@ -413,11 +414,50 @@ export class Plutio implements INodeType {
body.assignedTo = assignedTo as [string]; 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); responseData = await plutioApiRequest.call(this, 'POST', '/tasks', body);
} }
if ('update' === operation) { if ('update' === operation) {
const _id = this.getNodeParameter('_id', 0) as string; const _id = this.getNodeParameter('_id', 0) as string;
const assignees = this.getNodeParameter('assignees', i) as IDataObject; const assignees = this.getNodeParameter('assignees', i) as IDataObject;
const followedBy = this.getNodeParameter('followers', i) as IDataObject;
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
if (_id) { if (_id) {
@ -510,6 +550,7 @@ export class Plutio implements INodeType {
let assignedTo: IProperyId[] = []; let assignedTo: IProperyId[] = [];
const users: IProperyId[] = []; const users: IProperyId[] = [];
if (metadata) {
// Push all assignees to a single array. // Push all assignees to a single array.
for (const data of metadata) { for (const data of metadata) {
assignedTo.push(data.value as IDataObject); assignedTo.push(data.value as IDataObject);
@ -529,6 +570,7 @@ export class Plutio implements INodeType {
} }
} }
}); });
}
// remove duplicates. // remove duplicates.
assignedTo = users.filter((c, index) => { assignedTo = users.filter((c, index) => {
@ -537,8 +579,47 @@ export class Plutio implements INodeType {
body.assignedTo = assignedTo as [string]; 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); responseData = await plutioApiRequest.call(this, 'PUT', '/tasks', body);
} }
if ('get' === operation) { if ('get' === operation) {
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
@ -647,6 +728,8 @@ export class Plutio implements INodeType {
responseData = await plutioApiRequest.call(this, 'DELETE', '/tasks', body); responseData = await plutioApiRequest.call(this, 'DELETE', '/tasks', body);
} }
} }
// Execute Comments.
if ('comment' === resource) { if ('comment' === resource) {
if ('create' === operation) { if ('create' === operation) {
const entityId = this.getNodeParameter('entityId', i) as string; const entityId = this.getNodeParameter('entityId', i) as string;
@ -697,6 +780,8 @@ export class Plutio implements INodeType {
responseData = await plutioApiRequest.call(this, 'DELETE', '/comments', body); responseData = await plutioApiRequest.call(this, 'DELETE', '/comments', body);
} }
} }
// execute Invoice.
if ('invoice' === resource) { if ('invoice' === resource) {
if ('create' === operation) { if ('create' === operation) {
const taxUi = this.getNodeParameter('taxUi', i) as IDataObject; const taxUi = this.getNodeParameter('taxUi', i) as IDataObject;

View File

@ -242,6 +242,46 @@ 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 <a href="https://docs.n8n.io/nodes/expressions.html#expressions">expression</a>.', 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: '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 <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
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 <a href="https://docs.n8n.io/nodes/expressions.html#expressions">expression</a>.',
},
// move & copy task operation // move & copy task operation
{ {
displayName: 'Task Group Name or ID', displayName: 'Task Group Name or ID',

View File

@ -7,8 +7,7 @@
], ],
"license": "MIT", "license": "MIT",
"homepage": "https://chykalophia.com", "homepage": "https://chykalophia.com",
"contributors": "contributors": [
[
{ {
"name": "Peter Krzyzek", "name": "Peter Krzyzek",
"email": "peter@chykalophia.com", "email": "peter@chykalophia.com",