Add Create and Update for Client Contact

This commit is contained in:
trojanh 2020-02-03 18:06:51 +05:30
parent 9e7ac3c13f
commit 5d36ce0a1e
4 changed files with 501 additions and 126 deletions

View file

@ -158,6 +158,129 @@ export const clientFields = [
},
},
description: 'The ID of the client you want to delete.',
}
},
/* -------------------------------------------------------------------------- */
/* client:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'name',
name: 'name',
type: 'string',
displayOptions: {
show: {
operation: [
'create',
],
resource,
},
},
default: '',
required: true,
description: 'The name of the client.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'create',
],
resource,
},
},
default: {},
options: [
{
displayName: 'is_active',
name: 'is_active',
type: 'string',
default: '',
description: 'Whether the client is active, or archived. Defaults to true.'
},
{
displayName: 'address',
name: 'address',
type: 'string',
default: '',
description: ' A textual representation of the clients physical address. May include new line characters.'
},
{
displayName: 'Currency',
name: 'currency',
type: 'string',
default: '',
description: 'The currency used by the estimate. If not provided, the clients currency will be used. See a list of supported currencies'
},
],
},
/* -------------------------------------------------------------------------- */
/* client:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'client Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource,
},
},
description: 'The ID of the client want to update.',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'update',
],
resource,
},
},
default: {},
options: [
{
displayName: 'name',
name: 'name',
type: 'string',
default: '',
description: 'Whether the client is active, or archived. Defaults to true.'
},
{
displayName: 'is_active',
name: 'is_active',
type: 'string',
default: '',
description: 'Whether the client is active, or archived. Defaults to true.'
},
{
displayName: 'address',
name: 'address',
type: 'string',
default: '',
description: ' A textual representation of the clients physical address. May include new line characters.'
},
{
displayName: 'Currency',
name: 'currency',
type: 'string',
default: '',
description: 'The currency used by the estimate. If not provided, the clients currency will be used. See a list of supported currencies'
},
],
},
] as INodeProperties[];

View file

@ -158,6 +158,194 @@ export const contactFields = [
},
},
description: 'The ID of the contact you want to delete.',
}
},
/* -------------------------------------------------------------------------- */
/* contact:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'First name',
name: 'first_name',
type: 'string',
displayOptions: {
show: {
operation: [
'create',
],
resource,
},
},
default: '',
required: true,
description: 'The first name of the contact.',
},
{
displayName: 'client_id',
name: 'client_id',
type: 'string',
displayOptions: {
show: {
operation: [
'create',
],
resource,
},
},
default: '',
required: true,
description: 'The ID of the client associated with this contact.',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'create',
],
resource,
},
},
default: {},
options: [
{
displayName: 'last_name',
name: 'last_name',
type: 'string',
default: '',
description: 'The last name of the contact.'
},
{
displayName: 'title',
name: 'title',
type: 'string',
default: '',
description: 'The title of the contact.'
},
{
displayName: 'email',
name: 'email',
type: 'string',
default: '',
description: 'The contacts email address.'
},
{
displayName: 'phone_office',
name: 'phone_office',
type: 'string',
default: '',
description: 'The contacts office phone number.'
},
{
displayName: 'phone_mobile',
name: 'phone_mobile',
type: 'string',
default: '',
description: 'The contacts mobile phone number.'
},
{
displayName: 'fax',
name: 'fax',
type: 'string',
default: '',
description: 'The contacts fax number.'
},
],
},
/* -------------------------------------------------------------------------- */
/* contact:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'contact Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource,
},
},
description: 'The ID of the contact want to update.',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'update',
],
resource,
},
},
default: {},
options: [
{
displayName: 'client_id',
name: 'client_id',
type: 'string',
default: '',
description: 'The ID of the client associated with this contact.',
},
{
displayName: 'First name',
name: 'first_name',
type: 'string',
default: '',
description: 'The first name of the contact.',
},
{
displayName: 'last_name',
name: 'last_name',
type: 'string',
default: '',
description: 'The last name of the contact.'
},
{
displayName: 'title',
name: 'title',
type: 'string',
default: '',
description: 'The title of the contact.'
},
{
displayName: 'email',
name: 'email',
type: 'string',
default: '',
description: 'The contacts email address.'
},
{
displayName: 'phone_office',
name: 'phone_office',
type: 'string',
default: '',
description: 'The contacts office phone number.'
},
{
displayName: 'phone_mobile',
name: 'phone_mobile',
type: 'string',
default: '',
description: 'The contacts mobile phone number.'
},
{
displayName: 'fax',
name: 'fax',
type: 'string',
default: '',
description: 'The contacts fax number.'
},
],
},
] as INodeProperties[];

View file

@ -50,6 +50,7 @@ export async function harvestApiRequest(
if (Object.keys(options.body).length === 0) {
delete options.body;
}
console.log(options)
try {
const result = await this.helpers.request!(options);

View file

@ -306,6 +306,37 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, resource, i);
returnData.push.apply(returnData, responseData);
} else if (operation === 'create') {
// ----------------------------------
// create
// ----------------------------------
requestMethod = 'POST';
endpoint = resource;
body.name = this.getNodeParameter('name', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(body, additionalFields);
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
returnData.push(responseData);
} else if (operation === 'update') {
// ----------------------------------
// update
// ----------------------------------
requestMethod = 'PATCH';
const id = this.getNodeParameter('id', i) as string;
endpoint = `${resource}/${id}`;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
Object.assign(qs, updateFields);
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
returnData.push(responseData);
} else if (operation === 'delete') {
// ----------------------------------
// delete
@ -446,7 +477,7 @@ export class Harvest implements INodeType {
} else if (operation === 'update') {
// ----------------------------------
// createByDuration
// update
// ----------------------------------
requestMethod = 'PATCH';
@ -495,6 +526,38 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, resource, i);
returnData.push.apply(returnData, responseData);
} else if (operation === 'create') {
// ----------------------------------
// create
// ----------------------------------
requestMethod = 'POST';
endpoint = resource;
body.client_id = this.getNodeParameter('client_id', i) as string;
body.first_name = this.getNodeParameter('first_name', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(body, additionalFields);
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
returnData.push(responseData);
} else if (operation === 'update') {
// ----------------------------------
// update
// ----------------------------------
requestMethod = 'PATCH';
const id = this.getNodeParameter('id', i) as string;
endpoint = `${resource}/${id}`;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
Object.assign(qs, updateFields);
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
returnData.push(responseData);
} else if (operation === 'delete') {
// ----------------------------------
// delete
@ -600,7 +663,7 @@ export class Harvest implements INodeType {
} else if (operation === 'update') {
// ----------------------------------
// createByDuration
// update
// ----------------------------------
requestMethod = 'PATCH';
@ -670,7 +733,7 @@ export class Harvest implements INodeType {
} else if (operation === 'update') {
// ----------------------------------
// createByDuration
// update
// ----------------------------------
requestMethod = 'PATCH';
@ -737,7 +800,7 @@ export class Harvest implements INodeType {
} else if (operation === 'update') {
// ----------------------------------
// createByDuration
// update
// ----------------------------------
requestMethod = 'PATCH';