forked from Yara724/api
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { ApiPropertyOptional } from "@nestjs/swagger";
|
|
import { Type, Transform } from "class-transformer";
|
|
import {
|
|
IsArray,
|
|
IsOptional,
|
|
Validate,
|
|
ValidateNested,
|
|
} from "class-validator";
|
|
import { HasObjectionEntriesConstraint } from "src/common/validators/has-objection-entries.validator";
|
|
import { NewPartDto, UserObjectionPartDto } from "./user-objection.dto";
|
|
|
|
/**
|
|
* V2 user objection body — submitted as multipart/form-data.
|
|
* `objectionParts` and `newParts` are JSON-encoded strings in the form fields.
|
|
* Optional `invoices` files are uploaded as a `invoices` file array.
|
|
*/
|
|
export class UserObjectionV2Dto {
|
|
@ApiPropertyOptional({
|
|
type: [UserObjectionPartDto],
|
|
description:
|
|
"JSON-encoded array of disputed priced parts. Pass as a JSON string in the multipart field.",
|
|
})
|
|
@Validate(HasObjectionEntriesConstraint)
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ValidateNested({ each: true })
|
|
@Type(() => UserObjectionPartDto)
|
|
@Transform(({ value }) => {
|
|
if (typeof value === "string") {
|
|
try {
|
|
return JSON.parse(value);
|
|
} catch {
|
|
return value;
|
|
}
|
|
}
|
|
return value;
|
|
})
|
|
objectionParts?: UserObjectionPartDto[];
|
|
|
|
@ApiPropertyOptional({
|
|
type: [NewPartDto],
|
|
description:
|
|
"JSON-encoded array of new parts to add. Pass as a JSON string in the multipart field.",
|
|
})
|
|
@Validate(HasObjectionEntriesConstraint)
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ValidateNested({ each: true })
|
|
@Type(() => NewPartDto)
|
|
@Transform(({ value }) => {
|
|
if (typeof value === "string") {
|
|
try {
|
|
return JSON.parse(value);
|
|
} catch {
|
|
return value;
|
|
}
|
|
}
|
|
return value;
|
|
})
|
|
newParts?: NewPartDto[];
|
|
}
|