update get status of tsp provider

This commit is contained in:
2026-05-27 22:44:01 +03:30
parent 816c5ebb50
commit cd3492d625
9 changed files with 116 additions and 164 deletions
@@ -8,7 +8,8 @@ import {
} from 'generated/prisma/client'
import {
TspProviderCorrectionSendPayloadDto,
TspProviderOriginalSendItemResultDto,
TspProviderGetResponseDto,
TspProviderOriginalResponseDto,
TspProviderOriginalSendPayloadDto,
TspProviderRevokePayloadDto,
} from '../dto'
@@ -473,27 +474,29 @@ export async function trySend(
tspSwitchService: {
send(
payload: TspProviderOriginalSendPayloadDto,
): Promise<TspProviderOriginalSendItemResultDto>
): Promise<TspProviderOriginalResponseDto>
},
payload: TspProviderOriginalSendPayloadDto,
): Promise<TspProviderOriginalSendItemResultDto> {
): Promise<TspProviderOriginalResponseDto> {
return (await tspSwitchService.send(payload)) || null
}
export async function onResult(
prisma: PrismaService,
result: TspProviderOriginalSendItemResultDto,
result: TspProviderOriginalResponseDto | TspProviderGetResponseDto,
attempt_id: string,
): Promise<TspProviderActionResponseDto> {
let attemptUpdatedData: SaleInvoiceTspAttemptsUpdateInput = {}
console.log('attempt', result, attempt_id)
const resultMessage = result.message
if (result) {
attemptUpdatedData = {
provider_request_payload: JSON.parse(
JSON.stringify(result.provider_request_payload),
),
provider_request_payload: result['provider_request_payload']
? JSON.parse(JSON.stringify(result['provider_request_payload']))
: undefined,
provider_response: JSON.parse(JSON.stringify(result.provider_response)),
status: result.status,
received_at: result.received_at || new Date().toISOString(),
@@ -504,18 +507,18 @@ export async function onResult(
: 'فاکتور با موفقیت به سامانه مالیاتی ارسال شد.',
invoice: {
update: {
tax_id: result.tax_id,
tax_id: result['tax_id'] ? result['tax_id'] : undefined,
},
},
}
if (result.hasError) {
;((attemptUpdatedData.error_message = result.error_message),
(attemptUpdatedData.validation_errors = JSON.parse(
JSON.stringify(result.validation_errors),
)),
(attemptUpdatedData.fiscal_warnings = JSON.parse(
JSON.stringify(result.fiscal_warnings),
)))
attemptUpdatedData.error_message = result.error_message
attemptUpdatedData.validation_errors = JSON.parse(
JSON.stringify(result.validation_errors),
)
attemptUpdatedData.fiscal_warnings = JSON.parse(
JSON.stringify(result.fiscal_warnings),
)
}
} else {
attemptUpdatedData = {