@vasrefil/api-toolkit 1.0.28 → 1.0.30

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/env.d.ts CHANGED
@@ -8,6 +8,7 @@ declare const env: {
8
8
  MONGODB_URI: string;
9
9
  API_KEY: string | undefined;
10
10
  SERVICE_NAME: string | undefined;
11
+ REDIS_URL: string;
11
12
  VASREFIL: {
12
13
  BASEURL: string;
13
14
  API_KEY: string | undefined;
package/dist/env.js CHANGED
@@ -14,6 +14,7 @@ const env = {
14
14
  MONGODB_URI: '',
15
15
  API_KEY: process.env.API_KEY,
16
16
  SERVICE_NAME: process.env.SERVICE_NAME,
17
+ REDIS_URL: process.env.REDIS_URL,
17
18
  VASREFIL: {
18
19
  BASEURL: NODE_ENV === NODE_ENVS.PROD ? 'https://api.vasrefil.com' : 'https://api-v2-test.vasrefil.com',
19
20
  API_KEY: process.env.VASREFIL_API_KEY
@@ -15,6 +15,7 @@ declare class QueryHelper_ {
15
15
  }): {};
16
16
  get_filters(filter: any): any;
17
17
  process_filters: (query: any) => {} | undefined;
18
+ private get_search;
18
19
  private get_sort;
19
20
  private str_to_obj;
20
21
  }
@@ -34,14 +34,28 @@ class QueryHelper_ {
34
34
  console.log(error);
35
35
  }
36
36
  };
37
+ this.get_search = (query) => {
38
+ const { search } = query;
39
+ let searchx = search ? this.str_to_obj(search) : {};
40
+ let result = {};
41
+ if (searchx.key && searchx.value) {
42
+ const keys = searchx.key.split(',');
43
+ const filters = [];
44
+ for (let key of keys) {
45
+ key = key.trim();
46
+ filters.push({ [key]: { $regex: new RegExp(`${searchx.value}`, 'i') } });
47
+ }
48
+ result = { '$or': filters };
49
+ }
50
+ return result;
51
+ };
37
52
  }
38
53
  build_query(query) {
39
54
  if (!query)
40
55
  query = {};
41
- const { filter, limit, page, filterRange, date_range, date_type, search } = query;
56
+ const { filter, limit, page, filterRange, date_range, date_type } = query;
42
57
  let range = filterRange ? this.str_to_obj(filterRange) : null;
43
58
  const filterx = filter ? this.str_to_obj(filter) : {};
44
- let searchx = search ? this.str_to_obj(search) : {};
45
59
  const date_rangex = date_range ? this.str_to_obj(date_range) : {};
46
60
  const pagex = page ? Number(page) : 1;
47
61
  const skipx = page ? ((Number(page) - 1) * limit) : 0;
@@ -50,13 +64,12 @@ class QueryHelper_ {
50
64
  const { field, ranges: { from, to } } = range;
51
65
  range = { [field]: { $gte: from, $lt: to } };
52
66
  }
53
- searchx = searchx.key && searchx.value ? searchx : null;
67
+ const search = this.get_search(query);
54
68
  const filterResult = range || filterx || {};
55
69
  const date_range_ = this.get_date_range({ date_type, date_range: date_rangex });
56
- const search_ = searchx ? { [searchx.key]: { $regex: new RegExp(`${searchx.value}`, 'i') } } : {};
57
70
  const filters = this.process_filters(query);
58
71
  const sort = this.get_sort(query);
59
- const filter_result = { ...filterResult, ...date_range_, ...search_, ...filters };
72
+ const filter_result = { ...filterResult, ...date_range_, ...search, ...filters };
60
73
  return { sort, limit: limitx, filter: filter_result, skip: skipx, page: pagex };
61
74
  }
