Init
This commit is contained in:
39
backend/src/common/dto/paging/chat-paging-query.dto.ts
Normal file
39
backend/src/common/dto/paging/chat-paging-query.dto.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { IsNumber, IsOptional } from 'class-validator';
|
||||
|
||||
import { PagingDefault } from '../../constants';
|
||||
|
||||
export class ChatPagingQuery {
|
||||
@ApiPropertyOptional({ description: 'Offset', example: 0 })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
offset?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Limit', example: 10 })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
limit?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Cursor position for pagination' })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
cursor?: number;
|
||||
|
||||
constructor(offset: number | undefined, limit: number | undefined, cursor: number | undefined) {
|
||||
this.offset = offset;
|
||||
this.limit = limit;
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
static default(): ChatPagingQuery {
|
||||
return new ChatPagingQuery(undefined, undefined, undefined);
|
||||
}
|
||||
|
||||
get skip(): number {
|
||||
return this.offset ?? PagingDefault.offset;
|
||||
}
|
||||
|
||||
get take(): number {
|
||||
return this.limit ?? PagingDefault.limit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user