moallem all endpoints working

This commit is contained in:
2026-06-14 16:42:52 +03:30
parent 7a6e482586
commit 2212f6da41
18 changed files with 833 additions and 234 deletions

View File

@@ -23,76 +23,19 @@ export class InquiryService {
private readonly inquiryLogService: InquiryLogService,
) {}
/**
* Person inquiry — unified business flow with provider fallback and audit logging.
*/
async inquirePerson(
dto: PersonInquiryRequestDto,
requestId: string,
): Promise<BaseInquiryResponseDto<PersonInquiryDataDto>> {
const trackingCode = generateTrackingCode();
const payload: PersonInquiryPayload = {
nationalCode: dto.nationalCode,
birthDate: dto.birthDate,
dateHasPostfix: (dto as PersonInquiryRequestDto & { dateHasPostfix?: number }).dateHasPostfix,
};
const start = Date.now();
try {
const result = await this.executeInquiry<PersonInquiryPayload, PersonInquiryResult>(
InquiryType.PERSON,
payload,
requestId,
trackingCode,
);
const response = this.buildSuccessResponse(
result.data,
result.provider,
trackingCode,
result.duration,
'Person inquiry completed successfully',
);
await this.persistLog({
inquiryType: InquiryType.PERSON,
provider: result.provider,
requestPayload: payload as unknown as Record<string, unknown>,
responsePayload: response.data as unknown as Record<string, unknown>,
status: InquiryStatus.SUCCESS,
duration: result.duration,
requestId,
trackingCode,
});
return response;
} catch (error) {
const duration = Date.now() - start;
const normalized = this.extractError(error);
const response: BaseInquiryResponseDto<PersonInquiryDataDto> = {
success: false,
provider: 'GATEWAY',
trackingCode,
message: normalized.message,
error: normalized,
duration,
};
await this.persistLog({
inquiryType: InquiryType.PERSON,
provider: ProviderName.HAMTA,
requestPayload: payload as unknown as Record<string, unknown>,
status: InquiryStatus.FAILURE,
duration,
requestId,
trackingCode,
error: normalized as unknown as Record<string, unknown>,
}).catch(() => undefined);
return response;
}
return this.inquire(
InquiryType.PERSON,
{
nationalCode: dto.nationalCode,
birthDate: dto.birthDate,
dateHasPostfix: dto.dateHasPostfix,
},
requestId,
) as unknown as Promise<BaseInquiryResponseDto<PersonInquiryDataDto>>;
}
async inquire(
@@ -111,7 +54,7 @@ export class InquiryService {
trackingCode,
);
const response = this.buildGenericSuccessResponse(
const response = this.buildSuccessResponse(
result.data,
result.provider,
trackingCode,
@@ -172,27 +115,6 @@ export class InquiryService {
}
private buildSuccessResponse(
result: PersonInquiryResult,
provider: string,
trackingCode: string,
duration: number,
message: string,
): BaseInquiryResponseDto<PersonInquiryDataDto> {
return {
success: true,
provider,
trackingCode,
message,
duration,
data: {
nationalCode: result.nationalCode,
birthDate: result.birthDate,
fullName: result.fullName,
},
};
}
private buildGenericSuccessResponse(
result: unknown,
provider: string,
trackingCode: string,
@@ -210,6 +132,20 @@ export class InquiryService {
}
private toResponseData(result: unknown): Record<string, unknown> {
if (this.isPersonInquiryResult(result)) {
const raw =
result.raw && typeof result.raw === 'object' && !Array.isArray(result.raw)
? (result.raw as Record<string, unknown>)
: {};
return {
nationalCode: result.nationalCode,
birthDate: result.birthDate,
...(result.fullName ? { fullName: result.fullName } : {}),
...raw,
};
}
if (result && typeof result === 'object' && 'raw' in result) {
const raw = (result as { raw: unknown }).raw;
return raw && typeof raw === 'object' ? (raw as Record<string, unknown>) : { raw };
@@ -220,6 +156,15 @@ export class InquiryService {
: { raw: result };
}
private isPersonInquiryResult(result: unknown): result is PersonInquiryResult {
return (
typeof result === 'object' &&
result !== null &&
'nationalCode' in result &&
'birthDate' in result
);
}
private getInquiryLabel(inquiryType: InquiryType): string {
return inquiryType.replace(/_INQUIRY$/, '').toLowerCase().replace(/_/g, ' ');
}