Spaces:
Sleeping
Sleeping
Merge pull request #46 from Modarb-Ai-Trainer:populate
Browse files
src/lib/services/crud.service.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import { HttpError } from "@lib/error-handling/http-error";
|
|
|
2 |
import { AnyKeys, Document, FilterQuery, Model } from "mongoose";
|
3 |
|
4 |
export const CrudService = <ModelDoc extends Document>(
|
@@ -40,8 +41,11 @@ export const CrudService = <ModelDoc extends Document>(
|
|
40 |
limit?: number;
|
41 |
skip?: number;
|
42 |
} = {
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
}
|
46 |
): Promise<{
|
47 |
docs: ModelDoc[];
|
@@ -51,11 +55,13 @@ export const CrudService = <ModelDoc extends Document>(
|
|
51 |
perPage: number;
|
52 |
};
|
53 |
}> {
|
54 |
-
const
|
55 |
.find(filter)
|
56 |
.limit(paginationOptions.limit)
|
57 |
-
.skip(paginationOptions.skip)
|
|
|
58 |
|
|
|
59 |
const total = await this.model.countDocuments(filter);
|
60 |
const paginationData = {
|
61 |
total: total,
|
|
|
1 |
import { HttpError } from "@lib/error-handling/http-error";
|
2 |
+
import { populate } from "dotenv";
|
3 |
import { AnyKeys, Document, FilterQuery, Model } from "mongoose";
|
4 |
|
5 |
export const CrudService = <ModelDoc extends Document>(
|
|
|
41 |
limit?: number;
|
42 |
skip?: number;
|
43 |
} = {
|
44 |
+
limit: 10,
|
45 |
+
skip: 0,
|
46 |
+
},
|
47 |
+
options?: {
|
48 |
+
populateObject: any
|
49 |
}
|
50 |
): Promise<{
|
51 |
docs: ModelDoc[];
|
|
|
55 |
perPage: number;
|
56 |
};
|
57 |
}> {
|
58 |
+
const queryInstruction = this.model
|
59 |
.find(filter)
|
60 |
.limit(paginationOptions.limit)
|
61 |
+
.skip(paginationOptions.skip)
|
62 |
+
if (options?.populateObject) queryInstruction.populate(options.populateObject);
|
63 |
|
64 |
+
const docs = await queryInstruction
|
65 |
const total = await this.model.countDocuments(filter);
|
66 |
const paginationData = {
|
67 |
total: total,
|
src/modules/console/common/models/admin.model.ts
CHANGED
@@ -2,6 +2,7 @@ import mongoose, { UpdateQuery } from "mongoose";
|
|
2 |
import bcrypt from "bcrypt";
|
3 |
import { config } from "../../../../configs/config";
|
4 |
import { Role } from "@common/enums/role.enum";
|
|
|
5 |
|
6 |
const { Schema } = mongoose;
|
7 |
|
|
|
2 |
import bcrypt from "bcrypt";
|
3 |
import { config } from "../../../../configs/config";
|
4 |
import { Role } from "@common/enums/role.enum";
|
5 |
+
import { saltrounds } from "@common/models/user.model";
|
6 |
|
7 |
const { Schema } = mongoose;
|
8 |
|