forked from Shared/esg
some error handler + error validation + realEstate bug fixed for hamta end moallem
This commit is contained in:
@@ -51,6 +51,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
InquiryType.SHEBA,
|
||||
InquiryType.SHAHKAR,
|
||||
InquiryType.POSTAL_CODE,
|
||||
InquiryType.REAL_ESTATE,
|
||||
];
|
||||
|
||||
private readonly hamtaConfig: ProviderEnvConfig;
|
||||
|
||||
@@ -51,6 +51,7 @@ export class MoallemProvider extends LegacyApiProvider {
|
||||
InquiryType.SHEBA,
|
||||
InquiryType.SHAHKAR,
|
||||
InquiryType.POSTAL_CODE,
|
||||
InquiryType.REAL_ESTATE,
|
||||
];
|
||||
|
||||
private readonly moallemConfig: ProviderEnvConfig;
|
||||
|
||||
@@ -10,8 +10,16 @@ import { AmitisProvider } from './amitis.provider';
|
||||
import {
|
||||
LegacyInquiryPayload,
|
||||
LegacyInquiryResult,
|
||||
PersonInquiryResult,
|
||||
} from '../shared/legacy-api.provider.abstract';
|
||||
|
||||
interface ParsianCivilRegistrationPayload extends LegacyInquiryPayload {
|
||||
nationalCode?: string;
|
||||
birthDate?: string;
|
||||
NIN?: string;
|
||||
BirthDate?: string;
|
||||
}
|
||||
|
||||
interface ParsianShahkarPayload extends LegacyInquiryPayload {
|
||||
nationalCode?: string;
|
||||
nationalCod?: string;
|
||||
@@ -71,6 +79,7 @@ interface ParsianPolicyByPlatePayload extends LegacyInquiryPayload {
|
||||
export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyInquiryResult> {
|
||||
readonly name = ProviderName.PARSIAN;
|
||||
readonly supportedInquiryTypes = [
|
||||
InquiryType.PERSON,
|
||||
InquiryType.SHAHKAR,
|
||||
InquiryType.SHEBA,
|
||||
InquiryType.POLICY_BY_CHASSIS,
|
||||
@@ -86,6 +95,7 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
}
|
||||
|
||||
isEnabled(): boolean {
|
||||
const personConfig = this.config.inquiries[InquiryType.PERSON];
|
||||
const shahkarConfig = this.config.inquiries[InquiryType.SHAHKAR];
|
||||
const shebaConfig = this.config.inquiries[InquiryType.SHEBA];
|
||||
const policyByChassisConfig = this.config.inquiries[InquiryType.POLICY_BY_CHASSIS];
|
||||
@@ -95,7 +105,8 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
|
||||
return (
|
||||
this.config.enabled &&
|
||||
((Boolean(shahkarConfig?.url) && Boolean(shahkarConfig?.apiKey)) ||
|
||||
(this.hasSoapCredentials(personConfig) ||
|
||||
(Boolean(shahkarConfig?.url) && Boolean(shahkarConfig?.apiKey)) ||
|
||||
(Boolean(shebaConfig?.url) &&
|
||||
Boolean(shebaConfig?.username) &&
|
||||
Boolean(shebaConfig?.password)) ||
|
||||
@@ -110,6 +121,10 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
payload: LegacyInquiryPayload,
|
||||
_context: ProviderExecutionContext,
|
||||
): Promise<LegacyInquiryResult> {
|
||||
if (inquiryType === InquiryType.PERSON) {
|
||||
return this.inquireCivilRegistration(payload as ParsianCivilRegistrationPayload);
|
||||
}
|
||||
|
||||
if (inquiryType === InquiryType.SHAHKAR) {
|
||||
return this.inquireShahkar(payload as ParsianShahkarPayload);
|
||||
}
|
||||
@@ -188,6 +203,64 @@ export class ParsianProvider extends BaseProvider<LegacyInquiryPayload, LegacyIn
|
||||
}
|
||||
}
|
||||
|
||||
private async inquireCivilRegistration(
|
||||
payload: ParsianCivilRegistrationPayload,
|
||||
): Promise<PersonInquiryResult> {
|
||||
const nationalCode = this.getRequiredString(
|
||||
payload.nationalCode ?? payload.NIN,
|
||||
'nationalCode',
|
||||
);
|
||||
const birthDate = this.getRequiredString(payload.birthDate ?? payload.BirthDate, 'birthDate');
|
||||
const inquiryConfig = this.config.inquiries[InquiryType.PERSON];
|
||||
|
||||
if (!this.hasSoapCredentials(inquiryConfig)) {
|
||||
throw this.formatProviderError(
|
||||
undefined,
|
||||
undefined,
|
||||
'Parsian person inquiry is not configured',
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.post<string>(
|
||||
inquiryConfig.url,
|
||||
this.buildCivilRegistrationEnvelope(
|
||||
nationalCode,
|
||||
birthDate,
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
),
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'text/xml; charset=utf-8',
|
||||
SOAPAction: '"http://tempuri.org/ISabtInq/SubmitInqDteStsWithPstCod"',
|
||||
},
|
||||
timeout: this.config.timeout,
|
||||
responseType: 'text',
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
nationalCode,
|
||||
birthDate,
|
||||
raw: {
|
||||
nationalCode,
|
||||
birthDate,
|
||||
result: this.extractSoapValue(response.data, 'SubmitInqDteStsWithPstCodResult'),
|
||||
soap: response.data,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof AxiosError) {
|
||||
throw this.formatProviderError(
|
||||
error.message,
|
||||
String(error.response?.status ?? 'NETWORK_ERROR'),
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private async inquirePolicyByChassis(
|
||||
payload: ParsianPolicyByChassisPayload,
|
||||
): Promise<{ raw: unknown }> {
|
||||
@@ -401,6 +474,27 @@ ${fieldXml}
|
||||
</soap:Envelope>`;
|
||||
}
|
||||
|
||||
private buildCivilRegistrationEnvelope(
|
||||
nationalCode: string,
|
||||
birthDate: string,
|
||||
username: string,
|
||||
password: string,
|
||||
): string {
|
||||
return `<?xml version="1.0" encoding="utf-8"?>
|
||||
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body>
|
||||
<SubmitInqDteStsWithPstCod xmlns="http://tempuri.org/">
|
||||
<NIN>${this.escapeXml(nationalCode)}</NIN>
|
||||
<BirthDate>${this.escapeXml(birthDate)}</BirthDate>
|
||||
<Username>${this.escapeXml(username)}</Username>
|
||||
<Password>${this.escapeXml(password)}</Password>
|
||||
</SubmitInqDteStsWithPstCod>
|
||||
</soap:Body>
|
||||
</soap:Envelope>`;
|
||||
}
|
||||
|
||||
private extractSoapValue(xml: string, tagName: string): string | null {
|
||||
const match = xml.match(
|
||||
new RegExp(`<(?:\\w+:)?${tagName}[^>]*>([\\s\\S]*?)</(?:\\w+:)?${tagName}>`),
|
||||
|
||||
Reference in New Issue
Block a user