forked from Shared/esg
initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { NormalizedErrorDto } from './normalized-error.dto';
|
||||
|
||||
/**
|
||||
* Unified inquiry response envelope.
|
||||
* Every inquiry endpoint MUST return this structure.
|
||||
*/
|
||||
export class BaseInquiryResponseDto<T = Record<string, unknown>> {
|
||||
@ApiProperty({ example: true })
|
||||
success!: boolean;
|
||||
|
||||
@ApiProperty({ example: 'HAMTA' })
|
||||
provider!: string;
|
||||
|
||||
@ApiProperty({ example: 'INQ-20250525-ABC123' })
|
||||
trackingCode!: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 'Inquiry completed successfully' })
|
||||
message?: string;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
data?: T;
|
||||
|
||||
@ApiPropertyOptional({ type: NormalizedErrorDto })
|
||||
error?: NormalizedErrorDto;
|
||||
|
||||
@ApiProperty({ example: 342, description: 'Duration in milliseconds' })
|
||||
duration!: number;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
|
||||
/**
|
||||
* Standardized error shape returned to API consumers
|
||||
* regardless of upstream provider error formats.
|
||||
*/
|
||||
export class NormalizedErrorDto {
|
||||
@ApiProperty({ example: 'PROVIDER_TIMEOUT' })
|
||||
code!: string;
|
||||
|
||||
@ApiProperty({ example: 'Provider request timed out' })
|
||||
message!: string;
|
||||
|
||||
@ApiPropertyOptional({ example: 'سرویس در دسترس نیست' })
|
||||
providerMessage?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: '503' })
|
||||
providerCode?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user