From 3f1106439a8707e8c915041782869a6aedd8bfa8 Mon Sep 17 00:00:00 2001 From: SandipBajracharya Date: Thu, 5 Mar 2026 15:47:28 +0545 Subject: [PATCH 1/2] fix(OUT-3278): prioritize product description from Assembly --- .../api/quickbooks/invoice/invoice.service.ts | 34 ++++++++++++------- src/type/dto/webhook.dto.ts | 14 ++++---- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/app/api/quickbooks/invoice/invoice.service.ts b/src/app/api/quickbooks/invoice/invoice.service.ts index 01e9163..43050c7 100644 --- a/src/app/api/quickbooks/invoice/invoice.service.ts +++ b/src/app/api/quickbooks/invoice/invoice.service.ts @@ -164,7 +164,8 @@ export class InvoiceService extends BaseService { const priceUpdatePayload = { copilotUnitPrice: itemAmount, } - const conditions = eq(QBProductSync.id, mappingId) as WhereClause + const conditions = eq(QBProductSync.id, mappingId) + await productService.updateQBProduct(priceUpdatePayload, conditions) console.info('Copilot unit price updated in mapping table') return itemAmount @@ -181,6 +182,19 @@ export class InvoiceService extends BaseService { incomeAccRef: string, ): Promise { const productService = new ProductService(this.user) + + // get product info from assembly + const productInfo = await this.copilot.getProduct(productId) + if (!productInfo) { + throw new APIError( + httpStatus.NOT_FOUND, + 'Product not found. Id: ' + productId, + ) + } + const productDescription = productInfo.description + ? convert(productInfo.description) + : '' + const mapping = await productService.ensureProductExistsAndSyncToken( productId, priceId, @@ -211,7 +225,7 @@ export class InvoiceService extends BaseService { return { ref: { value: mapping.qbItemId }, amount: parseFloat(itemAmount) / 100, - productDescription: mapping.description || '', + productDescription, // classRef is optional. A classRef to the mapped QB item is checked every time for each item when creating an invoice. classRef: intuitItem.ClassRef, } @@ -232,19 +246,10 @@ export class InvoiceService extends BaseService { } // 2. create a new product in QB company - const productInfo = await this.copilot.getProduct(productId) const priceInfo = await this.copilot.getPrice(priceId) - if (!productInfo) { - throw new APIError( - httpStatus.NOT_FOUND, - 'Product not found. Id: ' + productId, - ) - } if (!priceInfo) { throw new APIError(httpStatus.NOT_FOUND, 'Price not found. Id:' + priceId) } - - const productDescription = convert(productInfo.description) const incomeAccRefVal = incomeAccRef // total products with the same product id @@ -464,7 +469,7 @@ export class InvoiceService extends BaseService { ): Promise { const invoice = invoiceResource.data // check invoice fee is paid by client - const clientWithFee = invoice?.paymentMethodPreferences.find( + const clientWithFee = invoice?.paymentMethodPreferences?.find( (preference) => preference.feePaidByClient === true, ) if (clientWithFee) { @@ -489,7 +494,10 @@ export class InvoiceService extends BaseService { const feeAmount = payments.data.reduce((acc, payment) => { - if (payment.feeAmount.paidByClient > 0) { + if ( + payment.feeAmount?.paidByClient && + payment.feeAmount.paidByClient > 0 + ) { return acc + payment.feeAmount.paidByClient } return acc diff --git a/src/type/dto/webhook.dto.ts b/src/type/dto/webhook.dto.ts index ce86949..6b1a132 100644 --- a/src/type/dto/webhook.dto.ts +++ b/src/type/dto/webhook.dto.ts @@ -37,12 +37,14 @@ export const InvoiceCreatedResponseSchema = z.object({ taxPercentage: z.number().default(0), sentDate: z.string().datetime().nullish(), dueDate: z.string().datetime().nullish(), - paymentMethodPreferences: z.array( - z.object({ - type: z.string(), - feePaidByClient: z.boolean(), - }), - ), + paymentMethodPreferences: z + .array( + z.object({ + type: z.string(), + feePaidByClient: z.boolean(), + }), + ) + .optional(), }), }) From 4ff26968ee5574c57bd4fa8311e7e22a9199b82b Mon Sep 17 00:00:00 2001 From: SandipBajracharya Date: Thu, 5 Mar 2026 16:32:29 +0545 Subject: [PATCH 2/2] refactor(OUT-3278): maintain code standard --- src/app/api/quickbooks/invoice/invoice.service.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/app/api/quickbooks/invoice/invoice.service.ts b/src/app/api/quickbooks/invoice/invoice.service.ts index 43050c7..18baf17 100644 --- a/src/app/api/quickbooks/invoice/invoice.service.ts +++ b/src/app/api/quickbooks/invoice/invoice.service.ts @@ -494,10 +494,7 @@ export class InvoiceService extends BaseService { const feeAmount = payments.data.reduce((acc, payment) => { - if ( - payment.feeAmount?.paidByClient && - payment.feeAmount.paidByClient > 0 - ) { + if (!!payment.feeAmount?.paidByClient) { return acc + payment.feeAmount.paidByClient } return acc