tango-app-api-audit 1.0.21 → 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
|
@@ -814,3 +814,250 @@ export async function overViewCard( req, res ) {
|
|
|
814
814
|
return res.sendError( err, 500 );
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
|
+
|
|
818
|
+
export async function summarySplit( req, res ) {
|
|
819
|
+
try {
|
|
820
|
+
const inputData = req.body;
|
|
821
|
+
const temp = {
|
|
822
|
+
totalInprogress: 0,
|
|
823
|
+
auditInprogress: 0,
|
|
824
|
+
reAuditInprogress: 0,
|
|
825
|
+
draft: 0,
|
|
826
|
+
notAssigned: 0,
|
|
827
|
+
auditCompleted: 0,
|
|
828
|
+
reAuditCompleted: 0,
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
832
|
+
let filters =[
|
|
833
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
834
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
835
|
+
];
|
|
836
|
+
if ( inputData.clientId.length > 0 ) {
|
|
837
|
+
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
838
|
+
}
|
|
839
|
+
const query =[
|
|
840
|
+
{
|
|
841
|
+
$match: {
|
|
842
|
+
$and: filters,
|
|
843
|
+
},
|
|
844
|
+
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
$project: {
|
|
848
|
+
auditInprogress: {
|
|
849
|
+
$cond: [
|
|
850
|
+
{ $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$status', 'inprogress' ] } ] }, 1, 0,
|
|
851
|
+
],
|
|
852
|
+
},
|
|
853
|
+
reAuditInprogress: {
|
|
854
|
+
$cond: [
|
|
855
|
+
{ $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'inprogress' ] } ] }, 1, 0,
|
|
856
|
+
],
|
|
857
|
+
},
|
|
858
|
+
draft: {
|
|
859
|
+
$cond: [
|
|
860
|
+
{ $ne: [ '$status', 'drafted' ] }, 1, 0,
|
|
861
|
+
],
|
|
862
|
+
},
|
|
863
|
+
assigned: {
|
|
864
|
+
$cond: [
|
|
865
|
+
{ $ne: [ '$status', 'assigned' ] }, 1, 0,
|
|
866
|
+
],
|
|
867
|
+
},
|
|
868
|
+
completedCount: {
|
|
869
|
+
$cond: [
|
|
870
|
+
{ $eq: [ '$status', 'completed' ] }, 1, 0,
|
|
871
|
+
],
|
|
872
|
+
},
|
|
873
|
+
reAuditCompleted: {
|
|
874
|
+
$cond: [
|
|
875
|
+
{ $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
|
|
876
|
+
],
|
|
877
|
+
},
|
|
878
|
+
auditCompleted: {
|
|
879
|
+
$cond: [
|
|
880
|
+
{ $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
|
|
881
|
+
],
|
|
882
|
+
},
|
|
883
|
+
},
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
$group: {
|
|
887
|
+
_id: { fileDate: '$fileDate', clientId: '$clientId' },
|
|
888
|
+
totalInprogress: { $sum: 1 },
|
|
889
|
+
auditInprogress: { $sum: '$auditInprogress' },
|
|
890
|
+
reAuditInprogress: { $sum: '$reAuditInprogress' },
|
|
891
|
+
draft: { $sum: '$draft' },
|
|
892
|
+
assigned: { $sum: 'assigned' },
|
|
893
|
+
completedCount: { $sum: '$completedCount' },
|
|
894
|
+
reAuditCompleted: { $sum: '$reAuditCompleted' },
|
|
895
|
+
auditCompleted: { $sum: '$auditCompleted' },
|
|
896
|
+
completedCount: { $sum: '$completedCount' },
|
|
897
|
+
|
|
898
|
+
},
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
$project: {
|
|
902
|
+
_id: 0,
|
|
903
|
+
totalInprogress: 1,
|
|
904
|
+
auditInprogress: 1,
|
|
905
|
+
reAuditInprogress: 1,
|
|
906
|
+
draft: 1,
|
|
907
|
+
assigned: 1,
|
|
908
|
+
completedCount: 1,
|
|
909
|
+
reAuditCompleted: 1,
|
|
910
|
+
auditCompleted: 1,
|
|
911
|
+
completedCount: 1,
|
|
912
|
+
|
|
913
|
+
},
|
|
914
|
+
},
|
|
915
|
+
];
|
|
916
|
+
const result = await aggregateStoreAudit( query );
|
|
917
|
+
logger.info( { result: result } );
|
|
918
|
+
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
919
|
+
} catch ( error ) {
|
|
920
|
+
const err = error.message || 'Internal Server Error';
|
|
921
|
+
logger.error( { error: error, message: req.body, function: 'summarySplit' } );
|
|
922
|
+
return res.sendError( err, 500 );
|
|
923
|
+
}
|
|
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, 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
|
|
|
@@ -116,7 +116,7 @@ export const auditMetricsDocs = {
|
|
|
116
116
|
'/v3/audit-metrics/overview-card': {
|
|
117
117
|
post: {
|
|
118
118
|
tags: [ 'Audit Metrics' ],
|
|
119
|
-
description: `Get overall high level audited files count
|
|
119
|
+
description: `Get overall high level audited files count`,
|
|
120
120
|
operationId: 'overview-card',
|
|
121
121
|
parameters: {},
|
|
122
122
|
requestBody: {
|
|
@@ -135,4 +135,48 @@ export const auditMetricsDocs = {
|
|
|
135
135
|
},
|
|
136
136
|
},
|
|
137
137
|
},
|
|
138
|
+
'/v3/audit-metrics/summary-split-up': {
|
|
139
|
+
post: {
|
|
140
|
+
tags: [ 'Audit Metrics' ],
|
|
141
|
+
description: `Get overall high level audited files count splitup`,
|
|
142
|
+
operationId: 'summary-split-up',
|
|
143
|
+
parameters: {},
|
|
144
|
+
requestBody: {
|
|
145
|
+
content: {
|
|
146
|
+
'application/json': {
|
|
147
|
+
schema: j2s( summarySplitSchema ).swagger,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
responses: {
|
|
152
|
+
200: { description: 'Successful' },
|
|
153
|
+
401: { description: 'Unauthorized User' },
|
|
154
|
+
422: { description: 'Field Error' },
|
|
155
|
+
500: { description: 'Server Error' },
|
|
156
|
+
204: { description: 'Not Found' },
|
|
157
|
+
},
|
|
158
|
+
},
|
|
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
|
+
},
|
|
138
182
|
};
|
|
@@ -106,3 +106,35 @@ export const overViewCardSchema = joi.object(
|
|
|
106
106
|
export const overViewCardValid = {
|
|
107
107
|
body: overViewCardSchema,
|
|
108
108
|
};
|
|
109
|
+
|
|
110
|
+
export const summarySplitSchema = joi.object(
|
|
111
|
+
{
|
|
112
|
+
fromDate: joi.string().required(),
|
|
113
|
+
toDate: joi.string().required(),
|
|
114
|
+
clientId: joi.array().optional(),
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
export const summarySplitValid = {
|
|
119
|
+
body: summarySplitSchema,
|
|
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, userAuditHistory, userMetrics } from '../controllers/auditMetrics.controllers.js';
|
|
5
|
-
import { clientMetricsValid, overViewCardValid, storeMetricsValid, 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
|
|
|
@@ -11,5 +11,7 @@ auditMetricsRouter.post( '/store-metrics', isAllowedSessionHandler, validate( st
|
|
|
11
11
|
auditMetricsRouter.post( '/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
|
|
12
12
|
auditMetricsRouter.post( '/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
|
|
13
13
|
auditMetricsRouter.post( '/overview-card', isAllowedSessionHandler, validate( overViewCardValid ), overViewCard );
|
|
14
|
+
auditMetricsRouter.post( '/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
|
|
15
|
+
auditMetricsRouter.post( '/overview-table', isAllowedSessionHandler, validate( overViewTableValid ), overViewTable );
|
|
14
16
|
|
|
15
17
|
export default auditMetricsRouter;
|