soul-cli 0.6.0 → 0.7.0

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.
Files changed (64) hide show
  1. package/.all-contributorsrc +73 -0
  2. package/.editorconfig +26 -0
  3. package/.env.sample +9 -0
  4. package/.eslintignore +2 -0
  5. package/.eslintrc.js +24 -0
  6. package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  7. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. package/.github/workflows/npm-publish.yml +23 -0
  9. package/.husky/pre-commit +5 -0
  10. package/CONTRIBUTING.md +92 -0
  11. package/LICENSE +21 -0
  12. package/README.md +186 -1
  13. package/docs/api/root-examples.md +41 -0
  14. package/docs/api/rows-examples.md +225 -0
  15. package/docs/api/tables-examples.md +217 -0
  16. package/docs/api-examples.md +62 -0
  17. package/docs/extensions-examples.md +167 -0
  18. package/docs/logo.png +0 -0
  19. package/docs/soul-studio.png +0 -0
  20. package/docs/ws/rows-examples.md +122 -0
  21. package/docs/ws-examples.md +42 -0
  22. package/package.json +17 -2
  23. package/src/cli.js +59 -1
  24. package/src/commands.js +22 -0
  25. package/src/config/index.js +48 -3
  26. package/src/constants/api.js +26 -0
  27. package/src/constants/auth.js +5 -0
  28. package/src/constants/index.js +13 -0
  29. package/src/constants/messages.js +41 -0
  30. package/src/constants/roles.js +3 -0
  31. package/src/constants/tables.js +47 -0
  32. package/src/controllers/auth/common.js +16 -0
  33. package/src/controllers/auth/index.js +5 -0
  34. package/src/controllers/auth/tables.js +96 -0
  35. package/src/controllers/auth/token.js +243 -0
  36. package/src/controllers/auth/user.js +394 -0
  37. package/src/controllers/auth.test.js +372 -0
  38. package/src/controllers/rows.js +30 -31
  39. package/src/controllers/rows.test.js +209 -18
  40. package/src/controllers/tables.test.js +58 -28
  41. package/src/db/schema.js +118 -0
  42. package/src/index.js +32 -7
  43. package/src/middlewares/api.js +79 -0
  44. package/src/middlewares/auth.js +85 -0
  45. package/src/middlewares/broadcast.js +1 -1
  46. package/src/middlewares/validation.js +3 -2
  47. package/src/routes/auth.js +29 -0
  48. package/src/routes/rows.js +17 -5
  49. package/src/routes/tables.js +26 -4
  50. package/src/schemas/auth.js +67 -0
  51. package/src/schemas/index.js +6 -1
  52. package/src/schemas/rows.js +20 -0
  53. package/src/schemas/tables.js +18 -2
  54. package/src/server.js +3 -2
  55. package/src/services/authService.js +78 -0
  56. package/src/services/index.js +2 -1
  57. package/src/services/rowService.js +36 -7
  58. package/src/services/tableService.js +127 -1
  59. package/src/swagger/index.js +67 -0
  60. package/src/swagger/swagger.json +292 -60
  61. package/src/tests/index.js +4 -5
  62. package/src/tests/testData.js +72 -27
  63. package/src/utils/index.js +78 -0
  64. /package/{src/services/.gitkeep → docs/extensions/api-examples.js} +0 -0
