tango-app-api-audit 1.0.22 → 1.0.23
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
CHANGED
|
@@ -922,3 +922,142 @@ export async function summarySplit( req, res ) {
|
|
|
922
922
|
return res.sendError( err, 500 );
|
|
923
923
|
}
|
|
924
924
|
}
|
|
925
|
+
|
|
926
|
+
export async function overViewTable( req, res ) {
|
|
927
|
+
try {
|
|
928
|
+
const inputData = req.body;
|
|
929
|
+
const limit = inputData.limit || 10;
|
|
930
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
931
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
932
|
+
let filters =[
|
|
933
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
934
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
935
|
+
{ auditStatus: { $in: inputData.filterByStatus } },
|
|
936
|
+
{ auditType: { $in: inputData.filterByAuditType } },
|
|
937
|
+
|
|
938
|
+
];
|
|
939
|
+
if ( inputData.clientId.length > 0 ) {
|
|
940
|
+
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
const query =[
|
|
944
|
+
{
|
|
945
|
+
$match: {
|
|
946
|
+
$and: filters,
|
|
947
|
+
},
|
|
948
|
+
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
$project: {
|
|
952
|
+
_id: 0,
|
|
953
|
+
storeId: 1,
|
|
954
|
+
fileDate: 1,
|
|
955
|
+
beforeCount: 1,
|
|
956
|
+
startTime: 1,
|
|
957
|
+
auditType: 1,
|
|
958
|
+
auditStatus: 1,
|
|
959
|
+
userId: 1,
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
},
|
|
963
|
+
},
|
|
964
|
+
{
|
|
965
|
+
$lookup: {
|
|
966
|
+
from: 'users',
|
|
967
|
+
let: { userId: '$userId' },
|
|
968
|
+
pipeline: [
|
|
969
|
+
{
|
|
970
|
+
$match: {
|
|
971
|
+
$expr: {
|
|
972
|
+
$eq: [ '$_id', '$$userId' ],
|
|
973
|
+
},
|
|
974
|
+
},
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
$project: {
|
|
978
|
+
userName: 1,
|
|
979
|
+
userEmail: '$email',
|
|
980
|
+
},
|
|
981
|
+
},
|
|
982
|
+
], as: 'user',
|
|
983
|
+
},
|
|
984
|
+
},
|
|
985
|
+
{
|
|
986
|
+
$unwind: {
|
|
987
|
+
path: '$user',
|
|
988
|
+
preserveNullAndEmptyArrays: true,
|
|
989
|
+
},
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
$project: {
|
|
993
|
+
storeId: 1,
|
|
994
|
+
fileDate: 1,
|
|
995
|
+
beforeCount: 1,
|
|
996
|
+
startTime: 1,
|
|
997
|
+
auditType: 1,
|
|
998
|
+
auditStatus: 1,
|
|
999
|
+
userName: '$users.userName',
|
|
1000
|
+
userEmail: '$users.userEmail',
|
|
1001
|
+
|
|
1002
|
+
},
|
|
1003
|
+
},
|
|
1004
|
+
];
|
|
1005
|
+
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
1006
|
+
query.push( {
|
|
1007
|
+
$match: {
|
|
1008
|
+
$or: [
|
|
1009
|
+
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1010
|
+
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1011
|
+
],
|
|
1012
|
+
|
|
1013
|
+
},
|
|
1014
|
+
} );
|
|
1015
|
+
}
|
|
1016
|
+
if ( inputData.sortColumnName ) {
|
|
1017
|
+
const sortBy = inputData.sortBy || -1;
|
|
1018
|
+
query.push( {
|
|
1019
|
+
$sort: { [inputData.sortColumName]: sortBy },
|
|
1020
|
+
},
|
|
1021
|
+
);
|
|
1022
|
+
}
|
|
1023
|
+
const count = await aggregateUserAudit( query );
|
|
1024
|
+
if ( count.length == 0 ) {
|
|
1025
|
+
return res.sendError( 'No Data Found', 204 );
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
if ( inputData.isExport ) {
|
|
1029
|
+
query.push( { limit: 10000 } );
|
|
1030
|
+
} else {
|
|
1031
|
+
query.push( {
|
|
1032
|
+
$skip: offset,
|
|
1033
|
+
},
|
|
1034
|
+
{
|
|
1035
|
+
$limit: limit,
|
|
1036
|
+
} );
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
const result = await aggregateUserAudit( query );
|
|
1040
|
+
if ( inputData.isExport ) {
|
|
1041
|
+
const exportdata = [];
|
|
1042
|
+
result.forEach( ( element ) => {
|
|
1043
|
+
exportdata.push( {
|
|
1044
|
+
'Store Id': element.storeId,
|
|
1045
|
+
'File Date': element.fileDtae,
|
|
1046
|
+
'Audit Type': element.audittype,
|
|
1047
|
+
'Before Count': element.beforeCount,
|
|
1048
|
+
'Start Time': element.startTime,
|
|
1049
|
+
'User Name': element.userName,
|
|
1050
|
+
'User Email': element.userEmail,
|
|
1051
|
+
'Status': element.auditStatus,
|
|
1052
|
+
} );
|
|
1053
|
+
} );
|
|
1054
|
+
await download( exportdata, res );
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
1058
|
+
} catch ( error ) {
|
|
1059
|
+
const err = error.message || 'Internal Server Error';
|
|
1060
|
+
logger.error( { error: error, message: req.body, function: 'summarySplit' } );
|
|
1061
|
+
return res.sendError( err, 500 );
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { clientMetricsSchema, getAuditImagesSchema, overViewCardSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema } from '../dtos/auditMetrics.dtos.js';
|
|
2
|
+
import { clientMetricsSchema, getAuditImagesSchema, overViewCardSchema, overViewTableSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema } from '../dtos/auditMetrics.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const auditMetricsDocs = {
|
|
5
5
|
|
|
@@ -157,4 +157,26 @@ export const auditMetricsDocs = {
|
|
|
157
157
|
},
|
|
158
158
|
},
|
|
159
159
|
},
|
|
160
|
+
'/v3/audit-metrics/overview-table': {
|
|
161
|
+
post: {
|
|
162
|
+
tags: [ 'Audit Metrics' ],
|
|
163
|
+
description: `Get overall user taken data with some filters `,
|
|
164
|
+
operationId: 'overview-table',
|
|
165
|
+
parameters: {},
|
|
166
|
+
requestBody: {
|
|
167
|
+
content: {
|
|
168
|
+
'application/json': {
|
|
169
|
+
schema: j2s( overViewTableSchema ).swagger,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
responses: {
|
|
174
|
+
200: { description: 'Successful' },
|
|
175
|
+
401: { description: 'Unauthorized User' },
|
|
176
|
+
422: { description: 'Field Error' },
|
|
177
|
+
500: { description: 'Server Error' },
|
|
178
|
+
204: { description: 'Not Found' },
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
160
182
|
};
|
|
@@ -118,3 +118,23 @@ export const summarySplitSchema = joi.object(
|
|
|
118
118
|
export const summarySplitValid = {
|
|
119
119
|
body: summarySplitSchema,
|
|
120
120
|
};
|
|
121
|
+
|
|
122
|
+
export const overViewTableSchema = joi.object(
|
|
123
|
+
{
|
|
124
|
+
fromDate: joi.string().required(),
|
|
125
|
+
toDate: joi.string().required(),
|
|
126
|
+
clientId: joi.array().optional(),
|
|
127
|
+
limit: joi.number().optional(),
|
|
128
|
+
offset: joi.number().optional(),
|
|
129
|
+
searchValue: joi.number().optional().allow( '' ),
|
|
130
|
+
filterByStatus: joi.array().required(),
|
|
131
|
+
filterByAuditType: joi.array().required(),
|
|
132
|
+
sortColumnName: joi.string().optional(),
|
|
133
|
+
sortBy: joi.number().optional(),
|
|
134
|
+
isExport: joi.boolean().optional(),
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
export const overViewTableValid = {
|
|
139
|
+
body: overViewTableSchema,
|
|
140
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { clientMetrics, overViewCard, storeMetrics, summarySplit, userAuditHistory, userMetrics } from '../controllers/auditMetrics.controllers.js';
|
|
5
|
-
import { clientMetricsValid, overViewCardValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid } from '../dtos/auditMetrics.dtos.js';
|
|
4
|
+
import { clientMetrics, overViewCard, overViewTable, storeMetrics, summarySplit, userAuditHistory, userMetrics } from '../controllers/auditMetrics.controllers.js';
|
|
5
|
+
import { clientMetricsValid, overViewCardValid, overViewTableValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid } from '../dtos/auditMetrics.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditMetricsRouter = express.Router();
|
|
8
8
|
|
|
@@ -12,5 +12,6 @@ auditMetricsRouter.post( '/client-metrics', isAllowedSessionHandler, validate( c
|
|
|
12
12
|
auditMetricsRouter.post( '/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
|
|
13
13
|
auditMetricsRouter.post( '/overview-card', isAllowedSessionHandler, validate( overViewCardValid ), overViewCard );
|
|
14
14
|
auditMetricsRouter.post( '/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
|
|
15
|
+
auditMetricsRouter.post( '/overview-table', isAllowedSessionHandler, validate( overViewTableValid ), overViewTable );
|
|
15
16
|
|
|
16
17
|
export default auditMetricsRouter;
|