@vasrefil/api-toolkit 1.0.41 → 1.0.43
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.
|
@@ -14,7 +14,7 @@ export declare class RootController {
|
|
|
14
14
|
fetchAll(condition?: object, query?: FetchAllQuery, select?: string | object, populate?: any): import("mongoose").Query<Omit<any, never>[], any, {}, any>;
|
|
15
15
|
fetchAllWithPagination: (conditon: object, query?: FetchAllQuery, select?: string | object, populate?: ModelPopulateI[]) => Promise<FetchWithPaginationDataI>;
|
|
16
16
|
getOneP: (condition: object, select?: any) => Promise<any>;
|
|
17
|
-
getOne(condition: any, select?: any): import("mongoose").Query<any, any, {}, any>;
|
|
17
|
+
getOne(condition: any, select?: any, populate?: any): import("mongoose").Query<any, any, {}, any>;
|
|
18
18
|
getOnePSes: (condition: object, session: ClientSession, select?: string) => Promise<any>;
|
|
19
19
|
getById: (id: string, select?: string | object) => Promise<any>;
|
|
20
20
|
getByIdSes: (id: string, session: ClientSession, select?: object | string) => Promise<any>;
|
|
@@ -144,13 +144,13 @@ class RootController {
|
|
|
144
144
|
const { filter, skip, limit, sort } = query_helper_1.QueryHelper.build_query(query);
|
|
145
145
|
return this.model.find({ ...filter, ...condition }).select(select).skip(skip).limit(limit).sort(sort).populate(populate);
|
|
146
146
|
}
|
|
147
|
-
getOne(condition, select) {
|
|
147
|
+
getOne(condition, select, populate) {
|
|
148
148
|
select = select ? select : '';
|
|
149
149
|
let cond = condition;
|
|
150
150
|
if (this.modelName === 'User') {
|
|
151
151
|
cond = { is_deleted: false, ...condition };
|
|
152
152
|
}
|
|
153
|
-
return (this.model.findOne(cond).select(select).lean());
|
|
153
|
+
return (this.model.findOne(cond).select(select).populate(populate).lean());
|
|
154
154
|
}
|
|
155
155
|
updateOne(condition, updateValues) {
|
|
156
156
|
return this.model.updateOne({ ...condition }, { ...updateValues }, { new: true });
|
|
@@ -5,6 +5,7 @@ declare class AdminAuthMidWare_ extends RootService {
|
|
|
5
5
|
auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
6
6
|
voucher_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
7
7
|
edu_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
8
|
+
log_auth: (req: AdminRequestI, res: Response, next: NextFunction) => Promise<any>;
|
|
8
9
|
private get_admin;
|
|
9
10
|
}
|
|
10
11
|
declare const AdminAuthMidWare: AdminAuthMidWare_;
|
|
@@ -69,6 +69,25 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
|
|
|
69
69
|
return this.sendResponse({ req, res, status, actionType, message, data, error });
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
|
+
this.log_auth = async (req, res, next) => {
|
|
73
|
+
const actionType = 'LOG_ADMIN_AUTH_MIDWARE';
|
|
74
|
+
try {
|
|
75
|
+
const apiKey = req.headers['api-key'];
|
|
76
|
+
if (apiKey) {
|
|
77
|
+
if (apiKey !== env_1.default.LOG.API_KEY)
|
|
78
|
+
throw user_response_1.UserApiResp.NO_API_KEY;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const { admin_user } = await this.get_admin(req);
|
|
82
|
+
req.admin = admin_user;
|
|
83
|
+
}
|
|
84
|
+
next();
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const { status, message, data } = this.get_error(error);
|
|
88
|
+
return this.sendResponse({ req, res, status, actionType, message, data, error });
|
|
89
|
+
}
|
|
90
|
+
};
|
|
72
91
|
this.get_admin = async (req) => {
|
|
73
92
|
try {
|
|
74
93
|
const baseurl = env_1.default.VASREFIL.BASEURL;
|