feat: enhance CustomerIndividual and CustomerLegal models with new unique input types
feat: add cache invalidation method for POS middleware feat: implement Redis caching in POS middleware for improved performance feat: refactor sales invoice DTOs for POS to include correction functionality feat: extend SalesInvoicesController to handle invoice corrections and returns feat: update SalesInvoicesService to support invoice correction and return operations feat: enhance TSP provider correction functionality with new DTOs and utility methods fix: improve error handling and logging in Nama provider switch adapter refactor: streamline invoice payload building in TSP provider utilities
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
TspProviderBulkSendResultDto,
|
||||
} from '../../dto/provider-switch.dto'
|
||||
import {
|
||||
NamaProviderCorrectionResponseDto,
|
||||
NamaProviderGetResponseDto,
|
||||
NamaProviderOriginalResponseDto,
|
||||
NamaProviderResponseStatus,
|
||||
@@ -38,6 +39,7 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
||||
process.env.NAMA_PROVIDER_PRODUCTION_URL || 'https://api.nama.ir'
|
||||
|
||||
private readonly sendPath = '/api/v1/invoices/single-send'
|
||||
private readonly correctionPath = this.sendPath
|
||||
private readonly sendBulkPath = '/api/v1/invoices'
|
||||
private readonly checkBulkStatus = '/api/v1/invoices/check-by-uuids'
|
||||
private readonly getPath = '/api/v1/invoices'
|
||||
@@ -57,6 +59,10 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
||||
return `${this.baseUrl}${this.sendPath}`
|
||||
}
|
||||
|
||||
private buildCorrectionUrl() {
|
||||
return `${this.baseUrl}${this.correctionPath}`
|
||||
}
|
||||
|
||||
private buildGetUrl(invoiceId: string) {
|
||||
return `${this.baseUrl}${this.getPath}/${invoiceId}`
|
||||
}
|
||||
@@ -110,9 +116,8 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
||||
|
||||
return result
|
||||
} catch (err) {
|
||||
console.log('err@@@@@@@@@@@@@@@@@@', err);
|
||||
console.log(JSON.parse(JSON.stringify(mappedRequest)));
|
||||
|
||||
console.log('err@@@@@@@@@@@@@@@@@@', err)
|
||||
console.log(JSON.parse(JSON.stringify(mappedRequest)))
|
||||
|
||||
const failure: TspProviderOriginalResponseDto = {
|
||||
invoice_id: payload.id,
|
||||
@@ -129,21 +134,21 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
||||
async correctionSend(
|
||||
payload: TspProviderCorrectionSendPayloadDto,
|
||||
): Promise<TspProviderCorrectionSendResponseDto> {
|
||||
const mappedRequest = this.namaProviderUtils.mapToNamaOriginalRequestDto(payload)
|
||||
const mappedRequest = this.namaProviderUtils.mapToNamaCorrectionDto(payload)
|
||||
|
||||
try {
|
||||
const response = await this.httpClient.request(
|
||||
this.buildSendUrl(),
|
||||
this.buildCorrectionUrl(),
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify(mappedRequest),
|
||||
},
|
||||
this.createRequestInterceptors(payload.token),
|
||||
)
|
||||
const providerResponse: NamaProviderOriginalResponseDto = await response.json()
|
||||
this.logger.debug('NAMA provider response', providerResponse)
|
||||
const providerResponse: NamaProviderCorrectionResponseDto = await response.json()
|
||||
this.logger.debug('NAMA provider correction response', providerResponse)
|
||||
|
||||
const result: TspProviderOriginalResponseDto = {
|
||||
const result: TspProviderCorrectionSendResponseDto = {
|
||||
invoice_id: payload.id,
|
||||
provider_request_payload: JSON.parse(JSON.stringify(mappedRequest)),
|
||||
hasError: !response.ok,
|
||||
@@ -158,15 +163,14 @@ export class NamaProviderSwitchAdapter implements IProviderSwitchAdapter {
|
||||
|
||||
return result
|
||||
} catch (err) {
|
||||
this.logger.error('NAMA send failed', err)
|
||||
const failure: TspProviderOriginalResponseDto = {
|
||||
this.logger.error('NAMA correction send failed', err)
|
||||
const failure: TspProviderCorrectionSendResponseDto = {
|
||||
invoice_id: payload.id,
|
||||
provider_request_payload: JSON.parse(JSON.stringify(mappedRequest)),
|
||||
hasError: true,
|
||||
message: (err as Error).message,
|
||||
received_at: new Date().toISOString(),
|
||||
tax_id: null,
|
||||
status: TspProviderResponseStatus.NOT_SEND,
|
||||
status: TspProviderResponseStatus.SEND_FAILURE,
|
||||
}
|
||||
return failure
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user