@@ -0,0 +1,372 @@
1
+ const supertest = require('supertest');
2
+
3
+ const app = require('../index');
4
+ const config = require('../config');
5
+ const { generateToken } = require('../utils');
6
+ const { testData } = require('../tests/testData');
7
+
8
+ const requestWithSupertest = supertest(app);
9
+
10
+ describe('Auth Endpoints', () => {
11
+ describe('User Endpoints', () => {
12
+ it('POST /tables/_users/rows should register a user', async () => {
13
+ const accessToken = await generateToken(
14
+ { username: 'John', userId: 1, isSuperuser: true },
15
+ config.tokenSecret,
16
+ '1H',
17
+ );
18
+
19
+ const res = await requestWithSupertest
20
+ .post('/api/tables/_users/rows')
21
+ .set('Cookie', [`accessToken=${accessToken}`])
22
+ .send({
23
+ fields: {
24
+ username: testData.users.user1.username,
25
+ password: testData.strongPassword,
26
+ },
27
+ });
28
+
29
+ expect(res.status).toEqual(201);
30
+ expect(res.type).toEqual(expect.stringContaining('json'));
31
+
32
+ expect(res.body).toHaveProperty('message');
33
+ expect(res.body.message).toBe('Row Inserted');
34
+
35
+ expect(res.body).not.toHaveProperty('password');
36
+ expect(res.body).not.toHaveProperty('hashed_password');
37
+ expect(res.body).not.toHaveProperty('salt');
38
+ });
39
+
40
+ it('POST /tables/_users/rows should throw 400 error if username is not passed', async () => {
41
+ const accessToken = await generateToken(
42
+ { username: 'John', isSuperuser: true },
43
+ config.tokenSecret,
44
+ '1H',
45
+ );
46
+
47
+ const res = await requestWithSupertest
48
+ .post('/api/tables/_users/rows')
49
+ .set('Cookie', [`accessToken=${accessToken}`])
50
+ .send({
51
+ fields: { password: testData.strongPassword },
52
+ });
53
+
54
+ expect(res.status).toEqual(400);
55
+ expect(res.body.message).toBe('username is required');
56
+
57
+ expect(res.body).not.toHaveProperty('password');
58
+ expect(res.body).not.toHaveProperty('hashed_password');
59
+ expect(res.body).not.toHaveProperty('salt');
60
+ });
61
+
62
+ it('POST /tables/_users/rows should throw 400 error if the password is not strong', async () => {
63
+ const accessToken = await generateToken(
64
+ { username: 'John', isSuperuser: true },
65
+ config.tokenSecret,
66
+ '1H',
67
+ );
68
+
69
+ const res = await requestWithSupertest
70
+ .post('/api/tables/_users/rows')
71
+ .set('Cookie', [`accessToken=${accessToken}`])
72
+ .send({
73
+ fields: {
74
+ username: testData.users.user2.username,
75
+ password: testData.weakPassword,
76
+ },
77
+ });
78
+
79
+ expect(res.status).toEqual(400);
80
+ expect(res.body.message).toBe(
81
+ 'This password is weak, please use another password',
82
+ );
83
+
84
+ expect(res.body).not.toHaveProperty('password');
85
+ expect(res.body).not.toHaveProperty('hashed_password');
86
+ expect(res.body).not.toHaveProperty('salt');
87
+ });
88
+
89
+ it('POST /tables/_users/rows should throw 409 error if the username is taken', async () => {
90
+ const accessToken = await generateToken(
91
+ { username: 'John', isSuperuser: true },
92
+ config.tokenSecret,
93
+ '1H',
94
+ );
95
+
96
+ const res = await requestWithSupertest
97
+ .post('/api/tables/_users/rows')
98
+ .set('Cookie', [`accessToken=${accessToken}`])
99
+ .send({
100
+ fields: {
101
+ username: testData.users.user1.username,
102
+ password: testData.strongPassword,
103
+ },
104
+ });
105
+
106
+ expect(res.status).toEqual(409);
107
+ expect(res.body.message).toBe('This username is taken');
108
+
109
+ expect(res.body).not.toHaveProperty('password');
110
+ expect(res.body).not.toHaveProperty('hashed_password');
111
+ expect(res.body).not.toHaveProperty('salt');
112
+ });
113
+
114
+ it('GET /tables/_users/rows should return list of users', async () => {
115
+ const accessToken = await generateToken(
116
+ { username: 'John', isSuperuser: true },
117
+ config.tokenSecret,
118
+ '1H',
119
+ );
120
+
121
+ const res = await requestWithSupertest
122
+ .get('/api/tables/_users/rows')
123
+ .set('Cookie', [`accessToken=${accessToken}`]);
124
+
125
+ expect(res.status).toEqual(200);
126
+ expect(res.body.data[0]).toHaveProperty('id');
127
+ expect(res.body.data[0]).toHaveProperty('username');
128
+ expect(res.body.data[0]).toHaveProperty('is_superuser');
129
+ expect(res.body.data[0]).toHaveProperty('createdAt');
130
+
131
+ expect(res.body.data[0]).not.toHaveProperty('password');
132
+ expect(res.body.data[0]).not.toHaveProperty('hashed_password');
133
+ expect(res.body.data[0]).not.toHaveProperty('salt');
134
+ });
135
+
136
+ it('GET /tables/_users/rows/:id should retrive a single user', async () => {
137
+ const accessToken = await generateToken(
138
+ { username: 'John', isSuperuser: true },
139
+ config.tokenSecret,
140
+ '1H',
141
+ );
142
+
143
+ const res = await requestWithSupertest
144
+ .get('/api/tables/_users/rows/1')
145
+ .set('Cookie', [`accessToken=${accessToken}`]);
146
+
147
+ expect(res.status).toEqual(200);
148
+ expect(res.body.data[0]).toHaveProperty('id');
149
+ expect(res.body.data[0]).toHaveProperty('username');
150
+ expect(res.body.data[0]).toHaveProperty('is_superuser');
151
+ expect(res.body.data[0]).toHaveProperty('createdAt');
152
+
153
+ expect(res.body.data[0]).not.toHaveProperty('password');
154
+ expect(res.body.data[0]).not.toHaveProperty('hashed_password');
155
+ expect(res.body.data[0]).not.toHaveProperty('salt');
156
+ });
157
+
158
+ it('PUT /tables/_users/rows/:id should update a user', async () => {
159
+ const accessToken = await generateToken(
160
+ { username: 'John', isSuperuser: true },
161
+ config.tokenSecret,
162
+ '1H',
163
+ );
164
+
165
+ const res = await requestWithSupertest
166
+ .put('/api/tables/_users/rows/1')
167
+ .set('Cookie', [`accessToken=${accessToken}`])
168
+ .send({
169
+ fields: {
170
+ username: testData.users.user3.username,
171
+ },
172
+ });
173
+
174
+ expect(res.status).toEqual(200);
175
+ expect(res.type).toEqual(expect.stringContaining('json'));
176
+
177
+ expect(res.body).toHaveProperty('message');
178
+ expect(res.body.message).toBe('Row updated');
179
+
180
+ expect(res.body).not.toHaveProperty('password');
181
+ expect(res.body).not.toHaveProperty('hashed_password');
182
+ expect(res.body).not.toHaveProperty('salt');
183
+ });
184
+
185
+ it('DELETE /tables/_users/rows/:id should remove a user', async () => {
186
+ const accessToken = await generateToken(
187
+ { username: 'John', isSuperuser: true },
188
+ config.tokenSecret,
189
+ '1H',
190
+ );
191
+
192
+ const res = await requestWithSupertest
193
+ .delete('/api/tables/_users/rows/2')
194
+ .set('Cookie', [`accessToken=${accessToken}`]);
195
+
196
+ expect(res.status).toEqual(400);
197
+ expect(res.body.message).toBe('FOREIGN KEY constraint failed');
198
+
199
+ expect(res.body).not.toHaveProperty('password');
200
+ expect(res.body).not.toHaveProperty('hashed_password');
201
+ expect(res.body).not.toHaveProperty('salt');
202
+ });
203
+ });
204
+
205
+ describe('Obtain Access Token Endpoint', () => {
206
+ it('POST /auth/token/obtain should return an access token and refresh token values and a success message', async () => {
207
+ const res = await requestWithSupertest
208
+ .post('/api/auth/token/obtain')
209
+ .send({
210
+ fields: {
211
+ username: testData.users.user1.username,
212
+ password: testData.strongPassword,
213
+ },
214
+ });
215
+
216
+ expect(res.status).toEqual(201);
217
+ expect(res.type).toEqual(expect.stringContaining('json'));
218
+ expect(res.body).toHaveProperty('message');
219
+ expect(res.body.message).toBe('Success');
220
+
221
+ expect(res.headers['set-cookie']).toBeDefined();
222
+ expect(res.headers['set-cookie']).toEqual(
223
+ expect.arrayContaining([
224
+ expect.stringContaining('refreshToken='),
225
+ expect.stringContaining('accessToken='),
226
+ ]),
227
+ );
228
+
229
+ expect(res.body).not.toHaveProperty('password');
230
+ expect(res.body).not.toHaveProperty('hashed_password');
231
+ expect(res.body).not.toHaveProperty('salt');
232
+ });
233
+
234
+ it('POST /auth/token/obtain should throw a 401 error if the username does not exist in the DB', async () => {
235
+ const res = await requestWithSupertest
236
+ .post('/api/auth/token/obtain')
237
+ .send({
238
+ fields: {
239
+ username: testData.invalidUsername,
240
+ password: testData.strongPassword,
241
+ },
242
+ });
243
+
244
+ expect(res.status).toEqual(401);
245
+ expect(res.type).toEqual(expect.stringContaining('json'));
246
+ expect(res.body).toHaveProperty('message');
247
+ expect(res.body.message).toBe('Invalid username or password');
248
+
249
+ expect(res.body).not.toHaveProperty('password');
250
+ expect(res.body).not.toHaveProperty('hashed_password');
251
+ expect(res.body).not.toHaveProperty('salt');
252
+ });
253
+
254
+ it('POST /auth/token/obtain should throw a 401 error if the password is invalid', async () => {
255
+ const res = await requestWithSupertest
256
+ .post('/api/auth/token/obtain')
257
+ .send({
258
+ fields: {
259
+ username: testData.users.user1.username,
260
+ password: testData.invalidPassword,
261
+ },
262
+ });
263
+
264
+ expect(res.status).toEqual(401);
265
+ expect(res.type).toEqual(expect.stringContaining('json'));
266
+ expect(res.body).toHaveProperty('message');
267
+ expect(res.body.message).toBe('Invalid username or password');
268
+
269
+ expect(res.body).not.toHaveProperty('password');
270
+ expect(res.body).not.toHaveProperty('hashed_password');
271
+ expect(res.body).not.toHaveProperty('salt');
272
+ });
273
+ });
274
+
275
+ describe('Refresh Access Token Endpoint', () => {
276
+ it('GET /auth/token/refresh should refresh the access and refresh tokens', async () => {
277
+ const refreshToken = await generateToken(
278
+ { username: 'John', userId: 1, isSuperuser: true },
279
+ config.tokenSecret,
280
+ '1H',
281
+ );
282
+
283
+ const res = await requestWithSupertest
284
+ .get('/api/auth/token/refresh')
285
+ .set('Cookie', [`refreshToken=${refreshToken}`]);
286
+
287
+ expect(res.status).toEqual(200);
288
+ expect(res.type).toEqual(expect.stringContaining('json'));
289
+ expect(res.body).toHaveProperty('message');
290
+ expect(res.body.message).toBe('Success');
291
+
292
+ expect(res.headers['set-cookie']).toBeDefined();
293
+ expect(res.headers['set-cookie']).toEqual(
294
+ expect.arrayContaining([
295
+ expect.stringContaining('refreshToken='),
296
+ expect.stringContaining('accessToken='),
297
+ ]),
298
+ );
299
+ });
300
+ });
301
+
302
+ describe('Change Password Endpoint', () => {
303
+ it('PUT /auth/change-password/ should change a password', async () => {
304
+ const accessToken = await generateToken(
305
+ { username: 'John', userId: 2, isSuperuser: true },
306
+ config.tokenSecret,
307
+ '1H',
308
+ );
309
+
310
+ const res = await requestWithSupertest
311
+ .put('/api/auth/change-password')
312
+ .set('Cookie', [`accessToken=${accessToken}`])
313
+ .send({
314
+ fields: {
315
+ currentPassword: testData.strongPassword,
316
+ newPassword: testData.strongPassword2,
317
+ },
318
+ });
319
+
320
+ expect(res.status).toEqual(200);
321
+ expect(res.type).toEqual(expect.stringContaining('json'));
322
+ expect(res.body).toHaveProperty('message');
323
+ expect(res.body.message).toBe('Password updated successfully');
324
+
325
+ expect(res.body).not.toHaveProperty('password');
326
+ expect(res.body).not.toHaveProperty('hashed_password');
327
+ expect(res.body).not.toHaveProperty('salt');
328
+
329
+ // check if the password is really updated
330
+ const res2 = await requestWithSupertest
331
+ .post('/api/auth/token/obtain')
332
+ .send({
333
+ fields: {
334
+ username: testData.users.user1.username,
335
+ password: testData.strongPassword2,
336
+ },
337
+ });
338
+
339
+ expect(res2.status).toEqual(201);
340
+ expect(res2.type).toEqual(expect.stringContaining('json'));
341
+ expect(res2.body).toHaveProperty('message');
342
+ expect(res2.body.message).toBe('Success');
343
+ });
344
+
345
+ it('PUT /auth/change-password/ should throw 401 error if the current password is not valid', async () => {
346
+ const accessToken = await generateToken(
347
+ { username: 'John', userId: 2, isSuperuser: true },
348
+ config.tokenSecret,
349
+ '1H',
350
+ );
351
+
352
+ const res = await requestWithSupertest
353
+ .put('/api/auth/change-password')
354
+ .set('Cookie', [`accessToken=${accessToken}`])
355
+ .send({
356
+ fields: {
357
+ currentPassword: testData.invalidPassword,
358
+ newPassword: testData.strongPassword2,
359
+ },
360
+ });
361
+
362
+ expect(res.status).toEqual(401);
363
+ expect(res.type).toEqual(expect.stringContaining('json'));
364
+ expect(res.body).toHaveProperty('message');
365
+ expect(res.body.message).toBe('Invalid current password');
366
+
367
+ expect(res.body).not.toHaveProperty('password');
368
+ expect(res.body).not.toHaveProperty('hashed_password');
369
+ expect(res.body).not.toHaveProperty('salt');
370
+ });
371
+ });
372
+ });
@@ -1,12 +1,6 @@
1
1
  const db = require('../db/index');
