Files
yara724api/src/common/dto/list-query-v2.dto.ts
2026-05-20 14:57:10 +03:30

79 lines
1.7 KiB
TypeScript

import { ApiPropertyOptional } from "@nestjs/swagger";
import { Type } from "class-transformer";
import {
IsIn,
IsInt,
IsOptional,
IsString,
Max,
MaxLength,
Min,
} from "class-validator";
/** Allowed sort keys for V2 list endpoints (claims / blame). */
export const LIST_SORT_BY_V2 = [
"publicId",
"createdAt",
"requestNo",
"status",
] as const;
export type ListSortByV2 = (typeof LIST_SORT_BY_V2)[number];
/**
* Optional query params for V2 lists. If neither `page` nor `limit` is sent,
* the full filtered+sorted list is returned (backward compatible).
*/
export class ListQueryV2Dto {
@ApiPropertyOptional({
description: "1-based page index (use together with `limit` for pagination).",
example: 1,
minimum: 1,
})
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
page?: number;
@ApiPropertyOptional({
description: "Page size (max 100). If only `page` is set, defaults to 20.",
example: 20,
minimum: 1,
maximum: 100,
})
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(100)
limit?: number;
@ApiPropertyOptional({
enum: LIST_SORT_BY_V2,
description: "Sort field. Default: `createdAt`.",
})
@IsOptional()
@IsIn([...LIST_SORT_BY_V2])
sortBy?: ListSortByV2;
@ApiPropertyOptional({
enum: ["asc", "desc"],
description: "Sort direction. Default: `desc` for dates, `asc` for publicId/requestNo.",
})
@IsOptional()
@IsIn(["asc", "desc"])
sortOrder?: "asc" | "desc";
@ApiPropertyOptional({
description:
"Case-insensitive substring match on `publicId` and `requestNo` (and other endpoint-specific fields).",
example: "A142",
maxLength: 64,
})
@IsOptional()
@IsString()
@MaxLength(64)
search?: string;
}