Add DELETE for Harvest APIs

This commit is contained in:
trojanh 2020-01-31 18:17:20 +05:30
parent 481d6d2bc1
commit 8374a23389
9 changed files with 311 additions and 6 deletions

View file

@ -23,6 +23,11 @@ export const clientOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all clients', description: 'Get data of all clients',
}, },
{
name: 'Delete',
value: 'delete',
description: `Delete a client`,
},
], ],
default: 'getAll', default: 'getAll',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -131,6 +136,28 @@ export const clientFields = [
}, },
}, },
description: 'The ID of the client you are retrieving.', description: 'The ID of the client you are retrieving.',
},
/* -------------------------------------------------------------------------- */
/* client:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Client Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'client',
],
},
},
description: 'The ID of the client you want to delete.',
} }
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -23,6 +23,11 @@ export const contactOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all contacts', description: 'Get data of all contacts',
}, },
{
name: 'Delete',
value: 'delete',
description: `Delete a contact`,
},
], ],
default: 'getAll', default: 'getAll',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -131,6 +136,28 @@ export const contactFields = [
}, },
}, },
description: 'The ID of the contact you are retrieving.', description: 'The ID of the contact you are retrieving.',
},
/* -------------------------------------------------------------------------- */
/* contact:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Contact Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'contact',
],
},
},
description: 'The ID of the contact you want to delete.',
} }
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -23,6 +23,11 @@ export const estimateOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all estimates', description: 'Get data of all estimates',
}, },
{
name: 'Delete',
value: 'delete',
description: `Delete an estimate`,
},
], ],
default: 'getAll', default: 'getAll',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -162,6 +167,28 @@ export const estimateFields = [
}, },
}, },
description: 'The ID of the estimate you are retrieving.', description: 'The ID of the estimate you are retrieving.',
},
/* -------------------------------------------------------------------------- */
/* estimate:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Estimate Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'estimate',
],
},
},
description: 'The ID of the estimate want to delete.',
} }
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -23,6 +23,11 @@ export const expenseOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all expenses', description: 'Get data of all expenses',
}, },
{
name: 'Delete',
value: 'delete',
description: `Delete an expense`,
},
], ],
default: 'getAll', default: 'getAll',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -176,6 +181,28 @@ export const expenseFields = [
}, },
}, },
description: 'The ID of the expense you are retrieving.', description: 'The ID of the expense you are retrieving.',
},
/* -------------------------------------------------------------------------- */
/* expense:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Expense Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'expense',
],
},
},
description: 'The ID of the expense you want to delete.',
} }
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -306,6 +306,17 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, 'clients', i); const responseData: IDataObject[] = await getAllResource.call(this, 'clients', i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `clients/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} else { } else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }
@ -331,6 +342,17 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, 'projects', i); const responseData: IDataObject[] = await getAllResource.call(this, 'projects', i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `projects/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} else { } else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }
@ -368,7 +390,18 @@ export class Harvest implements INodeType {
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData); returnData.push(responseData);
} else { } else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `users/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }
} else if (resource === 'contact') { } else if (resource === 'contact') {
@ -393,7 +426,18 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, 'contacts', i); const responseData: IDataObject[] = await getAllResource.call(this, 'contacts', i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} else { } else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `contacts/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }
} else if (resource === 'company') { } else if (resource === 'company') {
@ -433,6 +477,17 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, 'tasks', i); const responseData: IDataObject[] = await getAllResource.call(this, 'tasks', i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `tasks/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} else { } else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }
@ -458,7 +513,18 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, 'invoices', i); const responseData: IDataObject[] = await getAllResource.call(this, 'invoices', i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} else { } else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `invoices/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }
} else if (resource === 'expense') { } else if (resource === 'expense') {
@ -483,7 +549,18 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, 'expenses', i); const responseData: IDataObject[] = await getAllResource.call(this, 'expenses', i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} else { } else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `expenses/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }
} else if (resource === 'estimate') { } else if (resource === 'estimate') {
@ -508,7 +585,18 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, 'estimates', i); const responseData: IDataObject[] = await getAllResource.call(this, 'estimates', i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} else { } else if (operation === 'delete') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `estimates/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} else {
throw new Error(`The resource "${resource}" is not known!`); throw new Error(`The resource "${resource}" is not known!`);
} }
} else { } else {

View file

@ -23,6 +23,11 @@ export const invoiceOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all invoices', description: 'Get data of all invoices',
}, },
{
name: 'Delete',
value: 'delete',
description: `Delete a invoice`,
},
], ],
default: 'getAll', default: 'getAll',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -187,6 +192,28 @@ export const invoiceFields = [
}, },
}, },
description: 'The ID of the invoice you are retrieving.', description: 'The ID of the invoice you are retrieving.',
},
/* -------------------------------------------------------------------------- */
/* invoice:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Invoice Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'invoice',
],
},
},
description: 'The ID of the invoice want to delete.',
} }
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -23,6 +23,11 @@ export const projectOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all projects', description: 'Get data of all projects',
}, },
{
name: 'Delete',
value: 'delete',
description: `Delete a project`,
},
], ],
default: 'getAll', default: 'getAll',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -149,6 +154,28 @@ export const projectFields = [
}, },
}, },
description: 'The ID of the project you are retrieving.', description: 'The ID of the project you are retrieving.',
},
/* -------------------------------------------------------------------------- */
/* project:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Project Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'project',
],
},
},
description: 'The ID of the project want to delete.',
} }
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -23,6 +23,11 @@ export const taskOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all tasks', description: 'Get data of all tasks',
}, },
{
name: 'Delete',
value: 'delete',
description: `Delete a task`,
},
], ],
default: 'getAll', default: 'getAll',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -141,6 +146,29 @@ export const taskFields = [
}, },
}, },
description: 'The ID of the task you are retrieving.', description: 'The ID of the task you are retrieving.',
} },
/* -------------------------------------------------------------------------- */
/* task:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Task Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'task',
],
},
},
description: 'The ID of the task you wan to delete.',
},
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -28,6 +28,11 @@ export const userOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all users', description: 'Get data of all users',
}, },
{
name: 'Delete',
value: 'delete',
description: `Delete a user`,
},
], ],
default: 'me', default: 'me',
description: 'The operation to perform.', description: 'The operation to perform.',
@ -146,6 +151,28 @@ export const userFields = [
}, },
}, },
description: 'The ID of the user you are retrieving.', description: 'The ID of the user you are retrieving.',
},
/* -------------------------------------------------------------------------- */
/* user:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'User Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'user',
],
},
},
description: 'The ID of the user you want to delete.',
} }
] as INodeProperties[]; ] as INodeProperties[];