102 lines
2.0 KiB
TypeScript
102 lines
2.0 KiB
TypeScript
import {
|
||
IsString,
|
||
IsInt,
|
||
IsArray,
|
||
IsNumber,
|
||
IsOptional,
|
||
IsBoolean,
|
||
IsDateString,
|
||
ArrayMinSize,
|
||
Min,
|
||
} from 'class-validator';
|
||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||
import { Type } from 'class-transformer';
|
||
|
||
export class CreateInvoiceItemDto {
|
||
@IsString()
|
||
@ApiProperty({ description: 'Product ID' })
|
||
productId!: string;
|
||
|
||
@IsInt()
|
||
@Min(1)
|
||
@ApiProperty({ example: 1 })
|
||
quantity!: number;
|
||
|
||
@IsNumber()
|
||
@Min(0)
|
||
@ApiProperty({ example: 10000 })
|
||
unitPrice: number;
|
||
|
||
@IsOptional()
|
||
@IsNumber()
|
||
@Min(0)
|
||
@ApiPropertyOptional({ example: 0 })
|
||
discount?: number;
|
||
|
||
@IsOptional()
|
||
@IsInt()
|
||
@Min(0)
|
||
@ApiPropertyOptional({ example: 10, description: 'Discount percentage (0–100)' })
|
||
discountPercent?: number;
|
||
|
||
@IsOptional()
|
||
@IsString()
|
||
@ApiPropertyOptional()
|
||
description?: string;
|
||
}
|
||
|
||
export class IAttachmentDto {
|
||
@IsString()
|
||
@ApiProperty({ description: 'Attachment type' })
|
||
type: string;
|
||
|
||
@IsString()
|
||
@ApiProperty({ description: 'Attachment URL' })
|
||
url: string;
|
||
}
|
||
|
||
export class CreateInvoiceDto {
|
||
@IsOptional()
|
||
@IsString()
|
||
@ApiPropertyOptional({ description: 'Request ID to link invoice to (optional)' })
|
||
requestId?: string;
|
||
|
||
@IsOptional()
|
||
@IsString()
|
||
@ApiPropertyOptional({ description: 'User ID (required when requestId is not provided)' })
|
||
userId?: string;
|
||
|
||
@IsArray()
|
||
@ArrayMinSize(1)
|
||
@Type(() => CreateInvoiceItemDto)
|
||
@ApiProperty({ type: [CreateInvoiceItemDto] })
|
||
items!: CreateInvoiceItemDto[];
|
||
|
||
@IsOptional()
|
||
@IsBoolean()
|
||
@ApiPropertyOptional({ example: false })
|
||
enableTax?: boolean;
|
||
|
||
@IsOptional()
|
||
@IsDateString()
|
||
@ApiPropertyOptional({ description: 'Approval deadline (ISO date string)' })
|
||
approvalDeadline?: string;
|
||
|
||
|
||
@ApiPropertyOptional()
|
||
@IsString()
|
||
paymentMethod?: string
|
||
|
||
|
||
@IsOptional()
|
||
@IsString()
|
||
@ApiPropertyOptional()
|
||
description?: string;
|
||
|
||
@IsArray()
|
||
@IsOptional()
|
||
@Type(() => IAttachmentDto)
|
||
@ApiProperty({ type: [IAttachmentDto] })
|
||
attachments?: IAttachmentDto[];
|
||
}
|