diff --git a/src/lib/customers.ts b/src/lib/customers.ts index 8a67406..b707bdd 100644 --- a/src/lib/customers.ts +++ b/src/lib/customers.ts @@ -3,7 +3,7 @@ import { query } from '../utils/PostgresConnection' import { pg as sql } from 'yesql' import { getConfig } from '../utils/config' import { stripe } from '../utils/StripeClientManager' -import { constructUpsertSql } from '../utils/helpers' +import { cleanseArrayField, constructUpsertSql } from '../utils/helpers' import { customerSchema } from '../schemas/customer' const config = getConfig() @@ -13,7 +13,8 @@ export const upsertCustomer = async (customer: Customer.Customer): Promise => const upsertString = constructUpsertSql(config.SCHEMA || 'stripe', 'prices', priceSchema) // Inject the values - const prepared = sql(upsertString)(price) + const cleansed = cleanseArrayField(price) + const prepared = sql(upsertString)(cleansed) // Run it const { rows } = await query(prepared.text, prepared.values) diff --git a/src/lib/products.ts b/src/lib/products.ts index bddc45e..f06dcdd 100644 --- a/src/lib/products.ts +++ b/src/lib/products.ts @@ -4,7 +4,7 @@ import { pg as sql } from 'yesql' import { getConfig } from '../utils/config' import { stripe } from '../utils/StripeClientManager' import { productSchema } from '../schemas/product' -import { constructUpsertSql } from '../utils/helpers' +import { cleanseArrayField, constructUpsertSql } from '../utils/helpers' const config = getConfig() @@ -13,7 +13,8 @@ export const upsertProduct = async (product: Product.Product): Promise { + const cleansed = { ...obj } + Object.keys(cleansed).map((k) => { + const data = cleansed[k] + if (Array.isArray(data)) { + cleansed[k] = JSON.stringify(data) + } + }) + return cleansed +}