Skip to content
Open
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"dev": "next dev --turbopack",
"trigger:dev": "npx [email protected] dev",
"trigger:deploy": "npx [email protected] deploy",
"dev:embedded": "node scripts/dev.js",
"build": "next build",
"start": "next start",
Expand All @@ -16,7 +17,9 @@
"lint-staged": "npx lint-staged",
"prepare": "husky",
"supabase:dev": "supabase start --ignore-health-check",
"cmd:rename-qb-accounts": "tsx src/cmd/renameQbAccount/index.ts"
"cmd:rename-qb-accounts": "tsx src/cmd/renameQbAccount/index.ts",
"cmd:check-impact-on-workspace": "tsx src/cmd/checkWorkspaceInvoice/index.ts",
"cmd:seed-impacted-workspace": "tsx src/cmd/seedPortalImpactVerification.ts"
},
"dependencies": {
"@sentry/nextjs": "^9.13.0",
Expand Down Expand Up @@ -88,4 +91,4 @@
"yarn prettier:fix"
]
}
}
}
2 changes: 1 addition & 1 deletion src/app/api/core/constants/limit.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const MAX_PRODUCT_LIST_LIMIT = 1_000
export const MAX_INVOICE_LIST_LIMIT = 10_000
export const MAX_INVOICE_LIST_LIMIT = 1_000
31 changes: 21 additions & 10 deletions src/app/api/quickbooks/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getPortalConnection,
getPortalSettings,
} from '@/db/service/token.service'
import { checkIncorrectlySyncedInvoiceForPortal } from '@/trigger/checkImpactedInvoiceForPortal'
import {
QBAuthTokenResponse,
QBAuthTokenResponseSchema,
Expand Down Expand Up @@ -174,7 +175,7 @@ export class AuthService extends BaseService {

const tokenService = new TokenService(this.user)
// check if the token exists
const existingToken = await tokenService.getOneByPortalId(portalId)
const existingPortal = await tokenService.getOneByPortalId(portalId)

const insertPayload: QBPortalConnectionCreateSchemaType = {
intuitRealmId: realmId,
Expand All @@ -186,9 +187,9 @@ export class AuthService extends BaseService {
tokenSetTime,
tokenType: tokenInfo.token_type,
intiatedBy: this.user.internalUserId as string, // considering this is defined since we know this action is intiated by an IU
incomeAccountRef: existingToken?.incomeAccountRef || '',
expenseAccountRef: existingToken?.expenseAccountRef || '',
assetAccountRef: existingToken?.assetAccountRef || '',
incomeAccountRef: existingPortal?.incomeAccountRef || '',
expenseAccountRef: existingPortal?.expenseAccountRef || '',
assetAccountRef: existingPortal?.assetAccountRef || '',
isSuspended: false, // default vaalue is false when created. Added this for the re-auth case.
}
const intuitApi = new IntuitAPI({
Expand All @@ -198,8 +199,8 @@ export class AuthService extends BaseService {
incomeAccountRef: insertPayload.incomeAccountRef,
expenseAccountRef: insertPayload.expenseAccountRef,
assetAccountRef: insertPayload.assetAccountRef,
serviceItemRef: existingToken?.serviceItemRef || null,
clientFeeRef: existingToken?.clientFeeRef || null,
serviceItemRef: existingPortal?.serviceItemRef || null,
clientFeeRef: existingPortal?.clientFeeRef || null,
})
// handle accounts
const createPayload = await this.handleAccountReferences(
Expand Down Expand Up @@ -229,11 +230,21 @@ export class AuthService extends BaseService {
})

after(async () => {
if (existingToken) {
console.info('Not initial process. Starting the re-sync process')
if (existingPortal) {
console.info(`Not initial connection for the portal: ${portalId}`)

// check for impacted portals that could have incorrectly synced invoices
checkIncorrectlySyncedInvoiceForPortal.trigger({
user: this.user,
portal: existingPortal,
})

console.info(
`Starting the re-sync process for the portal ${portalId}`,
)
this.user.qbConnection = {
serviceItemRef: existingToken.serviceItemRef,
clientFeeRef: existingToken.clientFeeRef,
serviceItemRef: existingPortal.serviceItemRef,
clientFeeRef: existingPortal.clientFeeRef,
}
const syncService = new SyncService(this.user)
await syncService.syncFailedRecords({
Expand Down
Loading
Loading