Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 deletions src/app/api/quickbooks/product/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,44 +548,54 @@ export class ProductService extends BaseService {
)
const productDescription = convert(copilotProduct.description)

const tokenService = new TokenService(this.user)
const incomeAccountRef = await tokenService.checkAndUpdateAccountStatus(
AccountTypeObj.Income,
qbTokenInfo.intuitRealmId,
intuitApi,
qbTokenInfo.incomeAccountRef,
)
// create item in QB
const item = await this.createItemInQB(
{
productName: z.string().parse(qbItemName),
unitPrice: priceResource.amount,
incomeAccRefVal: z.string().parse(incomeAccountRef),
productDescription,
},
intuitApi,
)
// check if item with name exists in QBO
let qbItem = await intuitApi.getAnItem(qbItemName, undefined, true)

if (!qbItem) {
const tokenService = new TokenService(this.user)
const incomeAccountRef = await tokenService.checkAndUpdateAccountStatus(
AccountTypeObj.Income,
qbTokenInfo.intuitRealmId,
intuitApi,
qbTokenInfo.incomeAccountRef,
)
// create item in QB
qbItem = await this.createItemInQB(
{
productName: z.string().parse(qbItemName),
unitPrice: priceResource.amount,
incomeAccRefVal: z.string().parse(incomeAccountRef),
productDescription,
},
intuitApi,
)
}

// map product and price
await this.createQBProduct({
portalId: this.user.workspaceId,
productId: priceResource.productId,
priceId: priceResource.id,
unitPrice: priceResource.amount.toFixed(2),
qbItemId: item.Id,
qbSyncToken: item.SyncToken,
qbItemId: qbItem.Id,
qbSyncToken: qbItem.SyncToken,
name: qbItemName,
copilotName: copilotProduct.name,
description: productDescription,
})

console.info('WebhookService#webhookPriceCreated | Product created in QB')
await this.logSync(priceResource.productId, item.Id, EventType.CREATED, {
productName: copilotProduct.name,
productPrice: priceResource.amount.toFixed(2),
qbItemName: item.Name,
copilotPriceId: priceResource.id,
})
await this.logSync(
priceResource.productId,
qbItem.Id,
EventType.CREATED,
{
productName: copilotProduct.name,
productPrice: priceResource.amount.toFixed(2),
qbItemName: qbItem.Name,
copilotPriceId: priceResource.id,
},
)

this.unsetTransaction()
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/quickbooks/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import CustomLogger from '@/utils/logger'
import { QBSyncLog, QBSyncLogSelectSchemaType } from '@/db/schema/qbSyncLogs'
import { z } from 'zod'
import { and, eq, inArray, max } from 'drizzle-orm'

Check warning on line 20 in src/app/api/quickbooks/sync/sync.service.ts

View workflow job for this annotation

GitHub Actions / Run linters

'max' is defined but never used. Allowed unused vars must match /^_/u
import { WhereClause } from '@/type/common'
import { TokenService } from '@/app/api/quickbooks/token/token.service'
import { QBPortalConnection } from '@/db/schema/qbPortalConnections'
Expand Down Expand Up @@ -522,7 +522,7 @@
// report to sentry if any records has exceeded max retry count
if (attempt == MAX_ATTEMPTS) {
captureMessage(
`SyncService#intiateSync | Records exceeded max retry count. Portal Id: ${this.user.workspaceId}.`,
`SyncService#checkAndUpdateAttempt | Records exceeded max retry count. Portal Id: ${this.user.workspaceId}.`,
{
tags: {
key: 'exceedMaxAttempts', // can be used to search like "key:exceedMaxAttempts"
Expand Down
Loading