Files
certd/packages/core/pipeline/src/context/index.ts
T

43 lines
810 B
TypeScript
Raw Normal View History

2024-07-15 00:30:33 +08:00
import { IContext } from "../core/index.js";
2022-12-27 12:32:09 +08:00
export type UserContext = IContext;
export type PipelineContext = IContext;
2025-05-28 00:57:52 +08:00
export type PageSearch = {
2025-05-28 00:57:52 +08:00
offset?: number;
limit?: number;
searchKey?: string;
// sortBy?: string;
// sortOrder?: "asc" | "desc";
2025-05-28 00:57:52 +08:00
};
export type PageRes = {
offset?: number;
limit?: number;
total?: string;
list: any[];
};
export class Pager {
offset: number;
limit: number;
constructor(req: PageSearch) {
this.offset = req.offset ?? 0;
this.limit = req.limit || 50;
}
getPageNo() {
const size = this.limit;
const offset = this.offset;
let page = Math.floor(offset / size);
if (offset % size === 0) {
page++;
}
return page;
}
setPageNo(pageNo: number) {
this.offset = (pageNo - 1) * (this.limit ?? 50);
}
}