forked from Shared/esg
moallem all endpoints working
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import { mergeOutboundAxiosConfig } from '../../common/helpers/http-client.helper';
|
||||
import {
|
||||
getSayahProviderError,
|
||||
SayahApiResponse,
|
||||
} from '../../common/helpers/sayah-response.helper';
|
||||
import { InquiryType } from '../../common/enums/inquiry-type.enum';
|
||||
import { ProviderName } from '../../common/enums/provider-name.enum';
|
||||
import { ProviderEnvConfig } from '../../config/configuration';
|
||||
@@ -107,11 +112,11 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
try {
|
||||
const response = await axios.get<Record<string, unknown>>(
|
||||
`${inquiryConfig.url}/AddressByPostcode`,
|
||||
{
|
||||
mergeOutboundAxiosConfig({
|
||||
params: { PostalCode: postalCode },
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
timeout: this.hamtaConfig.timeout,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
return { raw: response.data };
|
||||
@@ -146,14 +151,14 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
),
|
||||
{
|
||||
mergeOutboundAxiosConfig({
|
||||
headers: {
|
||||
'Content-Type': 'text/xml; charset=utf-8',
|
||||
SOAPAction: '"http://tempuri.org/ISabtInq/SubmitInqDteStsWithPstCod"',
|
||||
},
|
||||
timeout: this.hamtaConfig.timeout,
|
||||
responseType: 'text',
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const result = this.extractSoapValue(response.data, 'SubmitInqDteStsWithPstCodResult');
|
||||
@@ -195,14 +200,14 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
inquiryConfig.username,
|
||||
inquiryConfig.password,
|
||||
),
|
||||
{
|
||||
mergeOutboundAxiosConfig({
|
||||
headers: {
|
||||
'Content-Type': 'text/xml; charset=utf-8',
|
||||
SOAPAction: '"http://tempuri.org/IShahkarInq/ShahkarInquery"',
|
||||
},
|
||||
timeout: this.hamtaConfig.timeout,
|
||||
responseType: 'text',
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const result = this.extractSoapValue(response.data, 'ShahkarInqueryResult');
|
||||
@@ -241,11 +246,7 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await axios.post<{
|
||||
IsSucceed?: boolean;
|
||||
Errors?: Array<{ Code?: string; Message?: string }>;
|
||||
Result?: unknown;
|
||||
}>(
|
||||
const response = await axios.post<SayahApiResponse>(
|
||||
inquiryConfig.url,
|
||||
{
|
||||
AccountOwnerType: accountOwnerType,
|
||||
@@ -253,20 +254,18 @@ export class HamtaProvider extends LegacyApiProvider {
|
||||
LegalId: legalId,
|
||||
ShebaId: shebaId,
|
||||
},
|
||||
{
|
||||
mergeOutboundAxiosConfig({
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: this.hamtaConfig.timeout,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
if (!response.data.IsSucceed && response.data.Errors) {
|
||||
throw this.formatProviderError(
|
||||
this.formatErrors(response.data.Errors),
|
||||
'SAYAH_HAS_ERROR',
|
||||
);
|
||||
const providerError = getSayahProviderError(response.data);
|
||||
if (providerError) {
|
||||
throw this.formatProviderError(providerError.message, providerError.code);
|
||||
}
|
||||
|
||||
return { raw: response.data };
|
||||
|
||||
Reference in New Issue
Block a user