Adjust param types

This commit is contained in:
Iván Ovejero 2021-05-07 13:19:01 +02:00
parent 662ea2467c
commit 75a7bbef34
8 changed files with 49 additions and 26 deletions

View file

@ -130,15 +130,25 @@ const adjustMailingAddressFields = adjustLocationFields('Mailing_Address');
const adjustShippingAddressFields = adjustLocationFields('Shipping_Address'); const adjustShippingAddressFields = adjustLocationFields('Shipping_Address');
const adjustOtherAddressFields = adjustLocationFields('Other_Address'); const adjustOtherAddressFields = adjustLocationFields('Other_Address');
const adjustDateOfBirth = (allFields: { Date_of_Birth: string }) => { /**
if (!allFields.Date_of_Birth) return allFields; * Remove a date field's timestamp.
allFields.Date_of_Birth = allFields.Date_of_Birth.split('T')[0]; */
const adjustDateField = (dateType: DateType) => (allFields: DateField) => {
const dateField = allFields[dateType];
if (!dateField) return allFields;
allFields[dateType] = dateField.split('T')[0];
return allFields; return allFields;
}; };
const adjustDateOfBirthField = adjustDateField('Date_of_Birth');
const adjustClosingDateField = adjustDateField('Closing_Date');
export const adjustAccountFields = flow(adjustBillingAddressFields, adjustShippingAddressFields); export const adjustAccountFields = flow(adjustBillingAddressFields, adjustShippingAddressFields);
export const adjustContactFields = flow(adjustMailingAddressFields, adjustOtherAddressFields, adjustDateOfBirth); export const adjustContactFields = flow(adjustMailingAddressFields, adjustOtherAddressFields, adjustDateOfBirthField);
export const adjustDealFields = adjustClosingDateField;
export const adjustInvoiceFields = flow(adjustBillingAddressFields, adjustShippingAddressFields); // TODO: product details export const adjustInvoiceFields = flow(adjustBillingAddressFields, adjustShippingAddressFields); // TODO: product details
export const adjustLeadFields = adjustAddressFields; export const adjustLeadFields = adjustAddressFields;
export const adjustPurchaseOrderFields = adjustInvoiceFields; export const adjustPurchaseOrderFields = adjustInvoiceFields;
@ -165,3 +175,7 @@ type LocationType = 'Address' | 'Billing_Address' | 'Mailing_Address' | 'Shippin
type LocationField = { type LocationField = {
address_fields: { [key in LocationType]: string }; address_fields: { [key in LocationType]: string };
}; };
type DateType = 'Date_of_Birth' | 'Closing_Date';
type DateField = { Date_of_Birth?: string; Closing_Date?: string; };

View file

@ -12,6 +12,7 @@ import {
import { import {
adjustAccountFields, adjustAccountFields,
adjustContactFields, adjustContactFields,
adjustDealFields,
adjustInvoiceFields, adjustInvoiceFields,
adjustLeadFields, adjustLeadFields,
adjustPurchaseOrderFields, adjustPurchaseOrderFields,
@ -305,14 +306,14 @@ export class ZohoCrm implements INodeType {
// ---------------------------------------- // ----------------------------------------
const body: IDataObject = { const body: IDataObject = {
Deal_Name: this.getNodeParameter('Deal_Name', i), Deal_Name: this.getNodeParameter('dealName', i),
Stage: this.getNodeParameter('Stage', i), Stage: this.getNodeParameter('stage', i),
}; };
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) { if (Object.keys(additionalFields).length) {
Object.assign(body, additionalFields); Object.assign(body, adjustDealFields(additionalFields));
} }
responseData = await zohoApiRequest.call(this, 'POST', '/deals', body); responseData = await zohoApiRequest.call(this, 'POST', '/deals', body);
@ -355,7 +356,7 @@ export class ZohoCrm implements INodeType {
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
if (Object.keys(updateFields).length) { if (Object.keys(updateFields).length) {
Object.assign(body, updateFields); Object.assign(body, adjustDealFields(updateFields));
} }
const dealId = this.getNodeParameter('dealId', i); const dealId = this.getNodeParameter('dealId', i);

View file

@ -107,7 +107,7 @@ export const accountFields = [
{ {
displayName: 'Annual Revenue', displayName: 'Annual Revenue',
name: 'Annual_Revenue', name: 'Annual_Revenue',
type: 'string', type: 'number',
default: '', default: '',
}, },
billingAddress, billingAddress,
@ -140,7 +140,7 @@ export const accountFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },
@ -293,7 +293,7 @@ export const accountFields = [
{ {
displayName: 'Annual Revenue', displayName: 'Annual Revenue',
name: 'Annual_Revenue', name: 'Annual_Revenue',
type: 'string', type: 'number',
default: '', default: '',
}, },
billingAddress, billingAddress,
@ -326,7 +326,7 @@ export const accountFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },

View file

@ -110,7 +110,7 @@ export const dealFields = [
{ {
displayName: 'Closing Date', displayName: 'Closing Date',
name: 'Closing_Date', name: 'Closing_Date',
type: 'string', type: 'dateTime',
default: '', default: '',
}, },
{ {
@ -150,9 +150,13 @@ export const dealFields = [
{ {
displayName: 'Probability', displayName: 'Probability',
name: 'Probability', name: 'Probability',
type: 'string', type: 'number',
typeOptions: {
minValue: 0,
maxValue: 100,
},
default: '', default: '',
description: 'Probability of deal closure.', description: 'Probability of deal closure as a percentage.',
}, },
{ {
displayName: 'Sales Cycle Duration', displayName: 'Sales Cycle Duration',
@ -261,7 +265,7 @@ export const dealFields = [
{ {
displayName: 'Closing Date', displayName: 'Closing Date',
name: 'Closing_Date', name: 'Closing_Date',
type: 'string', type: 'dateTime',
default: '', default: '',
}, },
{ {
@ -307,9 +311,13 @@ export const dealFields = [
{ {
displayName: 'Probability', displayName: 'Probability',
name: 'Probability', name: 'Probability',
type: 'string', type: 'number',
typeOptions: {
minValue: 0,
maxValue: 100,
},
default: '', default: '',
description: 'Probability of deal closure.', description: 'Probability of deal closure as a percentage.',
}, },
{ {
displayName: 'Sales Cycle Duration', displayName: 'Sales Cycle Duration',

View file

@ -155,7 +155,7 @@ export const invoiceFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },
@ -354,7 +354,7 @@ export const invoiceFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },

View file

@ -191,7 +191,7 @@ export const purchaseOrderFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },
@ -392,7 +392,7 @@ export const purchaseOrderFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },

View file

@ -134,7 +134,7 @@ export const quoteFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },
@ -307,7 +307,7 @@ export const quoteFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },

View file

@ -201,7 +201,7 @@ export const salesOrderFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },
@ -476,7 +476,7 @@ export const salesOrderFields = [
{ {
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'string', type: 'number',
default: '', default: '',
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },