tango-app-api-audit 1.0.17 → 1.0.18
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/package.json +1 -1
- package/src/controllers/store.controllers.js +9 -44
- package/src/controllers/user.controllers.js +41 -0
- package/src/docs/store.docs.js +11 -29
- package/src/docs/user.docs.js +33 -0
- package/src/dtos/store.dtos.js +2 -3
- package/src/dtos/user.dtos.js +14 -0
- package/src/routes/store.routes.js +1 -1
- package/src/routes/user.routes.js +2 -1
- package/src/service/store.service.js +4 -0
- package/src/service/user.service.js +4 -0
package/package.json
CHANGED
|
@@ -1,61 +1,26 @@
|
|
|
1
1
|
import { logger } from 'tango-app-api-middleware';
|
|
2
|
-
import {
|
|
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.
|
|
6
|
+
const inputData = req.body;
|
|
7
7
|
const query =[
|
|
8
8
|
{
|
|
9
9
|
$match: {
|
|
10
|
-
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
|
-
|
|
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
|
|
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
|
|
34
|
+
const result = await aggregateStore( query );
|
|
70
35
|
|
|
71
|
-
return res.sendSuccess( { result:
|
|
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.
|
|
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
|
+
}
|
package/src/docs/store.docs.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
tags: [ 'Audit/
|
|
8
|
-
description:
|
|
9
|
-
operationId: '
|
|
10
|
-
parameters:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
};
|
package/src/dtos/store.dtos.js
CHANGED
|
@@ -3,13 +3,12 @@ import joi from 'joi';
|
|
|
3
3
|
|
|
4
4
|
export const auditStoreSchema = joi.object(
|
|
5
5
|
{
|
|
6
|
-
clientId: joi.
|
|
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
|
-
|
|
13
|
+
body: auditStoreSchema,
|
|
15
14
|
};
|
|
@@ -5,6 +5,6 @@ import { auditStoreValid } from '../dtos/store.dtos.js';
|
|
|
5
5
|
|
|
6
6
|
export const storeRouter = Router();
|
|
7
7
|
|
|
8
|
-
storeRouter.
|
|
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( '/
|
|
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
|
+
}
|