Skip to content
Merged
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
24 changes: 14 additions & 10 deletions src/app/api/quickbooks/customer/customer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class CustomerService extends BaseService {
givenName: client.givenName,
displayName: `${client.givenName} ${client.familyName} (${company.name})`,
type: 'client' as const,
email: client.email || '',
email: client.email,
companyId: company.id,
companyName: company.name,
}
Expand All @@ -226,11 +226,11 @@ export class CustomerService extends BaseService {
return {
recipientInfo: {
...clientCompany,
familyName: client?.familyName || '',
givenName: client?.givenName || '',
familyName: client.familyName,
givenName: client.givenName,
displayName,
email: client?.email || '',
companyId: client?.companyId || '',
email: client.email,
companyId: client.companyId,
},
companyInfo: company,
}
Expand Down Expand Up @@ -335,10 +335,14 @@ export class CustomerService extends BaseService {
invoiceResource: InvoiceCreatedResponseType['data']
}) {
const displayName = recipientInfo.displayName
// 2.1. search client in qb using recipient's email
let customer = await intuitApiService.getCustomerByEmail(
recipientInfo.email,
)
// 2.1. search client in qb using recipient's email or
let customer = recipientInfo.email
? await intuitApiService.getCustomerByEmail(recipientInfo.email)
: await intuitApiService.getACustomer(
replaceSpecialCharsForQB(recipientInfo.displayName),
undefined,
true,
)

// 3. if not found, create a new client in the QB
if (!customer) {
Expand All @@ -350,7 +354,7 @@ export class CustomerService extends BaseService {
DisplayName: displayName,
CompanyName: companyInfo && replaceSpecialCharsForQB(companyInfo.name),
PrimaryEmailAddr: {
Address: recipientInfo?.email || '',
Address: recipientInfo.email,
},
}

Expand Down
Loading