62
75
  get_date_range(payload) {
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ const _config_1 = require("./models/_config");
12
12
  const index_route_1 = require("./routes/index.route");
13
13
  const logger_util_1 = require("./utilities/logger.util");
14
14
  // import { airbrake, airbrakeExpress } from './app-middlewares/airbrake';
15
- const port = process.env.PORT || 8082;
15
+ const port = process.env.PORT || 8012;
16
16
  const app = (0, express_1.default)();
17
17
  //configure application
18
18
  app.use(express_1.default.static(path_1.default.join(__dirname, "public")));
@@ -4,44 +4,8 @@ export interface UserI {
4
4
  first_name: string;
5
5
  last_name: string;
6
6
  middle_name: string;
7
- email: string;
8
- email_verified: boolean;
9
- email_verification_code: string;
10
7
  user_name: string;
11
- password: string;
12
- balance: number;
13
- level: number;
14
- phone: string;
15
- signup_code: string;
16
- pin?: string;
17
- password_reset_code?: string;
18
- pin_reset_code?: string;
19
- profile_image_url?: string;
20
- referrer_commission?: string;
21
- device_unique_id?: string;
22
- is_active?: boolean;
23
- is_deleted?: boolean;
24
- delete_account_code?: string;
25
- pin_is_set?: boolean;
26
- date_of_birth?: Date;
27
- gender: 'Male' | 'Female';
28
- bvn?: string;
29
- bvn_hash?: string;
30
- nin?: string;
31
- nin_hash?: string;
32
- bvn_phone?: string;
33
- marketing_channel?: string;
34
- onesignal_player_id_is_set?: boolean;
35
- vas_service_fee?: number;
36
- api_key: string;
37
- bvn_verification_code?: string;
38
- whatsapp_number?: string;
39
- address_info: {
40
- address: string;
41
- city: string;
42
- state: string;
43
- };
44
- can_use_voucher?: boolean;
8
+ email: string;
45
9
  createdAt?: Date;
46
10
  }
47
11
  export interface UserWalletOperationI {
@@ -5,3 +5,4 @@ export * from './app-middlewares';
5
5
  export * from './interfaces';
6
6
  export * from './middlewares';
7
7
  export * from './services';
8
+ export * from './redis';
@@ -21,3 +21,4 @@ __exportStar(require("./app-middlewares"), exports);
21
21
  __exportStar(require("./interfaces"), exports);
22
22
  __exportStar(require("./middlewares"), exports);
23
23
  __exportStar(require("./services"), exports);
24
+ __exportStar(require("./redis"), exports);
@@ -0,0 +1 @@
1
+ export * from './redis';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./redis"), exports);
@@ -0,0 +1,40 @@
1
+ declare class Redis_ {
2
+ private client;
3
+ private className;
4
+ init: () => Promise<void>;
5
+ exists: (key: string) => Promise<number>;
6
+ set_multiple_hash: (key: string, pairs: any) => Promise<"OK">;
7
+ set_hash: (payload: {
8
+ key: string;
9
+ field: string;
10
+ value: any;
11
+ }) => Promise<number>;
12
+ get_hash: (payload: {
13
+ key: string;
14
+ field: string;
15
+ }) => Promise<string | null>;
16
+ delete_hash: (payload: {
17
+ key: string;
18
+ field: string;
19
+ }) => Promise<number>;
20
+ fetch_hashes: (key: string) => Promise<Record<string, string>>;
21
+ set_item: (payload: {
22
+ key: string;
23
+ value: any;
24
+ }) => Promise<"OK">;
25
+ get_item: (key: string) => Promise<any>;
26
+ expire: (dto: {
27
+ key: string;
28
+ expireIn: number | string;
29
+ }) => Promise<number>;
30
+ set_list: (payload: {
31
+ key: string;
32
+ values: any[];
33
+ }) => Promise<number>;
34
+ get_list: (payload: {
35
+ key: string;
36
+ }) => Promise<string[]>;
37
+ private is_valid_json;
38
+ }
39
+ declare const Redis: Redis_;
40
+ export { Redis };
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Redis = void 0;
7
+ const ioredis_1 = __importDefault(require("ioredis"));
8
+ const env_1 = __importDefault(require("../env"));
9
+ class Redis_ {
10
+ constructor() {
11
+ this.className = 'Redis';
12
+ this.init = async () => {
13
+ this.client = new ioredis_1.default(env_1.default.REDIS_URL);
14
+ this.client.on('error', (err) => console.log('Redis Client Error', err));
15
+ this.client.on('connect', () => console.log('Redis server connected...'));
16
+ };
17
+ // new_client(option?: object) {
18
+ // return new IORedis(env.REDIS_URL, option);
19
+ // }
20
+ this.exists = async (key) => {
21
+ try {
22
+ const resp = await this.client.exists(key);
23
+ return resp;
24
+ }
25
+ catch (error) {
26
+ console.log(`[${this.className}-EXISTS]`, error);
27
+ throw error;
28
+ }
29
+ };
30
+ this.set_multiple_hash = async (key, pairs) => {
31
+ try {
32
+ const resp = await this.client.hmset(key, pairs);
33
+ return resp;
34
+ }
35
+ catch (error) {
36
+ console.log(`[${this.className}-SET_MULTIPLE_HASH]`, error);
37
+ throw error;
38
+ }
39
+ };
40
+ this.set_hash = async (payload) => {
41
+ try {
42
+ const { key, field, value } = payload;
43
+ const value_ = value ? JSON.stringify(value) : value;
44
+ const resp = await this.client.hset(key, field, value_);
45
+ return resp;
46
+ }
47
+ catch (error) {
48
+ console.log(`[${this.className}-SET_HASH]`, error);
49
+ throw error;
50
+ }
51
+ };
52
+ this.get_hash = async (payload) => {
53
+ try {
54
+ const { key, field } = payload;
55
+ let resp = await this.client.hget(key, `${field}`);
56
+ resp = resp ? JSON.parse(resp) : resp;
57
+ return resp;
58
+ }
59
+ catch (error) {
60
+ console.log(`[${this.className}-GET_HASH]`, error);
61
+ throw error;
62
+ }
63
+ };
64
+ this.delete_hash = async (payload) => {
65
+ try {
66
+ const { key, field } = payload;
67
+ let resp = await this.client.hdel(key, `${field}`);
68
+ resp = resp ? JSON.parse(`${resp}`) : resp;
69
+ return resp;
70
+ }
71
+ catch (error) {
72
+ console.log(`[${this.className}-DELETE_HASH]`, error);
73
+ throw error;
74
+ }
75
+ };
76
+ this.fetch_hashes = async (key) => {
77
+ try {
78
+ const resp = await this.client.hgetall(key);
79
+ return resp;
80
+ }
81
+ catch (error) {
82
+ console.log(`[${this.className}-GET_ALL_HASH]`, error);
83
+ throw error;
84
+ }
85
+ };
86
+ this.set_item = async (payload) => {
87
+ try {
88
+ const { key, value } = payload;
89
+ const resp = await this.client.set(key, JSON.stringify(value));
90
+ return resp;
91
+ }
92
+ catch (error) {
93
+ console.log(`[${this.className}-SET_ITEM]`, error);
94
+ throw error;
95
+ }
96
+ };
97
+ this.get_item = async (key) => {
98
+ try {
99
+ const resp = await this.client.get(key);
100
+ if (this.is_valid_json(resp)) {
101
+ return JSON.parse(resp);
102
+ }
103
+ else {
104
+ return resp;
105
+ }
106
+ }
107
+ catch (error) {
108
+ console.log(`[${this.className}-GET_ITEM]`, error);
109
+ throw error;
110
+ }
111
+ };
112
+ this.expire = async (dto) => {
113
+ try {
114
+ const resp = await this.client.expire(dto.key, dto.expireIn);
115
+ return resp;
116
+ }
117
+ catch (error) {
118
+ throw error;
119
+ }
120
+ };
121
+ this.set_list = async (payload) => {
122
+ try {
123
+ const { key, values } = payload;
124
+ const resp = await this.client.lpush(key, values);
125
+ return resp;
126
+ }
127
+ catch (error) {
128
+ console.log(`[${this.className}-SET_LIST]`, error);
129
+ throw error;
130
+ }
131
+ };
132
+ this.get_list = async (payload) => {
133
+ try {
134
+ const { key } = payload;
135
+ const resp = await this.client.lrange(key, 0, -1);
136
+ return resp;
137
+ }
138
+ catch (error) {
139
+ console.log(`[${this.className}-GET_LIST]`, error);
140
+ throw error;
141
+ }
142
+ };
143
+ }
144
+ is_valid_json(str) {
145
+ try {
146
+ JSON.parse(str);
147
+ return true;
148
+ }
149
+ catch (e) {
150
+ return false;
151
+ }
152
+ }
153
+ }
154
+ const Redis = new Redis_;
155
+ exports.Redis = Redis;
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.28",
4
+ "version": "1.0.30",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",
@@ -28,6 +28,7 @@
28
28
  "errorhandler": "^1.5.1",
29
29
  "express": "^4.18.3",
30
30
  "helmet": "^4.2.0",
31
+ "ioredis": "^5.4.1",
31
32
  "joi": "^17.3.0",
32
33
  "json-stringify-safe": "^5.0.1",
33
34
  "mongoose": "^6.0.14",