2
2
  const { rowService } = require('../services');
3
3
 
4
- const quotePrimaryKeys = (pks) => {
5
- const primaryKeys = pks.split(',');
6
- const quotedPks = primaryKeys.map((id) => `'${id}'`).join(',');
7
- return quotedPks;
8
- };
9
-
10
4
  const operators = {
11
5
  eq: '=',
12
6
  lt: '<',
@@ -19,7 +13,7 @@ const operators = {
19
13
  };
20
14
 
21
15
  // Return paginated rows of a table
22
- const listTableRows = async (req, res) => {
16
+ const listTableRows = async (req, res, next) => {
23
17
  /*
24
18
  #swagger.tags = ['Rows']
25
19
  #swagger.summary = 'List Rows'
@@ -66,7 +60,7 @@ const listTableRows = async (req, res) => {
66
60
  _ordering,
67
61
  _schema,
68
62
  _extend,
69
- _filters = ''
63
+ _filters = '',
70
64
  } = req.query;
71
65
 
72
66
  const page = parseInt(_page);
@@ -80,10 +74,16 @@ const listTableRows = async (req, res) => {
80
74
  let filters = [];
81
75
 
82
76
  // split the filters by comma(,) except when in an array
83
- const re = /(\w+:?(\[.*?\]|\w+)?)/g;
77
+ const re = /,(?![^[]*?\])/;
84
78
  try {
85
- filters = _filters.match(re)?.map((filter) => {
86
- let [key, value] = filter.split(':');
79
+ filters = _filters.split(re).map((filter) => {
80
+ //NOTE: When using the _filter parameter, the values are split using the ":" sign, like this (_filters=Total__eq:1). However, if the user sends a date value, such as (_filters=InvoiceDate__eq:2010-01-08 00:00:00), there will be additional colon (":") signs present.
81
+ let [key, ...value] = filter.split(':');
82
+ if (value.length === 1) {
83
+ value = value[0];
84
+ } else {
85
+ value = value.map((element) => element).join(':');
86
+ }
87
87
 
88
88
  let field = key.split('__')[0];
89
89
  let fieldOperator = key.split('__')[1];
@@ -92,7 +92,7 @@ const listTableRows = async (req, res) => {
92
92
  fieldOperator = 'eq';
93
93
  } else if (!operators[fieldOperator]) {
94
94
  throw new Error(
95
- `Invalid field operator '${fieldOperator}' for field '${field}'. You can only use the following operators after the '${field}' field: __lt, __gt, __lte, __gte, __eq, __neq.`
95
+ `Invalid field operator '${fieldOperator}' for field '${field}'. You can only use the following operators after the '${field}' field: __lt, __gt, __lte, __gte, __eq, __neq.`,
96
96
  );
97
97
  }
98
98
 
@@ -106,7 +106,7 @@ const listTableRows = async (req, res) => {
106
106
  } catch (error) {
107
107
  return res.status(400).json({
108
108
  message: error.message,
109
- error: error
109
+ error: error,
110
110
  });
111
111
  }
112
112
 
@@ -155,7 +155,7 @@ const listTableRows = async (req, res) => {
155
155
  } catch (error) {
156
156
  return res.status(400).json({
157
157
  message: error.message,
158
- error: error
158
+ error: error,
159
159
  });
160
160
  }
161
161
  }
@@ -230,7 +230,7 @@ const listTableRows = async (req, res) => {
230
230
 
231
231
  if (!foreignKey) {
232
232
  throw new Error(
233
- `Foreign key not found for extended field '${extendedField}'`
233
+ `Foreign key not found for extended field '${extendedField}'`,
234
234
  );
235
235
  }
236
236
 
@@ -248,7 +248,7 @@ const listTableRows = async (req, res) => {
248
248
  joinedTableFields
249
249
  .map(
250
250
  (joinedTableField) =>
251
- `'${joinedTableField.name}', ${joinedTableName}.${joinedTableField.name}`
251
+ `'${joinedTableField.name}', ${joinedTableName}.${joinedTableField.name}`,
252
252
  )
253
253
  .join(', ') +
254
254
  ' ) as ' +
@@ -271,7 +271,7 @@ const listTableRows = async (req, res) => {
271
271
  if (foreignKeyError.error) {
272
272
  return res.status(400).json({
273
273
  message: foreignKeyError.message,
274
- error: foreignKeyError.error
274
+ error: foreignKeyError.error,
275
275
  });
276
276
  }
277
277
  }
@@ -308,7 +308,7 @@ const listTableRows = async (req, res) => {
308
308
  whereStringValues,
309
309
  });
310
310
 
311
- const next =
311
+ const nextPage =
312
312
  data.length === limit
313
313
  ? `/tables/${tableName}/rows?${params}_limit=${_limit}&_page=${
314
314
  page + 1
@@ -321,16 +321,15 @@ const listTableRows = async (req, res) => {
321
321
  }`
322
322
  : null;
323
323
 
324
- res.json({
325
- data,
326
- total,
327
- next,
328
- previous
329
- });
324
+ req.response = {
325
+ status: 200,
326
+ payload: { data, total, next: nextPage, previous },
327
+ };
328
+ next();
330
329
  } catch (error) {
331
330
  res.status(400).json({
332
331
  message: error.message,
333
- error: error
332
+ error: error,
334
333
  });
335
334
  }
336
335
  };
@@ -361,7 +360,7 @@ const insertRowInTable = async (req, res, next) => {
361
360
 
362
361
  // Remove null values from fields for accurate query construction.
363
362
  const fields = Object.fromEntries(
364
- Object.entries(queryFields).filter(([_, value]) => value !== null)
363
+ Object.entries(queryFields).filter(([, value]) => value !== null),
365
364
  );
366
365
 
367
366
  try {
@@ -379,6 +378,7 @@ const insertRowInTable = async (req, res, next) => {
379
378
  message: 'Row inserted',
380
379
  data,
381
380
  });
381
+
382
382
  req.broadcast = {
383
383
  type: 'INSERT',
384
384
  data: {
@@ -404,7 +404,7 @@ const insertRowInTable = async (req, res, next) => {
404
404
  };
405
405
 
406
406
  // Get a row by pk
407
- const getRowInTableByPK = async (req, res) => {
407
+ const getRowInTableByPK = async (req, res, next) => {
408
408
  /*
409
409
  #swagger.tags = ['Rows']
410
410
  #swagger.summary = 'Retrieve Row'
@@ -536,7 +536,7 @@ const getRowInTableByPK = async (req, res) => {
536
536
  joinedTableFields
537
537
  .map(
538
538
  (joinedTableField) =>
539
- `'${joinedTableField.name}', ${joinedTableName}.${joinedTableField.name}`
539
+ `'${joinedTableField.name}', ${joinedTableName}.${joinedTableField.name}`,
540
540
  )
541
541
  .join(', ') +
542
542
  ' ) as ' +
@@ -585,9 +585,8 @@ const getRowInTableByPK = async (req, res) => {
585
585
  error: 'not_found',
586
586
  });
587
587
  } else {
588
- res.json({
589
- data,
590
- });
588
+ req.response = { status: 200, payload: { data } };
589
+ next();
591
590
  }
592
591
  } catch (error) {
593
592
  return res.status(400).json({