forked from Yara724/api
Added API for externalAPI, added env for clients
This commit is contained in:
@@ -1160,24 +1160,16 @@ export class RequestManagementService {
|
||||
);
|
||||
}
|
||||
const companyCode = inquiryMapped?.CompanyCode;
|
||||
let client =
|
||||
await this.clientService.findClientWithCompanyCode(+companyCode);
|
||||
|
||||
const client = await this.clientService.findOrCreateClientByCompanyCode(
|
||||
companyCode,
|
||||
clientName,
|
||||
);
|
||||
if (!client) {
|
||||
await this.clientService.addClient({
|
||||
clientName: {
|
||||
persian: clientName,
|
||||
english: null,
|
||||
},
|
||||
clientCode: Number(companyCode),
|
||||
useExpertMode: "legal",
|
||||
});
|
||||
throw new BadRequestException(
|
||||
`CompanyCode missing or invalid in inquiry response`,
|
||||
);
|
||||
}
|
||||
|
||||
// if (!client) {
|
||||
// throw new HttpException("Client not found", HttpStatus.CONFLICT);
|
||||
// }
|
||||
|
||||
// Persist inquiry/body data into new model
|
||||
if (!party.person) party.person = {} as any;
|
||||
const resolvedClientId =
|
||||
@@ -1286,27 +1278,13 @@ export class RequestManagementService {
|
||||
const carBodyCompanyCode = m.companyId ?? m.CompanyCode;
|
||||
const carBodyCompanyName = m.CompanyName ?? m.companyPersianName;
|
||||
|
||||
if (carBodyCompanyCode) {
|
||||
let carBodyClient: any =
|
||||
await this.clientService.findClientWithCompanyCode(
|
||||
Number(carBodyCompanyCode),
|
||||
if (carBodyCompanyCode && carBodyCompanyName) {
|
||||
const carBodyClient =
|
||||
await this.clientService.findOrCreateClientByCompanyCode(
|
||||
carBodyCompanyCode,
|
||||
carBodyCompanyName,
|
||||
);
|
||||
|
||||
if (!carBodyClient && carBodyCompanyName) {
|
||||
await this.clientService.addClient({
|
||||
clientName: {
|
||||
persian: carBodyCompanyName,
|
||||
english: null,
|
||||
},
|
||||
clientCode: Number(carBodyCompanyCode),
|
||||
useExpertMode: "legal",
|
||||
});
|
||||
// Re-fetch after creation so we get the actual document with _id
|
||||
carBodyClient = await this.clientService.findClientWithCompanyCode(
|
||||
Number(carBodyCompanyCode),
|
||||
);
|
||||
}
|
||||
|
||||
const carBodyClientId =
|
||||
(carBodyClient as any)?._id ?? (carBodyClient as any)?._doc?._id;
|
||||
|
||||
@@ -2075,8 +2053,10 @@ export class RequestManagementService {
|
||||
const clientName = sandHubReport?.CompanyName;
|
||||
const companyCode = sandHubReport?.CompanyCode;
|
||||
|
||||
const client =
|
||||
await this.clientService.findClientWithCompanyCode(+companyCode);
|
||||
const client = await this.clientService.findOrCreateClientByCompanyCode(
|
||||
companyCode,
|
||||
clientName,
|
||||
);
|
||||
|
||||
if (!client) {
|
||||
throw new HttpException("Client not found", HttpStatus.CONFLICT);
|
||||
@@ -5021,7 +5001,10 @@ export class RequestManagementService {
|
||||
sandHubReport?.CompanyName || sandHubReport?.LastCompanyName;
|
||||
const companyCode = sandHubReport?.CompanyCode;
|
||||
const client = companyCode
|
||||
? await this.clientService.findClientWithCompanyCode(+companyCode)
|
||||
? await this.clientService.findOrCreateClientByCompanyCode(
|
||||
companyCode,
|
||||
clientName,
|
||||
)
|
||||
: await this.clientService.findOne({ clientName });
|
||||
if (!client) {
|
||||
throw new NotFoundException(
|
||||
@@ -5228,7 +5211,10 @@ export class RequestManagementService {
|
||||
sandHubReport?.CompanyName || sandHubReport?.LastCompanyName;
|
||||
const companyCode = sandHubReport?.CompanyCode;
|
||||
const client = companyCode
|
||||
? await this.clientService.findClientWithCompanyCode(+companyCode)
|
||||
? await this.clientService.findOrCreateClientByCompanyCode(
|
||||
companyCode,
|
||||
clientName,
|
||||
)
|
||||
: await this.clientService.findOne({ clientName });
|
||||
if (!client) {
|
||||
throw new NotFoundException(
|
||||
@@ -5834,7 +5820,10 @@ export class RequestManagementService {
|
||||
|
||||
// Try to find client by company code first (more reliable)
|
||||
const client = companyCode
|
||||
? await this.clientService.findClientWithCompanyCode(+companyCode)
|
||||
? await this.clientService.findOrCreateClientByCompanyCode(
|
||||
companyCode,
|
||||
clientName,
|
||||
)
|
||||
: await this.clientService.findOne({ clientName: clientName });
|
||||
|
||||
if (!client) {
|
||||
@@ -5898,7 +5887,10 @@ export class RequestManagementService {
|
||||
|
||||
// Try to find client by company code first (more reliable)
|
||||
const client = companyCode
|
||||
? await this.clientService.findClientWithCompanyCode(+companyCode)
|
||||
? await this.clientService.findOrCreateClientByCompanyCode(
|
||||
companyCode,
|
||||
clientName,
|
||||
)
|
||||
: await this.clientService.findOne({ clientName: clientName });
|
||||
|
||||
if (!client) {
|
||||
@@ -6168,7 +6160,10 @@ export class RequestManagementService {
|
||||
|
||||
// Try to find client by company code first (more reliable)
|
||||
const client = companyCode
|
||||
? await this.clientService.findClientWithCompanyCode(+companyCode)
|
||||
? await this.clientService.findOrCreateClientByCompanyCode(
|
||||
companyCode,
|
||||
clientName,
|
||||
)
|
||||
: await this.clientService.findOne({ clientName: clientName });
|
||||
|
||||
if (!client) {
|
||||
|
||||
Reference in New Issue
Block a user