tango-app-api-audit 1.0.17 → 1.0.19

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/index.js CHANGED
@@ -8,7 +8,9 @@ import clientRouter from './src/routes/client.routes.js';
8
8
  import { clientDocs } from './src/docs/client.docs.js';
9
9
  import { storeRouter } from './src/routes/store.routes.js';
10
10
  import { storeDocs } from './src/docs/store.docs.js';
11
+ import { userDocs } from './src/docs/user.docs.js';
12
+ import { userRouter } from './src/routes/user.routes.js';
11
13
 
12
- export { auditRouter, auditMetricsRouter, auditMetricsDocs, auditDocs, clientRouter, clientDocs, storeRouter, storeDocs };
14
+ export { auditRouter, auditMetricsRouter, auditMetricsDocs, auditDocs, clientRouter, clientDocs, storeRouter, storeDocs, userRouter, userDocs };
13
15
 
14
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,61 +1,26 @@
1
1
  import { logger } from 'tango-app-api-middleware';
2
- import { aggregateAuditClientData } from '../service/auditClientData.service.js';
2
+ import { aggregateStore } from '../service/store.service.js';
3
3
 
4
4
  export async function auditStoreList( req, res ) {
5
5
  try {
6
- const inputData = req.query;
6
+ const inputData = req.body;
7
7
  const query =[
8
8
  {
9
9
  $match: {
10
- clientId: { $eq: inputData.clientId },
11
- fileDate: { $eq: inputData.fileDate },
10
+ clientId: { $in: inputData.clientId },
12
11
  },
13
12
  },
14
13
  {
15
14
  $project: {
16
15
  _id: 0,
17
- clientName: 1,
18
16
  clientId: 1,
19
- storeList: 1,
20
- },
21
- },
22
- {
23
- $lookup: {
24
- from: 'stores',
25
- let: { storeList: '$storeList' },
26
- pipeline: [
27
- {
28
- $match: {
29
- $expr: {
30
- $in: [ '$storeId', '$$storeList' ],
31
- },
32
- },
33
- },
34
- {
35
- $project: {
36
- _id: 1,
37
- storeId: 1,
38
- storeName: 1,
39
- clientId: 1,
40
- },
41
- },
42
- ], as: 'stores',
43
- },
44
-
45
- },
46
- {
47
- $unwind: { path: '$stores', preserveNullAndEmptyArrays: true },
48
- },
49
- {
50
- $project: {
51
- storeName: '$stores.storeName',
52
- storeId: '$stores.storeId',
53
- clientId: '$clientId',
17
+ storeId: 1,
18
+ storeName: 1,
54
19
  },
55
20
  },
56
21
  ];
57
22
 
58
- const count = await aggregateAuditClientData( query );
23
+ const count = await aggregateStore( query );
59
24
  if ( count.length == 0 ) {
60
25
  return res.sendSuccess( { result: [], count: 0 } );
61
26
  }
@@ -66,12 +31,12 @@ export async function auditStoreList( req, res ) {
66
31
  { $limit: limit },
67
32
  );
68
33
  }
69
- const getAuditClients = await aggregateAuditClientData( query );
34
+ const result = await aggregateStore( query );
70
35
 
71
- return res.sendSuccess( { result: getAuditClients, count: count.length } );
36
+ return res.sendSuccess( { result: result, count: count.length } );
72
37
  } catch ( error ) {
73
38
  const err = error.message || 'Internal Server Error';
74
- logger.info( { error: error, messgae: req.query, function: 'auditStoreList' } );
39
+ logger.info( { error: error, messgae: req.body, function: 'auditStoreList' } );
75
40
  return res.sendError( err, 500 );
76
41
  }
77
42
  }
@@ -0,0 +1,41 @@
1
+ import { logger } from 'tango-app-api-middleware';
2
+ import { aggregateUser } from '../service/user.service.js';
3
+
4
+ export async function auditUserList( req, res ) {
5
+ try {
6
+ const inputData = req.query;
7
+ const query =[
8
+ {
9
+ $match: {
10
+ userType: { $eq: 'tango' },
11
+ },
12
+ },
13
+ {
14
+ $project: {
15
+ userName: 1,
16
+ userId: '$_id',
17
+ _id: 0,
18
+ },
19
+ },
20
+ ];
21
+
22
+ const count = await aggregateUser( query );
23
+ if ( count.length == 0 ) {
24
+ return res.sendSuccess( { result: [], count: 0 } );
25
+ }
26
+ if ( inputData.limit ) {
27
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * inputData.limit : 0;
28
+ query.push(
29
+ { $skip: offset },
30
+ { $limit: limit },
31
+ );
32
+ }
33
+ const result = await aggregateUser( query );
34
+
35
+ return res.sendSuccess( { result: result, count: count.length } );
36
+ } catch ( error ) {
37
+ const err = error.message || 'Internal Server Error';
38
+ logger.info( { error: error, messgae: req.query, function: 'auditUserList' } );
39
+ return res.sendError( err, 500 );
40
+ }
41
+ }
@@ -3,36 +3,18 @@ import { auditStoreSchema } from '../dtos/store.dtos.js';
3
3
 
