@vasrefil/api-toolkit 1.0.36 → 1.0.38
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.
- package/dist/controllers/_root.control.d.ts +6 -2
- package/dist/controllers/_root.control.js +49 -2
- package/dist/interfaces/user.interface.d.ts +2 -0
- package/dist/services/_root.service.js +13 -2
- package/dist/utilities/api-request.util.d.ts +2 -2
- package/dist/utilities/log.util.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Model } from 'mongoose';
|
|
1
|
+
import { Model, ClientSession } from 'mongoose';
|
|
2
2
|
import { FetchAllQuery, FetchWithPaginationDataI, ModelPopulateI, NestedRecordQueryOptionsI } from '../interfaces/root-controller.interface';
|
|
3
3
|
export declare class RootController {
|
|
4
4
|
private model;
|
|
@@ -10,14 +10,18 @@ export declare class RootController {
|
|
|
10
10
|
}) => Promise<boolean>;
|
|
11
11
|
getDocumentCount: (conditon?: {}, query?: object) => Promise<number>;
|
|
12
12
|
create: (payload: any) => Promise<any>;
|
|
13
|
+
createSes: (payload: any, session: ClientSession) => Promise<any>;
|
|
13
14
|
fetchAll(condition?: object, query?: FetchAllQuery, select?: string | object, populate?: any): import("mongoose").Query<Omit<any, never>[], any, {}, any>;
|
|
14
15
|
fetchAllWithPagination: (conditon: object, query?: FetchAllQuery, select?: string | object, populate?: ModelPopulateI[]) => Promise<FetchWithPaginationDataI>;
|
|
15
16
|
getOneP: (condition: object, select?: any) => Promise<any>;
|
|
16
|
-
getOne(condition:
|
|
17
|
+
getOne(condition: any, select?: any): import("mongoose").Query<any, any, {}, any>;
|
|
18
|
+
getOnePSes: (condition: object, session: ClientSession, select?: string) => Promise<any>;
|
|
17
19
|
getById: (id: string, select?: string | object) => Promise<any>;
|
|
20
|
+
getByIdSes: (id: string, session: ClientSession, select?: object | string) => Promise<any>;
|
|
18
21
|
updateOne(condition: object, updateValues: object): any;
|
|
19
22
|
updateMany(condition: object, updateValues: object): import("mongoose").Query<import("mongodb").UpdateResult, any, {}, any>;
|
|
20
23
|
updateById(id: string, updateValues: object): any;
|
|
24
|
+
updateByIdPSes: (id: string, condition: any, session: ClientSession) => Promise<any>;
|
|
21
25
|
deleteOne(condition: object): import("mongoose").Query<import("mongodb").DeleteResult, any, {}, any>;
|
|
22
26
|
deleteMany(condition: object): import("mongoose").Query<import("mongodb").DeleteResult, any, {}, any>;
|
|
23
27
|
deleteById(id: string): import("mongoose").Query<any, any, {}, any>;
|
|
@@ -27,6 +27,15 @@ class RootController {
|
|
|
27
27
|
throw error;
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
+
this.createSes = async (payload, session) => {
|
|
31
|
+
try {
|
|
32
|
+
const document = await this.model.create([payload], { session });
|
|
33
|
+
return document[0];
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
30
39
|
this.fetchAllWithPagination = async (conditon, query, select = '', populate) => {
|
|
31
40
|
try {
|
|
32
41
|
const records = await this.fetchAll(conditon, query, select, populate);
|
|
@@ -49,6 +58,17 @@ class RootController {
|
|
|
49
58
|
throw error;
|
|
50
59
|
}
|
|
51
60
|
};
|
|
61
|
+
this.getOnePSes = async (condition, session, select = '') => {
|
|
62
|
+
try {
|
|
63
|
+
const document = await this.model.findOne(condition).select(select).session(session).lean();
|
|
64
|
+
if (!document)
|
|
65
|
+
throw ({ message: `${this.modelName} not found` });
|
|
66
|
+
return (document);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw (error);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
52
72
|
this.getById = async (id, select = '') => {
|
|
53
73
|
try {
|
|
54
74
|
const document = await this.model.findById(id).select(select).lean();
|
|
@@ -60,6 +80,28 @@ class RootController {
|
|
|
60
80
|
throw error;
|
|
61
81
|
}
|
|
62
82
|
};
|
|
83
|
+
this.getByIdSes = async (id, session, select = '') => {
|
|
84
|
+
try {
|
|
85
|
+
const document = await this.model.findById(id).session(session).select(select).lean();
|
|
86
|
+
if (!document)
|
|
87
|
+
throw { message: `${this.modelName} not found` };
|
|
88
|
+
return document;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
this.updateByIdPSes = async (id, condition, session) => {
|
|
95
|
+
try {
|
|
96
|
+
const resp = await this.model.findByIdAndUpdate(id, condition, { new: true }).session(session).lean();
|
|
97
|
+
if (!resp)
|
|
98
|
+
throw { message: `Invalid ${this.modelName}` };
|
|
99
|
+
return resp;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
63
105
|
this.search = async (payload, select = '') => {
|
|
64
106
|
try {
|
|
65
107
|
const regrex = new RegExp(`${payload.value}`, 'i');
|
|
@@ -102,8 +144,13 @@ class RootController {
|
|
|
102
144
|
const { filter, skip, limit, sort } = query_helper_1.QueryHelper.build_query(query);
|
|
103
145
|
return this.model.find({ ...filter, ...condition }).select(select).skip(skip).limit(limit).sort(sort).populate(populate);
|
|
104
146
|
}
|
|
105
|
-
getOne(condition, select
|
|
106
|
-
|
|
147
|
+
getOne(condition, select) {
|
|
148
|
+
select = select ? select : '';
|
|
149
|
+
let cond = condition;
|
|
150
|
+
if (this.modelName === 'User') {
|
|
151
|
+
cond = { is_deleted: false, ...condition };
|
|
152
|
+
}
|
|
153
|
+
return (this.model.findOne(cond).select(select).lean());
|
|
107
154
|
}
|
|
108
155
|
updateOne(condition, updateValues) {
|
|
109
156
|
return this.model.updateOne({ ...condition }, { ...updateValues }, { new: true });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
+
import { TransactionI } from './transaction.interface';
|
|
2
3
|
export interface UserI {
|
|
3
4
|
_id: string;
|
|
4
5
|
first_name: string;
|
|
@@ -29,4 +30,5 @@ export interface CheckUserWalletBalanceRespI {
|
|
|
29
30
|
}
|
|
30
31
|
export interface UserRequestI extends Request {
|
|
31
32
|
user?: UserI;
|
|
33
|
+
transaction?: TransactionI;
|
|
32
34
|
}
|
|
@@ -66,16 +66,27 @@ class RootService {
|
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
this.sanitize_service_resp = (serviceResponse) => {
|
|
69
|
-
const { user } = serviceResponse.req;
|
|
69
|
+
const { user, transaction } = serviceResponse.req;
|
|
70
70
|
let user_;
|
|
71
|
+
let transaction_;
|
|
71
72
|
if (user) {
|
|
72
73
|
user_ = {
|
|
73
74
|
email: user.email,
|
|
74
75
|
user_name: user.user_name,
|
|
75
76
|
};
|
|
76
77
|
}
|
|
78
|
+
if (transaction) {
|
|
79
|
+
transaction_ = {
|
|
80
|
+
trans_id: transaction.trans_id,
|
|
81
|
+
service_provider: transaction.service_provider,
|
|
82
|
+
service_type: transaction.service_type,
|
|
83
|
+
status: transaction.status,
|
|
84
|
+
platform_provider: transaction.platform_provider,
|
|
85
|
+
reference_id: transaction.reference_id
|
|
86
|
+
};
|
|
87
|
+
}
|
|
77
88
|
const request_data = log_util_1.LogUtil.get_request(serviceResponse.req);
|
|
78
|
-
const request = { ...request_data, user: user_, };
|
|
89
|
+
const request = { ...request_data, user: user_, transaction: transaction_ };
|
|
79
90
|
serviceResponse.request = request;
|
|
80
91
|
serviceResponse.NODE_ENV = env_1.default.NODE_ENV;
|
|
81
92
|
return serviceResponse;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
interface ApiRequestPayloadI {
|
|
1
|
+
export interface ApiRequestPayloadI {
|
|
2
2
|
method: string;
|
|
3
3
|
endpoint: string;
|
|
4
4
|
baseurl?: string;
|
|
5
|
+
url?: string;
|
|
5
6
|
body?: any;
|
|
6
7
|
params?: any;
|
|
7
8
|
}
|
|
8
9
|
export declare const VasrefilApiRequest: (request: ApiRequestPayloadI) => Promise<any>;
|
|
9
10
|
export declare const LogApiRequest: (request: ApiRequestPayloadI) => Promise<any>;
|
|
10
|
-
export {};
|
|
@@ -67,7 +67,7 @@ class LogUtil_ {
|
|
|
67
67
|
};
|
|
68
68
|
this.get_user = (serviceResponse) => {
|
|
69
69
|
const { req, actionType } = serviceResponse;
|
|
70
|
-
let distinct_id = req.user ? req.user.
|
|
70
|
+
let distinct_id = req.user ? req.user.user_name : (req.body.email || '--');
|
|
71
71
|
// if(this.cronjobs_events.includes(actionType)) {
|
|
72
72
|
// distinct_id = 'cron-job.org';
|
|
73
73
|
// }
|