feat: implement correction and original send functionality for Nama provider

- Added new DTOs for correction requests and responses in `nama-provider.dto.ts`.
- Updated `nama-provider.adapter.ts` to include `originalSend` and `correctionSend` methods.
- Enhanced `nama-provider.util.ts` with mapping functions for correction requests.
- Created operational guidelines for agents in `AGENT.md`.
- Updated Prisma migrations to support new invoice types and relationships.
- Introduced new service and DTO for creating sales invoices in `sale-invoice-create.service.ts` and `sale-invoice-create.dto.ts`.
- Added utility for handling Prisma errors in `prisma-error.util.ts`.
This commit is contained in:
2026-05-05 22:42:09 +03:30
parent 4af07fe3e8
commit 658496320b
43 changed files with 2808 additions and 1354 deletions
@@ -1,3 +1,7 @@
import {
SharedCreateSalesInvoiceItemDto,
SharedCreateSalesInvoicePaymentsDto,
} from '@/common/services/saleInvoices/sale-invoice-create.dto'
import {
CustomerType,
InvoiceTemplateType,
@@ -10,6 +14,7 @@ import {
import { ApiProperty } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import {
ArrayMinSize,
IsArray,
IsBoolean,
IsDateString,
@@ -142,7 +147,7 @@ export class TspProviderSendItemPayloadDto {
payload?: unknown
}
export class TspProviderSendPayloadDto {
export class TspProviderOriginalSendPayloadDto {
@ApiProperty({ required: true, enum: TspProviderRequestType })
@IsEnum(TspProviderRequestType)
type: TspProviderRequestType
@@ -219,11 +224,14 @@ export class TspProviderSendItemResultDto {
@IsString()
tax_id?: string | null
@ApiProperty({ required: true, nullable: true, type: TspProviderSendPayloadDto })
@ApiProperty({
required: true,
nullable: true,
type: TspProviderOriginalSendPayloadDto,
})
@IsOptional()
@IsObject()
@Type(() => TspProviderSendPayloadDto)
request_payload: TspProviderSendPayloadDto
request_payload: Object
@ApiProperty({ required: false, nullable: true, type: Object })
@IsOptional()
@@ -260,6 +268,8 @@ export class TspProviderBulkSendResultDto {
items: TspProviderSendItemResultDto[]
}
///////////// GET RELATED DTOs /////////////
export class TspProviderGetResultDto {
@ApiProperty()
@IsString()
@@ -292,6 +302,8 @@ export class TspProviderGetResultDto {
received_at: string
}
///////////// REVOKE RELATED DTOs /////////////
export class TspProviderRevokePayloadDto {
@ApiProperty({ required: true, nullable: true })
@IsNumber()
@@ -319,7 +331,7 @@ export class TspProviderRevokePayloadDto {
@ApiProperty({ required: true })
@IsString()
last_attempt_tax_id: string
last_tax_id: string
}
export class TspProviderRevokeResponseDto {
@@ -363,10 +375,55 @@ export class TspProviderRevokeResponseDto {
received_at: string
}
///////////// CORRECTION RELATED DTOs /////////////
export class TspProviderCorrectionInvoicePayloadDto {
@ApiProperty({ type: [SharedCreateSalesInvoiceItemDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => SharedCreateSalesInvoiceItemDto)
@ArrayMinSize(1)
items: SharedCreateSalesInvoiceItemDto[]
@ApiProperty()
@IsNumber()
total_amount: number
@ApiProperty({ required: true, type: SharedCreateSalesInvoicePaymentsDto })
@IsObject()
@ValidateNested({ each: true })
@Type(() => SharedCreateSalesInvoicePaymentsDto)
payments: SharedCreateSalesInvoicePaymentsDto
}
export class TspProviderCorrectionSendPayloadDto extends TspProviderOriginalSendPayloadDto {
@ApiProperty({ required: true })
@IsString()
last_tax_id: string
}
export class TspProviderCorrectionSendResponseDto {}
export class TspProviderActionResponseDto {
@IsObject()
invoice: object
@IsString()
message: string
@IsEnum(TspProviderResponseStatus)
status: TspProviderResponseStatus
}
export interface IProviderSwitchAdapter {
readonly code: string
send(payload: TspProviderSendPayloadDto): Promise<TspProviderSendItemResultDto>
sendBulk(payloads: TspProviderSendPayloadDto[]): Promise<TspProviderBulkSendResultDto[]>
originalSend(
payload: TspProviderOriginalSendPayloadDto,
): Promise<TspProviderSendItemResultDto>
sendBulk(
payloads: TspProviderOriginalSendPayloadDto[],
): Promise<TspProviderBulkSendResultDto[]>
correctionSend(
payload: TspProviderCorrectionSendPayloadDto,
): Promise<TspProviderCorrectionSendResponseDto>
get(invoiceId: string, tsp_token: string): Promise<TspProviderGetResultDto>
revoke(payload: TspProviderRevokePayloadDto): Promise<TspProviderRevokeResponseDto>
}