Merge pull request #2052 from n8n-io/woocommerce-lint-and-tags-fix

Fixed linting and tags information
This commit is contained in:
Omar Ajoue 2021-08-04 18:44:17 +02:00 committed by GitHub
commit b8524bbfb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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) { export function setFields(fieldsToSet: IDataObject, body: IDataObject) {
for(let fields in fieldsToSet) { for(const fields in fieldsToSet) {
body[snakeCase(fields.toString())] = fieldsToSet[fields] 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 { export interface IOrder {
[index: string]: any [index: string]: any; // tslint:disable-line:no-any
billing?: IAddress; billing?: IAddress;
coupon_lines?: ICouponLine[]; coupon_lines?: ICouponLine[];
currency?: string; currency?: string;

View file

@ -13,5 +13,5 @@ export interface IImage {
} }
export interface IProduct { 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'; } from 'n8n-workflow';
import { import {
adjustMetadata, adjustMetadata,
setFields,
setMetadata, setMetadata,
toSnakeCase, toSnakeCase,
woocommerceApiRequest, woocommerceApiRequest,
woocommerceApiRequestAllItems, woocommerceApiRequestAllItems,
setFields,
} from './GenericFunctions'; } from './GenericFunctions';
import { import {
productFields, productFields,
@ -250,11 +250,11 @@ export class WooCommerce implements INodeType {
if (operation === 'create') { if (operation === 'create') {
const name = this.getNodeParameter('name', i) as string; const name = this.getNodeParameter('name', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
let body: IProduct = { const body: IProduct = {
name, name,
}; };
setFields(additionalFields, body) setFields(additionalFields, body);
if (additionalFields.categories) { if (additionalFields.categories) {
body.categories = (additionalFields.categories as string[]).map(category => ({ id: parseInt(category, 10) })) as unknown as IDataObject[]; 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 updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
const body: IProduct = {}; const body: IProduct = {};
setFields(updateFields, body) setFields(updateFields, body);
const images = (this.getNodeParameter('imagesUi', i) as IDataObject).imagesValues as IImage[]; const images = (this.getNodeParameter('imagesUi', i) as IDataObject).imagesValues as IImage[];
if (images) { if (images) {
@ -375,7 +375,7 @@ export class WooCommerce implements INodeType {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const body: IOrder = {}; const body: IOrder = {};
setFields(additionalFields, body) setFields(additionalFields, body);
const billing = (this.getNodeParameter('billingUi', i) as IDataObject).billingValues as IAddress; const billing = (this.getNodeParameter('billingUi', i) as IDataObject).billingValues as IAddress;
if (billing !== undefined) { if (billing !== undefined) {