@vasrefil/api-toolkit 1.0.36 → 1.0.37

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,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;
@@ -15,6 +15,7 @@ export declare class RootController {
15
15
  getOneP: (condition: object, select?: any) => Promise<any>;
16
16
  getOne(condition: object, select?: string | object, populate?: any): any;
17
17
  getById: (id: string, select?: string | object) => Promise<any>;
18
+ getByIdSes: (id: string, session: ClientSession, select?: object | string) => Promise<any>;
18
19
  updateOne(condition: object, updateValues: object): any;
19
20
  updateMany(condition: object, updateValues: object): import("mongoose").Query<import("mongodb").UpdateResult, any, {}, any>;
20
21
  updateById(id: string, updateValues: object): any;
@@ -60,6 +60,17 @@ class RootController {
60
60
  throw error;
61
61
  }
62
62
  };
63
+ this.getByIdSes = async (id, session, select = '') => {
64
+ try {
65
+ const document = await this.model.findById(id).session(session).select(select).lean();
66
+ if (!document)
67
+ throw { message: `${this.modelName} not found` };
68
+ return document;
69
+ }
70
+ catch (error) {
71
+ throw error;
72
+ }
73
+ };
63
74
  this.search = async (payload, select = '') => {
64
75
  try {
65
76
  const regrex = new RegExp(`${payload.value}`, 'i');
@@ -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,4 +1,4 @@
1
- interface ApiRequestPayloadI {
1
+ export interface ApiRequestPayloadI {
2
2
  method: string;
3
3
  endpoint: string;
4
4
  baseurl?: string;
@@ -7,4 +7,3 @@ interface ApiRequestPayloadI {
7
7
  }
8
8
  export declare const VasrefilApiRequest: (request: ApiRequestPayloadI) => Promise<any>;
9
9
  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.email : (req.body.email || '--');
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
  // }
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.36",
4
+ "version": "1.0.37",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",