Fixed linting and tags information

This commit is contained in:
Omar Ajoue 2021-08-04 18:38:48 +02:00
parent caa6a3d234
commit dd034f2143
4 changed files with 15 additions and 10 deletions

View file

@ -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];
}
}
}

View file

@ -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;

View file

@ -13,5 +13,5 @@ export interface IImage {
}
export interface IProduct {
[index: string]: any
[index: string]: string | number | string[] | number[] | IDataObject | IDataObject[] | IImage[] | IDimension;
}

View file

@ -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) {