40 lines
948 B
TypeScript
40 lines
948 B
TypeScript
import { Transform, Type } from "class-transformer";
|
|
import { IsNumber, IsOptional, IsString, MaxLength, Min, ValidateIf, ValidateNested } from "class-validator";
|
|
|
|
export class ExpensePayloadDto {
|
|
@IsString()
|
|
type!: string;
|
|
|
|
@ValidateIf(o => (o.type ?? '').toUpperCase() !== 'MILEAGE')
|
|
@IsNumber()
|
|
@Min(0)
|
|
amount?: number;
|
|
|
|
@ValidateIf(o => (o.type ?? '').toUpperCase() === 'MILEAGE')
|
|
@IsNumber()
|
|
@Min(0)
|
|
mileage?: number;
|
|
|
|
@IsString()
|
|
@MaxLength(280)
|
|
@Transform(({ value }) => (typeof value === 'string' ? value.trim() : value))
|
|
comment!: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(255)
|
|
attachment?: string;
|
|
}
|
|
|
|
|
|
export class UpsertExpenseDto {
|
|
@IsOptional()
|
|
@ValidateNested()
|
|
@Type(()=> ExpensePayloadDto)
|
|
old_expense?: ExpensePayloadDto;
|
|
|
|
@IsOptional()
|
|
@ValidateNested()
|
|
@Type(()=> ExpensePayloadDto)
|
|
new_expense?: ExpensePayloadDto;
|
|
} |