Add upsert to all resources

This commit is contained in:
Iván Ovejero 2021-05-31 11:01:13 +02:00
parent baf3188258
commit 2863b04fff
12 changed files with 289 additions and 15 deletions

View file

@ -286,6 +286,26 @@ export class ZohoCrm implements INodeType {
const endpoint = `/accounts/${accountId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// account: upsert
// ----------------------------------------
const body: IDataObject = {
Account_Name: this.getNodeParameter('accountName', i),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustAccountPayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', '/accounts/upsert', body);
responseData = responseData.data;
}
} else if (resource === 'contact') {
@ -367,6 +387,26 @@ export class ZohoCrm implements INodeType {
const endpoint = `/contacts/${contactId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// contact: upsert
// ----------------------------------------
const body: IDataObject = {
Last_Name: this.getNodeParameter('lastName', i),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustContactPayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', '/contacts/upsert', body);
responseData = responseData.data;
}
} else if (resource === 'deal') {
@ -446,6 +486,27 @@ export class ZohoCrm implements INodeType {
responseData = await zohoApiRequest.call(this, 'PUT', `/deals/${dealId}`, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// deal: upsert
// ----------------------------------------
const body: IDataObject = {
Deal_Name: this.getNodeParameter('dealName', i),
Stage: this.getNodeParameter('stage', i),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustDealPayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', '/deals/upsert', body);
responseData = responseData.data;
}
} else if (resource === 'invoice') {
@ -531,6 +592,28 @@ export class ZohoCrm implements INodeType {
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// invoice: upsert
// ----------------------------------------
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = {
Subject: this.getNodeParameter('subject', i),
Product_Details: adjustProductDetails(productDetails),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustInvoicePayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', `/invoices/upsert`, body);
responseData = responseData.data;
}
} else if (resource === 'lead') {
@ -617,6 +700,26 @@ export class ZohoCrm implements INodeType {
responseData = await zohoApiRequest.call(this, 'PUT', `/leads/${leadId}`, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// lead: upsert
// ----------------------------------------
const body: IDataObject = {
Company: this.getNodeParameter('Company', i),
Last_Name: this.getNodeParameter('lastName', i),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustLeadPayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', '/leads/upsert', body);
responseData = responseData.data;
}
} else if (resource === 'product') {
@ -699,6 +802,25 @@ export class ZohoCrm implements INodeType {
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// product: upsert
// ----------------------------------------
const body: IDataObject = {
Product_Name: this.getNodeParameter('productName', i),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, additionalFields);
}
responseData = await zohoApiRequest.call(this, 'POST', '/products/upsert', body);
responseData = responseData.data;
}
} else if (resource === 'purchaseOrder') {
@ -785,6 +907,29 @@ export class ZohoCrm implements INodeType {
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// purchaseOrder: upsert
// ----------------------------------------
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = {
Subject: this.getNodeParameter('subject', i),
Vendor_Name: { id: this.getNodeParameter('vendorId', i) },
Product_Details: adjustProductDetails(productDetails),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustPurchaseOrderPayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', '/purchase_orders/upsert', body);
responseData = responseData.data;
}
} else if (resource === 'quote') {
@ -866,6 +1011,29 @@ export class ZohoCrm implements INodeType {
responseData = await zohoApiRequest.call(this, 'PUT', `/quotes/${quoteId}`, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// quote: upsert
// ----------------------------------------
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = {
Subject: this.getNodeParameter('subject', i),
Product_Details: adjustProductDetails(productDetails),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustQuotePayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', '/quotes/upsert', body);
responseData = responseData.data;
}
} else if (resource === 'salesOrder') {
@ -952,6 +1120,29 @@ export class ZohoCrm implements INodeType {
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// salesOrder: upsert
// ----------------------------------------
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = {
Account_Name: { id: this.getNodeParameter('accountId', i) },
Subject: this.getNodeParameter('subject', i),
Product_Details: adjustProductDetails(productDetails),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustSalesOrderPayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', '/sales_orders/upsert', body);
responseData = responseData.data;
}
} else if (resource === 'vendor') {
@ -1034,6 +1225,25 @@ export class ZohoCrm implements INodeType {
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
responseData = responseData.data;
} else if (operation === 'upsert') {
// ----------------------------------------
// vendor: upsert
// ----------------------------------------
const body: IDataObject = {
Vendor_Name: this.getNodeParameter('vendorName', i),
};
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) {
Object.assign(body, adjustVendorPayload(additionalFields));
}
responseData = await zohoApiRequest.call(this, 'POST', '/vendors/upsert', body);
responseData = responseData.data;
}
}

View file

@ -41,6 +41,10 @@ export const accountOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -49,7 +53,7 @@ export const accountOperations = [
export const accountFields = [
// ----------------------------------------
// account: create
// account: create + upsert
// ----------------------------------------
{
displayName: 'Account Name',
@ -64,6 +68,7 @@ export const accountFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -81,6 +86,7 @@ export const accountFields = [
],
operation: [
'create',
'upsert',
],
},
},

View file

@ -41,6 +41,10 @@ export const contactOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -49,7 +53,7 @@ export const contactOperations = [
export const contactFields = [
// ----------------------------------------
// contact: create
// contact: create + upsert
// ----------------------------------------
{
displayName: 'Last Name',
@ -64,6 +68,7 @@ export const contactFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -81,6 +86,7 @@ export const contactFields = [
],
operation: [
'create',
'upsert',
],
},
},

View file

@ -39,6 +39,10 @@ export const dealOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -47,7 +51,7 @@ export const dealOperations = [
export const dealFields = [
// ----------------------------------------
// deal: create
// deal: create + upsert
// ----------------------------------------
{
displayName: 'Deal Name',
@ -62,6 +66,7 @@ export const dealFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -79,6 +84,7 @@ export const dealFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -96,6 +102,7 @@ export const dealFields = [
],
operation: [
'create',
'upsert',
],
},
},

View file

@ -42,6 +42,10 @@ export const invoiceOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -50,7 +54,7 @@ export const invoiceOperations = [
export const invoiceFields = [
// ----------------------------------------
// invoice: create
// invoice: create + upsert
// ----------------------------------------
{
displayName: 'Subject',
@ -66,11 +70,12 @@ export const invoiceFields = [
],
operation: [
'create',
'upsert',
],
},
},
},
makeProductDetails('invoice', 'create'),
makeProductDetails('invoice', 'create', { hasUpsert: true }),
{
displayName: 'Additional Fields',
name: 'additionalFields',
@ -84,6 +89,7 @@ export const invoiceFields = [
],
operation: [
'create',
'upsert',
],
},
},

View file

@ -40,6 +40,10 @@ export const leadOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -48,7 +52,7 @@ export const leadOperations = [
export const leadFields = [
// ----------------------------------------
// lead: create
// lead: create + upsert
// ----------------------------------------
{
displayName: 'Company',
@ -64,6 +68,7 @@ export const leadFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -81,6 +86,7 @@ export const leadFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -98,6 +104,7 @@ export const leadFields = [
],
operation: [
'create',
'upsert',
],
},
},

View file

@ -39,6 +39,10 @@ export const productOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -47,7 +51,7 @@ export const productOperations = [
export const productFields = [
// ----------------------------------------
// product: create
// product: create + upsert
// ----------------------------------------
{
displayName: 'Product Name',
@ -62,6 +66,7 @@ export const productFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -79,6 +84,7 @@ export const productFields = [
],
operation: [
'create',
'upsert',
],
},
},

View file

@ -42,6 +42,10 @@ export const purchaseOrderOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -50,7 +54,7 @@ export const purchaseOrderOperations = [
export const purchaseOrderFields = [
// ----------------------------------------
// purchaseOrder: create
// purchaseOrder: create + upsert
// ----------------------------------------
{
displayName: 'Subject',
@ -66,6 +70,7 @@ export const purchaseOrderFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -86,11 +91,12 @@ export const purchaseOrderFields = [
],
operation: [
'create',
'upsert',
],
},
},
},
makeProductDetails('purchaseOrder', 'create'),
makeProductDetails('purchaseOrder', 'create', { hasUpsert: true }),
{
displayName: 'Additional Fields',
name: 'additionalFields',

View file

@ -42,6 +42,10 @@ export const quoteOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -50,7 +54,7 @@ export const quoteOperations = [
export const quoteFields = [
// ----------------------------------------
// quote: create
// quote: create + upsert
// ----------------------------------------
{
displayName: 'Subject',
@ -66,11 +70,12 @@ export const quoteFields = [
],
operation: [
'create',
'upsert',
],
},
},
},
makeProductDetails('quote', 'create'),
makeProductDetails('quote', 'create', { hasUpsert: true }),
{
displayName: 'Additional Fields',
name: 'additionalFields',
@ -84,6 +89,7 @@ export const quoteFields = [
],
operation: [
'create',
'upsert',
],
},
},

View file

@ -42,6 +42,10 @@ export const salesOrderOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -50,7 +54,7 @@ export const salesOrderOperations = [
export const salesOrderFields = [
// ----------------------------------------
// salesOrder: create
// salesOrder: create + upsert
// ----------------------------------------
{
displayName: 'Account ID',
@ -68,6 +72,7 @@ export const salesOrderFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -86,11 +91,12 @@ export const salesOrderFields = [
],
operation: [
'create',
'upsert',
],
},
},
},
makeProductDetails('salesOrder', 'create'),
makeProductDetails('salesOrder', 'create', { hasUpsert: true }),
{
displayName: 'Additional Fields',
name: 'additionalFields',
@ -104,6 +110,7 @@ export const salesOrderFields = [
],
operation: [
'create',
'upsert',
],
},
},

View file

@ -222,7 +222,7 @@ export const address = {
],
};
export const makeProductDetails = (resource: string, operation: string) => ({
export const makeProductDetails = (resource: string, operation: string, { hasUpsert } = { hasUpsert: false }) => ({
displayName: 'Products',
name: 'Product_Details',
type: 'collection',
@ -239,6 +239,7 @@ export const makeProductDetails = (resource: string, operation: string) => ({
],
operation: [
operation,
hasUpsert && 'upsert',
],
},
},

View file

@ -40,6 +40,10 @@ export const vendorOperations = [
name: 'Update',
value: 'update',
},
{
name: 'Upsert',
value: 'upsert',
},
],
default: 'create',
description: 'Operation to perform',
@ -48,7 +52,7 @@ export const vendorOperations = [
export const vendorFields = [
// ----------------------------------------
// vendor: create
// vendor: create + upsert
// ----------------------------------------
{
displayName: 'Vendor Name',
@ -63,6 +67,7 @@ export const vendorFields = [
],
operation: [
'create',
'upsert',
],
},
},
@ -80,6 +85,7 @@ export const vendorFields = [
],
operation: [
'create',
'upsert',
],
},
},