@vasrefil/api-toolkit 1.0.37 → 1.0.39

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.
@@ -10,15 +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: object, select?: string | object, populate?: any): any;
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>;
18
20
  getByIdSes: (id: string, session: ClientSession, select?: object | string) => Promise<any>;
19
21
  updateOne(condition: object, updateValues: object): any;
20
22
  updateMany(condition: object, updateValues: object): import("mongoose").Query<import("mongodb").UpdateResult, any, {}, any>;
21
23
  updateById(id: string, updateValues: object): any;
24
+ updateByIdPSes: (id: string, condition: any, session: ClientSession) => Promise<any>;
22
25
  deleteOne(condition: object): import("mongoose").Query<import("mongodb").DeleteResult, any, {}, any>;
23
26
  deleteMany(condition: object): import("mongoose").Query<import("mongodb").DeleteResult, any, {}, any>;
24
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();
@@ -71,6 +91,17 @@ class RootController {
71
91
  throw error;
72
92
  }
73
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
+ };
74
105
  this.search = async (payload, select = '') => {
75
106
  try {
76
107
  const regrex = new RegExp(`${payload.value}`, 'i');
@@ -113,8 +144,13 @@ class RootController {
113
144
  const { filter, skip, limit, sort } = query_helper_1.QueryHelper.build_query(query);
114
145
  return this.model.find({ ...filter, ...condition }).select(select).skip(skip).limit(limit).sort(sort).populate(populate);
115
146
  }
116
- getOne(condition, select = '', populate) {
117
- return this.model.findOne(condition).select(select).populate(populate).lean();
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());
118
154
  }
119
155
  updateOne(condition, updateValues) {
120
156
  return this.model.updateOne({ ...condition }, { ...updateValues }, { new: true });
@@ -13,7 +13,8 @@ class JoiVdtor_ extends _root_service_1.RootService {
13
13
  return async (req, res, next) => {
14
14
  const actionType = 'SCHEMA_VALIDATION';
15
15
  try {
16
- await schema.validateAsync(req[field], { abortEarly: false });
16
+ const validated_data = await schema.validateAsync(req[field], { abortEarly: false });
17
+ req[field] = validated_data;
17
18
  next();
18
19
  }
19
20
  catch (err) {
@@ -2,6 +2,7 @@ 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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vasrefil/api-toolkit",
3
3
  "description": "This is Vasrefil API toolkit",
4
- "version": "1.0.37",
4
+ "version": "1.0.39",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",