orders pagination
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
import { IsOptional, IsString, IsNumber, Min, IsIn, IsEnum, IsDateString } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { OrderStatus } from '../interface/order-status';
|
||||
import { PaymentStatusEnum } from '../../payments/interface/payment';
|
||||
|
||||
// Define the valid sort directions
|
||||
const sortOrderOptions = ['asc', 'desc'] as const;
|
||||
type SortOrder = (typeof sortOrderOptions)[number];
|
||||
|
||||
export class FindOrdersDto {
|
||||
/**
|
||||
* The page number to retrieve.
|
||||
* @default 1
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Page number',
|
||||
type: Number,
|
||||
default: 1,
|
||||
minimum: 1,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@Type(() => Number)
|
||||
page?: number = 1;
|
||||
|
||||
/**
|
||||
* The number of items per page.
|
||||
* @default 10
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Number of items per page',
|
||||
type: Number,
|
||||
default: 10,
|
||||
minimum: 1,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@Type(() => Number)
|
||||
limit?: number = 10;
|
||||
|
||||
/**
|
||||
* Filter by order status
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Filter by order status',
|
||||
enum: OrderStatus,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEnum(OrderStatus)
|
||||
status?: OrderStatus;
|
||||
|
||||
/**
|
||||
* Filter by payment status
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Filter by payment status',
|
||||
enum: PaymentStatusEnum,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEnum(PaymentStatusEnum)
|
||||
paymentStatus?: PaymentStatusEnum;
|
||||
|
||||
/**
|
||||
* Search by order number or user information
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Search by order number or user information',
|
||||
type: String,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
search?: string;
|
||||
|
||||
/**
|
||||
* Filter orders from this date (ISO date string)
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Filter orders from this date (ISO date string)',
|
||||
type: String,
|
||||
format: 'date-time',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
startDate?: string;
|
||||
|
||||
/**
|
||||
* Filter orders until this date (ISO date string)
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Filter orders until this date (ISO date string)',
|
||||
type: String,
|
||||
format: 'date-time',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
endDate?: string;
|
||||
|
||||
/**
|
||||
* The field to sort the results by.
|
||||
* @default "createdAt"
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Field to sort by (createdAt, total, orderNumber)',
|
||||
type: String,
|
||||
default: 'createdAt',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
orderBy?: string = 'createdAt';
|
||||
|
||||
/**
|
||||
* The direction to sort the results.
|
||||
* @default "desc"
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Sort direction (asc or desc)',
|
||||
enum: sortOrderOptions,
|
||||
default: 'desc',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsIn(sortOrderOptions)
|
||||
order?: SortOrder = 'desc';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user