Added API for externalAPI, added env for clients

This commit is contained in:
SepehrYahyaee
2026-06-13 11:26:33 +03:30
parent cb47069e90
commit 3abbd45fac
13 changed files with 335 additions and 161 deletions

View File

@@ -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));