@konplit-services/common 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface PaginationOptions
|
|
1
|
+
import { Model } from "mongoose";
|
|
2
|
+
export interface PaginationOptions {
|
|
3
3
|
page?: number;
|
|
4
4
|
limit?: number;
|
|
5
5
|
sort?: Record<string, "asc" | "desc">;
|
|
6
6
|
select?: string | Record<string, any>;
|
|
7
7
|
query?: Record<string, any>;
|
|
8
8
|
}
|
|
9
|
-
export interface PaginationResult<T
|
|
9
|
+
export interface PaginationResult<T> {
|
|
10
10
|
current_page: number;
|
|
11
11
|
total_page: number;
|
|
12
12
|
total_docs: number;
|
|
@@ -16,7 +16,7 @@ export interface PaginationResult<T extends Document> {
|
|
|
16
16
|
previous_page: number | null;
|
|
17
17
|
results: T[];
|
|
18
18
|
}
|
|
19
|
-
export declare function paginate<T
|
|
19
|
+
export declare function paginate<T>(model: Model<T>, options?: PaginationOptions): Promise<PaginationResult<T>>;
|
|
20
20
|
export interface FilterOptions {
|
|
21
21
|
search?: string;
|
|
22
22
|
status?: string;
|
|
@@ -35,7 +35,7 @@ export declare const generateQueryObject: (filters: FilterOptions, searchesField
|
|
|
35
35
|
limit: number;
|
|
36
36
|
query: any;
|
|
37
37
|
sort: {
|
|
38
|
-
[key: string]:
|
|
38
|
+
[key: string]: "asc" | "desc";
|
|
39
39
|
};
|
|
40
40
|
select: string | Record<string, any>;
|
|
41
41
|
};
|
|
@@ -102,7 +102,7 @@ const generateQueryObject = (filters, searchesFieldNames = [], select = "") => {
|
|
|
102
102
|
}
|
|
103
103
|
if (filters.sort_by && filters.order) {
|
|
104
104
|
const newSory = {
|
|
105
|
-
[sort_by]: order === "asc" ?
|
|
105
|
+
[sort_by]: order === "asc" ? "asc" : "desc",
|
|
106
106
|
};
|
|
107
107
|
sort = Object.assign({}, newSory);
|
|
108
108
|
}
|