mirror of
https://github.com/docmost/docmost.git
synced 2025-11-17 14:21:08 +10:00
server: refactor pagination
* fix transaction usgae in repos * other bug fixes
This commit is contained in:
@ -1,14 +0,0 @@
|
||||
import { IsArray } from 'class-validator';
|
||||
import { PaginationMetaDto } from './pagination-meta-dto';
|
||||
|
||||
export class PaginatedResult<T> {
|
||||
@IsArray()
|
||||
readonly items: T[];
|
||||
|
||||
readonly pagination: PaginationMetaDto;
|
||||
|
||||
constructor(items: T[], pagination: PaginationMetaDto) {
|
||||
this.items = items;
|
||||
this.pagination = pagination;
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
import { PaginationOptions } from './pagination-options';
|
||||
|
||||
export class PaginationMetaDto {
|
||||
readonly page: number;
|
||||
|
||||
readonly limit: number;
|
||||
|
||||
readonly total: number;
|
||||
|
||||
readonly pageCount: number;
|
||||
|
||||
readonly hasPreviousPage: boolean;
|
||||
|
||||
readonly hasNextPage: boolean;
|
||||
|
||||
constructor({ count, paginationOptions }: PageMetaDtoParameters) {
|
||||
this.page = paginationOptions.page;
|
||||
this.limit = paginationOptions.limit;
|
||||
this.total = count;
|
||||
this.pageCount = Math.ceil(this.total / this.limit);
|
||||
this.hasPreviousPage = this.page > 1;
|
||||
this.hasNextPage = this.page < this.pageCount;
|
||||
}
|
||||
}
|
||||
|
||||
export interface PageMetaDtoParameters {
|
||||
count: number;
|
||||
paginationOptions: PaginationOptions;
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
import { IsNumber, IsOptional, IsPositive, Max, Min } from 'class-validator';
|
||||
|
||||
export class PaginationOptions {
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
page = 1;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@IsPositive()
|
||||
@Min(1)
|
||||
@Max(100)
|
||||
limit = 20;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
offset = 0;
|
||||
|
||||
get skip(): number {
|
||||
return (this.page - 1) * this.limit;
|
||||
}
|
||||
}
|
||||
|
||||
export enum Order {
|
||||
ASC = 'ASC',
|
||||
DESC = 'DESC',
|
||||
}
|
||||
Reference in New Issue
Block a user