2020-04-22 15:52:17 +02:00
|
|
|
import Model from "./db/Model";
|
|
|
|
|
|
|
|
export default class Pagination<T extends Model> {
|
|
|
|
private readonly models: T[];
|
|
|
|
public readonly page: number;
|
|
|
|
public readonly perPage: number;
|
|
|
|
public readonly totalCount: number;
|
|
|
|
|
2020-09-25 23:42:15 +02:00
|
|
|
public constructor(models: T[], page: number, perPage: number, totalCount: number) {
|
2020-04-22 15:52:17 +02:00
|
|
|
this.models = models;
|
|
|
|
this.page = page;
|
|
|
|
this.perPage = perPage;
|
|
|
|
this.totalCount = totalCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public hasPrevious(): boolean {
|
|
|
|
return this.page > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public hasNext(): boolean {
|
|
|
|
return this.models.length >= this.perPage && this.page * this.perPage < this.totalCount;
|
|
|
|
}
|
|
|
|
|
2020-09-25 23:42:15 +02:00
|
|
|
}
|