4
4
  export const storeDocs = {
5
5
  '/v3/audit/store/audit-stores': {
6
- get: {
7
- tags: [ 'Audit/Store' ],
8
- description: 'Get client list which is enable for audit',
9
- operationId: 'clients',
10
- parameters: [
11
- {
12
- in: 'query',
13
- name: 'clientId',
14
- scema: j2s( auditStoreSchema ).swagger,
15
- require: true,
6
+ post: {
7
+ tags: [ 'Audit/Stores' ],
8
+ description: `sGet list of stores`,
9
+ operationId: 'audit-stores',
10
+ parameters: {},
11
+ requestBody: {
12
+ content: {
13
+ 'application/json': {
14
+ schema: j2s( auditStoreSchema ).swagger,
15
+ },
16
16
  },
17
- {
18
- in: 'query',
19
- name: 'fileDate',
20
- scema: j2s( auditStoreSchema ).swagger,
21
- require: true,
22
- },
23
- {
24
- in: 'query',
25
- name: 'limit',
26
- scema: j2s( auditStoreSchema ).swagger,
27
- require: false,
28
- },
29
- {
30
- in: 'query',
31
- name: 'offset',
32
- scema: j2s( auditStoreSchema ).swagger,
33
- require: false,
34
- },
35
- ],
17
+ },
36
18
  responses: {
37
19
  200: { description: 'Successful' },
38
20
  401: { description: 'Unauthorized User' },
@@ -0,0 +1,33 @@
1
+ import j2s from 'joi-to-swagger';
2
+ import { userSchema } from '../dtos/user.dtos.js';
3
+
4
+ export const userDocs = {
5
+ '/v3/audit/user/tango-users': {
6
+ get: {
7
+ tags: [ 'Audit/User' ],
8
+ description: 'Get user list',
9
+ operationId: 'tango-users',
10
+ parameters: [
11
+ {
12
+ in: 'query',
13
+ name: 'limit',
14
+ scema: j2s( userSchema ).swagger,
15
+ require: false,
16
+ },
17
+ {
18
+ in: 'query',
19
+ name: 'offset',
20
+ scema: j2s( userSchema ).swagger,
21
+ require: false,
22
+ },
23
+ ],
24
+ responses: {
25
+ 200: { description: 'Successful' },
26
+ 401: { description: 'Unauthorized User' },
27
+ 422: { description: 'Field Error' },
28
+ 500: { description: 'Server Error' },
29
+ 204: { description: 'Not Found' },
30
+ },
31
+ },
32
+ },
33
+ };
@@ -3,13 +3,12 @@ import joi from 'joi';
3
3
 
4
4
  export const auditStoreSchema = joi.object(
5
5
  {
6
- clientId: joi.string().required(),
7
- fileDate: joi.string().required(),
6
+ clientId: joi.array().required(),
8
7
  limit: joi.number().optional(),
9
8
  offset: joi.number().optional(),
10
9
  },
11
10
  );
12
11
 
13
12
  export const auditStoreValid = {
14
- query: auditStoreSchema,
13
+ body: auditStoreSchema,
15
14
  };
@@ -0,0 +1,14 @@
1
+ import joi from 'joi';
2
+
3
+
4
+ export const userSchema = joi.object(
5
+ {
6
+
7
+ limit: joi.number().optional(),
8
+ offset: joi.number().optional(),
9
+ },
10
+ );
11
+
12
+ export const userValid = {
13
+ query: userSchema,
14
+ };
@@ -5,6 +5,6 @@ import { auditStoreValid } from '../dtos/store.dtos.js';
5
5
 
6
6
  export const storeRouter = Router();
7
7
 
8
- storeRouter.get( '/audit-stores', isAllowedSessionHandler, validate( auditStoreValid ), auditStoreList );
8
+ storeRouter.post( '/audit-stores', isAllowedSessionHandler, validate( auditStoreValid ), auditStoreList );
9
9
 
10
10
  export default storeRouter;
@@ -1,8 +1,9 @@
1
1
  import { Router } from 'express';
2
2
  import { isAllowedSessionHandler } from 'tango-app-api-middleware';
3
+ import { auditUserList } from '../controllers/user.controllers.js';
3
4
 
4
5
  export const userRouter = Router();
5
6
 
6
- userRouter.get( '/audit-users', isAllowedSessionHandler, auditUserList );
7
+ userRouter.get( '/tango-users', isAllowedSessionHandler, auditUserList );
7
8
 
8
9
  export default userRouter;
@@ -4,3 +4,7 @@ import storeModel from 'tango-api-schema/schema/store.model.js';
4
4
  export function findOneStore( query, fields ) {
5
5
  return storeModel.findOne( query, fields );
6
6
  }
7
+
8
+ export function aggregateStore( query, fields ) {
9
+ return storeModel.aggregate( query, fields );
10
+ }
@@ -4,3 +4,7 @@ import userModel from 'tango-api-schema/schema/user.model.js';
4
4
  export function findOneUser( query, fields ) {
5
5
  return userModel.findOne( query, fields );
6
6
  }
7
+
8
+ export function aggregateUser( query, fields ) {
9
+ return userModel.aggregate( query, fields );
10
+ }