forked from Yara724/api
Added API for externalAPI, added env for clients
This commit is contained in:
@@ -142,6 +142,38 @@ export class ClientService {
|
||||
return await this.clientDbService.find({ clientCode: companyCode });
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a client by insurer company code from an external inquiry.
|
||||
* Creates the client when missing so inquiry flows don't fail on unknown codes.
|
||||
*/
|
||||
async findOrCreateClientByCompanyCode(
|
||||
companyCode: number | string | null | undefined,
|
||||
companyName: string | null | undefined,
|
||||
) {
|
||||
const name = typeof companyName === "string" ? companyName.trim() : "";
|
||||
const code = Number(companyCode);
|
||||
if (!name || !Number.isFinite(code)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let client = await this.clientDbService.find({ clientCode: code });
|
||||
if (client) return client;
|
||||
|
||||
try {
|
||||
await this.addClient({
|
||||
clientName: { persian: name, english: null },
|
||||
clientCode: code,
|
||||
useExpertMode: "legal",
|
||||
});
|
||||
} catch (err) {
|
||||
client = await this.clientDbService.find({ clientCode: code });
|
||||
if (client) return client;
|
||||
throw err;
|
||||
}
|
||||
|
||||
return this.clientDbService.find({ clientCode: code });
|
||||
}
|
||||
|
||||
async getClients(): Promise<ClientDtoRs[]> {
|
||||
const clients = await this.clientDbService.findAll();
|
||||
const show = clients.map((c) => new ClientDtoRs(c));
|
||||
|
||||
Reference in New Issue
Block a user