From dd034f21439ceb6c0282359f392a67bcefee59b8 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Wed, 4 Aug 2021 18:38:48 +0200 Subject: [PATCH] Fixed linting and tags information --- .../nodes-base/nodes/WooCommerce/GenericFunctions.ts | 11 ++++++++--- .../nodes-base/nodes/WooCommerce/OrderInterface.ts | 2 +- .../nodes-base/nodes/WooCommerce/ProductInterface.ts | 2 +- .../nodes-base/nodes/WooCommerce/WooCommerce.node.ts | 10 +++++----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts b/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts index 19b7f0a5cc..4416961a07 100644 --- a/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts +++ b/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts @@ -149,9 +149,14 @@ export function toSnakeCase(data: } } -export function setFields(fieldsToSet: IDataObject, body: any) { - for(let fields in fieldsToSet) { - body[snakeCase(fields.toString())] = fieldsToSet[fields] +export function setFields(fieldsToSet: IDataObject, body: IDataObject) { + for(const fields in fieldsToSet) { + if (fields === 'tags') { + body['tags'] = (fieldsToSet[fields] as string[]).map(tag => ({id: parseInt(tag, 10)})); + } else { + body[snakeCase(fields.toString())] = fieldsToSet[fields]; + } + } } diff --git a/packages/nodes-base/nodes/WooCommerce/OrderInterface.ts b/packages/nodes-base/nodes/WooCommerce/OrderInterface.ts index ec3a85fdc2..5a59c4c02a 100644 --- a/packages/nodes-base/nodes/WooCommerce/OrderInterface.ts +++ b/packages/nodes-base/nodes/WooCommerce/OrderInterface.ts @@ -46,7 +46,7 @@ export interface ICouponLine { } export interface IOrder { - [index: string]: any + [index: string]: any; // tslint:disable-line:no-any billing?: IAddress; coupon_lines?: ICouponLine[]; currency?: string; diff --git a/packages/nodes-base/nodes/WooCommerce/ProductInterface.ts b/packages/nodes-base/nodes/WooCommerce/ProductInterface.ts index 58362e1be3..b4382677cb 100644 --- a/packages/nodes-base/nodes/WooCommerce/ProductInterface.ts +++ b/packages/nodes-base/nodes/WooCommerce/ProductInterface.ts @@ -13,5 +13,5 @@ export interface IImage { } export interface IProduct { - [index: string]: any + [index: string]: string | number | string[] | number[] | IDataObject | IDataObject[] | IImage[] | IDimension; } diff --git a/packages/nodes-base/nodes/WooCommerce/WooCommerce.node.ts b/packages/nodes-base/nodes/WooCommerce/WooCommerce.node.ts index d8144f0b59..c8264dda24 100644 --- a/packages/nodes-base/nodes/WooCommerce/WooCommerce.node.ts +++ b/packages/nodes-base/nodes/WooCommerce/WooCommerce.node.ts @@ -11,11 +11,11 @@ import { } from 'n8n-workflow'; import { adjustMetadata, + setFields, setMetadata, toSnakeCase, woocommerceApiRequest, woocommerceApiRequestAllItems, - setFields, } from './GenericFunctions'; import { productFields, @@ -250,11 +250,11 @@ export class WooCommerce implements INodeType { if (operation === 'create') { const name = this.getNodeParameter('name', i) as string; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; - let body: IProduct = { + const body: IProduct = { name, }; - setFields(additionalFields, body) + setFields(additionalFields, body); if (additionalFields.categories) { body.categories = (additionalFields.categories as string[]).map(category => ({ id: parseInt(category, 10) })) as unknown as IDataObject[]; @@ -280,7 +280,7 @@ export class WooCommerce implements INodeType { const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; const body: IProduct = {}; - setFields(updateFields, body) + setFields(updateFields, body); const images = (this.getNodeParameter('imagesUi', i) as IDataObject).imagesValues as IImage[]; if (images) { @@ -375,7 +375,7 @@ export class WooCommerce implements INodeType { const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const body: IOrder = {}; - setFields(additionalFields, body) + setFields(additionalFields, body); const billing = (this.getNodeParameter('billingUi', i) as IDataObject).billingValues as IAddress; if (billing !== undefined) {