tango-app-api-audit 1.0.46 → 1.0.48
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 +2 -2
- package/src/controllers/audit.controllers.js +98 -53
- package/src/controllers/auditMetrics.controllers.js +20 -22
- package/src/controllers/zoneAudit.controller.js +38 -41
- package/src/docs/audit.docs.js +6 -0
- package/src/dtos/audit.dtos.js +9 -0
- package/src/validation/zoneAudit.validation.js +2 -2
- package/src/service/assignZoneAudit.service.js +0 -12
- package/src/service/auditClientData.service.js +0 -6
- package/src/service/storeZoneAudit.service.js +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.48",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"mongodb": "^6.7.0",
|
|
25
25
|
"nodemon": "^3.1.3",
|
|
26
26
|
"swagger-ui-express": "^5.0.1",
|
|
27
|
-
"tango-api-schema": "^2.0.
|
|
27
|
+
"tango-api-schema": "^2.0.149",
|
|
28
28
|
"tango-app-api-middleware": "^3.1.28",
|
|
29
29
|
"winston": "^3.13.0",
|
|
30
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -34,7 +34,6 @@ import {
|
|
|
34
34
|
findOneStoreAudit,
|
|
35
35
|
updateOneStoreAudit,
|
|
36
36
|
} from '../service/storeAudit.service.js';
|
|
37
|
-
import { aggregateAuditClientData } from '../service/auditClientData.service.js';
|
|
38
37
|
import _ from 'lodash';
|
|
39
38
|
import {
|
|
40
39
|
createAuditLog,
|
|
@@ -69,6 +68,7 @@ export async function getAuditFile( req, res ) {
|
|
|
69
68
|
{ auditStatus: { $nin: [ 'completed', 'skipped' ] } },
|
|
70
69
|
{ createdAt: { $gte: start } },
|
|
71
70
|
{ createdAt: { $lte: end } },
|
|
71
|
+
{ moduleType: inputData.moduleType },
|
|
72
72
|
],
|
|
73
73
|
},
|
|
74
74
|
},
|
|
@@ -83,7 +83,6 @@ export async function getAuditFile( req, res ) {
|
|
|
83
83
|
const userDetails = await aggregateUserAudit( userQuery );
|
|
84
84
|
const auditStatus =
|
|
85
85
|
userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
86
|
-
|
|
87
86
|
switch ( auditStatus ) {
|
|
88
87
|
case null:
|
|
89
88
|
const query = [
|
|
@@ -93,6 +92,7 @@ export async function getAuditFile( req, res ) {
|
|
|
93
92
|
{ userId: { $eq: req.user._id } },
|
|
94
93
|
{ isCompleted: { $eq: false } },
|
|
95
94
|
{ queueName: inputData.queueName },
|
|
95
|
+
{ moduleType: inputData.moduleType },
|
|
96
96
|
],
|
|
97
97
|
},
|
|
98
98
|
},
|
|
@@ -105,12 +105,14 @@ export async function getAuditFile( req, res ) {
|
|
|
105
105
|
store_id: userAssign[0].storeId,
|
|
106
106
|
curr_date: userAssign[0].fileDate,
|
|
107
107
|
total_count: userAssign[0].fileCount,
|
|
108
|
+
zone_id: userAssign[0].zoneName,
|
|
108
109
|
} ) :
|
|
109
110
|
( msg = {
|
|
110
111
|
store_id: userAssign[0].storeId,
|
|
111
112
|
curr_date: userAssign[0].fileDate,
|
|
112
113
|
audit_type: userAssign[0].fileType,
|
|
113
114
|
total_count: userAssign[0].fileCount,
|
|
115
|
+
zone_id: userAssign[0].zoneName,
|
|
114
116
|
} );
|
|
115
117
|
await updateOneAssignAudit(
|
|
116
118
|
{ _id: userAssign[0]._id },
|
|
@@ -143,6 +145,8 @@ export async function getAuditFile( req, res ) {
|
|
|
143
145
|
fileDate: userDetails[0].fileDate,
|
|
144
146
|
storeId: userDetails[0].storeId,
|
|
145
147
|
totalCount: userDetails[0].beforeCount,
|
|
148
|
+
moduleType: userDetails[0].moduleType,
|
|
149
|
+
zoneName: userDetails[0].zoneName,
|
|
146
150
|
},
|
|
147
151
|
{},
|
|
148
152
|
{ createdAt: -1 },
|
|
@@ -166,6 +170,8 @@ export async function getAuditFile( req, res ) {
|
|
|
166
170
|
type: userDetails[0].auditType,
|
|
167
171
|
queueName: log.queueName,
|
|
168
172
|
userId: log.userId,
|
|
173
|
+
moduleType: userDetails[0].moduleType,
|
|
174
|
+
zoneName: userDetails[0].zoneName,
|
|
169
175
|
};
|
|
170
176
|
const result = {
|
|
171
177
|
junk: log.junk,
|
|
@@ -196,6 +202,8 @@ export async function getAuditFile( req, res ) {
|
|
|
196
202
|
storeId: userDetails[0].storeId,
|
|
197
203
|
clientName: log.queueName,
|
|
198
204
|
auditId: userDetails[0]._id,
|
|
205
|
+
moduleType: userDetails[0].moduleType,
|
|
206
|
+
zoneName: userDetails[0].zoneName,
|
|
199
207
|
},
|
|
200
208
|
};
|
|
201
209
|
logger.info( { logData: logData } );
|
|
@@ -227,6 +235,7 @@ export async function getAuditFile( req, res ) {
|
|
|
227
235
|
curr_date: userDetails[0].fileDate,
|
|
228
236
|
audit_type: userDetails[0].auditType,
|
|
229
237
|
total_count: userDetails[0].beforeCount,
|
|
238
|
+
zone_id: userDetails[0].zoneName,
|
|
230
239
|
};
|
|
231
240
|
break;
|
|
232
241
|
}
|
|
@@ -261,6 +270,8 @@ export async function getAuditFile( req, res ) {
|
|
|
261
270
|
fileDateISO: start,
|
|
262
271
|
timeSpent: 0,
|
|
263
272
|
startTime: new Date(),
|
|
273
|
+
zoneName: msg.zone_id,
|
|
274
|
+
moduleType: inputData.moduleType,
|
|
264
275
|
};
|
|
265
276
|
const storeRecord = {
|
|
266
277
|
userId: req.user._id,
|
|
@@ -273,6 +284,8 @@ export async function getAuditFile( req, res ) {
|
|
|
273
284
|
status: 'inprogress',
|
|
274
285
|
fileDateISO: start,
|
|
275
286
|
timeSpent: 0,
|
|
287
|
+
zoneName: msg.zone_id,
|
|
288
|
+
moduleType: inputData.moduleType,
|
|
276
289
|
};
|
|
277
290
|
reauditInsert = await createUserAudit( record );
|
|
278
291
|
await createStoreAudit( storeRecord );
|
|
@@ -292,6 +305,8 @@ export async function getAuditFile( req, res ) {
|
|
|
292
305
|
storeId: msg.store_id,
|
|
293
306
|
clientName: inputData.queueName,
|
|
294
307
|
auditId: reauditInsert._id,
|
|
308
|
+
zoneName: msg.zone_id,
|
|
309
|
+
moduleType: inputData.moduleType,
|
|
295
310
|
},
|
|
296
311
|
};
|
|
297
312
|
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
@@ -319,16 +334,19 @@ export async function getAuditFile( req, res ) {
|
|
|
319
334
|
queueName: inputData.queueName,
|
|
320
335
|
auditId: reauditInsert._id,
|
|
321
336
|
userId: reauditInsert.userId,
|
|
337
|
+
zoneName: msg.zone_id,
|
|
338
|
+
moduleType: inputData.moduleType,
|
|
322
339
|
},
|
|
323
340
|
isDraft: reauditInsert.isDraft,
|
|
324
341
|
} );
|
|
325
342
|
}
|
|
326
343
|
const storeId = msg.store_id;
|
|
327
344
|
const fileDate = msg.curr_date;
|
|
345
|
+
|
|
328
346
|
const files = [];
|
|
329
347
|
let insertData = {};
|
|
330
348
|
fetchData.Bucket = bucket.auditInput; // need to change
|
|
331
|
-
fetchData.file_path = `${fileDate}/${storeId}/`;
|
|
349
|
+
fetchData.file_path = `${fileDate}/${storeId}/${msg.zone_id}/`;
|
|
332
350
|
if ( inputData.limit ) {
|
|
333
351
|
fetchData.MaxKeys = inputData.limit;
|
|
334
352
|
}
|
|
@@ -342,7 +360,7 @@ export async function getAuditFile( req, res ) {
|
|
|
342
360
|
if ( folderPath?.length > 0 ) {
|
|
343
361
|
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
344
362
|
const img = folderPath[i].Key.split( '/' );
|
|
345
|
-
const image = img[
|
|
363
|
+
const image = img[3].split( '.' );
|
|
346
364
|
const indexes = image[0].split( '_' );
|
|
347
365
|
fetchData.file_path = folderPath[i].Key;
|
|
348
366
|
const data = await signedUrl( fetchData );
|
|
@@ -382,6 +400,8 @@ export async function getAuditFile( req, res ) {
|
|
|
382
400
|
fileDateISO: start,
|
|
383
401
|
timeSpent: 0,
|
|
384
402
|
startTime: new Date(),
|
|
403
|
+
zoneName: msg.zone_id,
|
|
404
|
+
moduleType: inputData.moduleType,
|
|
385
405
|
};
|
|
386
406
|
const storeRecord = {
|
|
387
407
|
userId: req.user._id,
|
|
@@ -394,10 +414,12 @@ export async function getAuditFile( req, res ) {
|
|
|
394
414
|
status: 'inprogress',
|
|
395
415
|
fileDateISO: start,
|
|
396
416
|
timeSpent: 0,
|
|
417
|
+
zoneName: msg.zone_id,
|
|
418
|
+
moduleType: inputData.moduleType,
|
|
397
419
|
};
|
|
398
420
|
|
|
399
421
|
insertData = await createUserAudit( record );
|
|
400
|
-
await
|
|
422
|
+
await createStoreAudit( storeRecord );
|
|
401
423
|
} else {
|
|
402
424
|
insertData = userDetails[0];
|
|
403
425
|
}
|
|
@@ -430,6 +452,8 @@ export async function getAuditFile( req, res ) {
|
|
|
430
452
|
storeId: storeId,
|
|
431
453
|
clientName: inputData.queueName,
|
|
432
454
|
auditId: insertData._id,
|
|
455
|
+
zoneName: msg.zone_id,
|
|
456
|
+
moduleType: inputData.moduleType,
|
|
433
457
|
},
|
|
434
458
|
};
|
|
435
459
|
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
@@ -448,6 +472,8 @@ export async function getAuditFile( req, res ) {
|
|
|
448
472
|
type: 'Audit',
|
|
449
473
|
auditId: insertData._id,
|
|
450
474
|
userId: insertData.userId,
|
|
475
|
+
zoneName: msg.zone_id,
|
|
476
|
+
moduleType: inputData.moduleType,
|
|
451
477
|
nextToken: nextQuery ? encodeURIComponent( nextQuery ) : null,
|
|
452
478
|
},
|
|
453
479
|
isDraft: insertData.isDraft,
|
|
@@ -467,7 +493,7 @@ export async function getFilterData( msg ) {
|
|
|
467
493
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
468
494
|
const params = {
|
|
469
495
|
Bucket: `${bucket.auditOutput}`,
|
|
470
|
-
Key: `${msg.store_id}/${msg.curr_date}/${bucketName.masterJsonFile}`,
|
|
496
|
+
Key: `${msg.store_id}/${msg.zone_id}/${msg.curr_date}/${bucketName.masterJsonFile}`,
|
|
471
497
|
};
|
|
472
498
|
const mappingFile = await getJsonFileData( params );
|
|
473
499
|
if ( mappingFile.statusCode ) {
|
|
@@ -503,7 +529,7 @@ export async function getAuditImage( msg ) {
|
|
|
503
529
|
const files = [];
|
|
504
530
|
const fetchData = {};
|
|
505
531
|
fetchData.Bucket = `${bucket.auditInput}`;
|
|
506
|
-
fetchData.filePath = `${fileDate}/${storeId}
|
|
532
|
+
fetchData.filePath = `${fileDate}/${storeId}/${msg.zone_id}`;
|
|
507
533
|
const folderPath = await listFileWithoutLimit( fetchData );
|
|
508
534
|
if ( folderPath.statusCode == 404 ) {
|
|
509
535
|
return folderPath;
|
|
@@ -512,7 +538,7 @@ export async function getAuditImage( msg ) {
|
|
|
512
538
|
if ( auditImages && auditImages?.length > 0 ) {
|
|
513
539
|
for ( let i = 0; i < auditImages.length; i++ ) {
|
|
514
540
|
const img = auditImages[i].Key.split( '/' );
|
|
515
|
-
const image = img[
|
|
541
|
+
const image = img[3].split( '.' );
|
|
516
542
|
const indexes = image[0].split( '_' );
|
|
517
543
|
const params = {
|
|
518
544
|
file_path: auditImages[i].Key,
|
|
@@ -537,7 +563,7 @@ export async function getAuditImage( msg ) {
|
|
|
537
563
|
return files;
|
|
538
564
|
}
|
|
539
565
|
} catch ( error ) {
|
|
540
|
-
logger.error( { error: error, type: '
|
|
566
|
+
logger.error( { error: error, type: 'AWS BUCKET --getAuditImage' } );
|
|
541
567
|
return error;
|
|
542
568
|
}
|
|
543
569
|
}
|
|
@@ -612,30 +638,30 @@ export async function workSpace( req, res ) {
|
|
|
612
638
|
|
|
613
639
|
const clientDetails = await aggregateClient( clientQuery );
|
|
614
640
|
const clientList = clientDetails.map( ( i ) => i.clientId );
|
|
615
|
-
const query = [
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
];
|
|
641
|
+
// const query = [
|
|
642
|
+
// {
|
|
643
|
+
// $match: {
|
|
644
|
+
// clientId: { $in: clientList },
|
|
645
|
+
// },
|
|
646
|
+
// },
|
|
647
|
+
// {
|
|
648
|
+
// $group: {
|
|
649
|
+
// _id: '$clientId',
|
|
650
|
+
// clientId: { $last: '$clientId' },
|
|
651
|
+
// totalFilesCount: { $last: '$totalFilesCount' },
|
|
652
|
+
// clientName: { $last: '$clientName' },
|
|
653
|
+
// queueName: { $last: '$queueName' },
|
|
654
|
+
// },
|
|
655
|
+
// },
|
|
656
|
+
// {
|
|
657
|
+
// $project: {
|
|
658
|
+
// clientId: 1,
|
|
659
|
+
// totalFilesCount: 1,
|
|
660
|
+
// clientName: 1,
|
|
661
|
+
// queueName: 1,
|
|
662
|
+
// },
|
|
663
|
+
// },
|
|
664
|
+
// ];
|
|
639
665
|
|
|
640
666
|
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
641
667
|
|
|
@@ -799,7 +825,7 @@ export async function workSpace( req, res ) {
|
|
|
799
825
|
},
|
|
800
826
|
];
|
|
801
827
|
|
|
802
|
-
const auditDetails = await aggregateAuditClientData( query );
|
|
828
|
+
const auditDetails = [];// await aggregateAuditClientData( query );
|
|
803
829
|
const auditCount = await aggregateUserAudit( auditFiles );
|
|
804
830
|
const draftedCount = await aggregateUserAudit( draftedFiles );
|
|
805
831
|
const CompletedCount = await aggregateStoreAudit( completedFiles );
|
|
@@ -956,6 +982,8 @@ export async function saveDraft( req, res ) {
|
|
|
956
982
|
beforeCount: inputData.totalCount,
|
|
957
983
|
afterCount: inputData.customerCount,
|
|
958
984
|
auditId: inputData.auditId,
|
|
985
|
+
moduleType: inputData.moduleType,
|
|
986
|
+
zoneName: inputData.zoneName,
|
|
959
987
|
},
|
|
960
988
|
};
|
|
961
989
|
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
@@ -981,6 +1009,8 @@ export async function getDraftedData( req, res ) {
|
|
|
981
1009
|
fileDate: inputData.fileDate,
|
|
982
1010
|
storeId: inputData.storeId,
|
|
983
1011
|
userId: userId,
|
|
1012
|
+
moduleType: inputData.moduleType,
|
|
1013
|
+
zoneName: inputData.zoneName,
|
|
984
1014
|
};
|
|
985
1015
|
const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
|
|
986
1016
|
|
|
@@ -1006,7 +1036,7 @@ export async function save( req, res ) {
|
|
|
1006
1036
|
|
|
1007
1037
|
const inputData = req.body;
|
|
1008
1038
|
const params = {
|
|
1009
|
-
Key: `${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1039
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1010
1040
|
};
|
|
1011
1041
|
|
|
1012
1042
|
if ( inputData.auditType === 'ReAudit' ) {
|
|
@@ -1044,7 +1074,7 @@ export async function save( req, res ) {
|
|
|
1044
1074
|
|
|
1045
1075
|
const uploadDataParams = {
|
|
1046
1076
|
Bucket: bucket.auditUploadBucket,
|
|
1047
|
-
Key: `${inputData.storeId}/${inputData.fileDate}/`,
|
|
1077
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/`,
|
|
1048
1078
|
ContentType: 'application/json',
|
|
1049
1079
|
fileName: `${bucket.masterJsonFile}`,
|
|
1050
1080
|
body: JSON.stringify( tempObject ),
|
|
@@ -1053,7 +1083,7 @@ export async function save( req, res ) {
|
|
|
1053
1083
|
|
|
1054
1084
|
if ( mappingUpload?.statusCode ) {
|
|
1055
1085
|
logger.error( {
|
|
1056
|
-
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1086
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1057
1087
|
type: 'UPLOAD_ERROR',
|
|
1058
1088
|
} );
|
|
1059
1089
|
return res.sendError( mappingUpload, 500 );
|
|
@@ -1061,6 +1091,8 @@ export async function save( req, res ) {
|
|
|
1061
1091
|
|
|
1062
1092
|
let getUserAuditData = await findOneUserAudit( {
|
|
1063
1093
|
_id: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1094
|
+
moduleType: inputData.moduleType,
|
|
1095
|
+
zoneName: inputData.zoneName,
|
|
1064
1096
|
} );
|
|
1065
1097
|
const isoDate = getUserAuditData.startTime;
|
|
1066
1098
|
const currentTime = dayjs();
|
|
@@ -1097,6 +1129,9 @@ export async function save( req, res ) {
|
|
|
1097
1129
|
let storeAuditData = await findOneStoreAudit( {
|
|
1098
1130
|
storeId: inputData.storeId,
|
|
1099
1131
|
fileDate: inputData.fileDate,
|
|
1132
|
+
moduleType: inputData.moduleType,
|
|
1133
|
+
zoneName: inputData.zoneName,
|
|
1134
|
+
auditType: inputData.auditType,
|
|
1100
1135
|
} );
|
|
1101
1136
|
|
|
1102
1137
|
let clientData = await findClient( { clientId: storeConfig.clientId } );
|
|
@@ -1105,7 +1140,7 @@ export async function save( req, res ) {
|
|
|
1105
1140
|
( storeAuditData.beforeCount - inputData.customerCount ) /
|
|
1106
1141
|
storeAuditData.beforeCount <
|
|
1107
1142
|
storeConfig.auditConfigs.ratio
|
|
1108
|
-
) && inputData.auditType == 'Audit' ) {
|
|
1143
|
+
) && inputData.auditType == 'Audit' && inputData.moduleType=='traffic' ) {
|
|
1109
1144
|
logger.info(
|
|
1110
1145
|
`Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
|
|
1111
1146
|
'Reaudit',
|
|
@@ -1122,31 +1157,39 @@ export async function save( req, res ) {
|
|
|
1122
1157
|
} ),
|
|
1123
1158
|
};
|
|
1124
1159
|
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
1125
|
-
logger.info( { sqsQueue: sqsQueue } );
|
|
1126
1160
|
|
|
1127
1161
|
if ( sqsQueue.statusCode ) {
|
|
1128
1162
|
logger.error( {
|
|
1129
|
-
error:
|
|
1163
|
+
error: `${sqsQueue}`,
|
|
1130
1164
|
type: 'UPLOAD_ERROR',
|
|
1131
1165
|
} );
|
|
1132
1166
|
return res.sendError( mappingUpload, 500 );
|
|
1133
1167
|
}
|
|
1134
1168
|
|
|
1135
|
-
await updateOneStoreAudit( { storeId: inputData.storeId
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1169
|
+
await updateOneStoreAudit( { storeId: inputData.storeId,
|
|
1170
|
+
fileDate: inputData.fileDate,
|
|
1171
|
+
moduleType: inputData.moduleType,
|
|
1172
|
+
zoneName: inputData.zoneName,
|
|
1173
|
+
auditType: inputData.auditType },
|
|
1174
|
+
{
|
|
1175
|
+
status: 'not_assign',
|
|
1176
|
+
afterCount: inputData.customerCount,
|
|
1177
|
+
auditType: 'ReAudit',
|
|
1178
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1179
|
+
} );
|
|
1142
1180
|
} else {
|
|
1143
1181
|
logger.info( 'Hit in Features', { data: ( _.omit( inputData, [ 'junk', 'employee', 'customer' ] ) ) } );
|
|
1144
|
-
await updateOneStoreAudit( { storeId: inputData.storeId
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1182
|
+
await updateOneStoreAudit( { storeId: inputData.storeId,
|
|
1183
|
+
fileDate: inputData.fileDate,
|
|
1184
|
+
moduleType: inputData.moduleType,
|
|
1185
|
+
zoneName: inputData.zoneName,
|
|
1186
|
+
auditType: inputData.auditType,
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
status: 'completed',
|
|
1190
|
+
afterCount: inputData.customerCount,
|
|
1191
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1192
|
+
} );
|
|
1150
1193
|
|
|
1151
1194
|
const sqsProduceQueue = {
|
|
1152
1195
|
QueueUrl: `${sqs.url}${sqs.feature}`,
|
|
@@ -1155,6 +1198,8 @@ export async function save( req, res ) {
|
|
|
1155
1198
|
store_id: inputData.storeId,
|
|
1156
1199
|
store_date: inputData.fileDate,
|
|
1157
1200
|
bucket_name: `${bucket.auditUploadBucket}`,
|
|
1201
|
+
zone_id: inputData.zoneName,
|
|
1202
|
+
process_type: 'audit',
|
|
1158
1203
|
} ),
|
|
1159
1204
|
};
|
|
1160
1205
|
logger.info( { sqsProduceQueue: sqsProduceQueue } );
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { chunkArray, download, getUTC, insertOpenSearchData, logger, sendMessageToQueue } from 'tango-app-api-middleware';
|
|
2
|
-
import { aggregateAuditClientData } from '../service/auditClientData.service.js';
|
|
3
2
|
import { aggregateUserAudit, updateOneUserAudit } from '../service/userAudit.service.js';
|
|
4
3
|
import mongoose from 'mongoose';
|
|
5
4
|
import { aggregateStoreAudit, updateOneStoreAudit } from '../service/storeAudit.service.js';
|
|
@@ -10,7 +9,6 @@ import { countDocumentsStore } from '../service/store.service.js';
|
|
|
10
9
|
import { findOneClient } from '../service/client.service.js';
|
|
11
10
|
import { getAuditFilterData, getAuditImageData, zipDownloadImage } from '../validation/audit.validation.js';
|
|
12
11
|
import { getReauditImg } from './audit.controllers.js';
|
|
13
|
-
import { aggregateStoreZoneAudit } from '../service/storeZoneAudit.service.js';
|
|
14
12
|
// import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
15
13
|
|
|
16
14
|
export async function userAuditHistory( req, res ) {
|
|
@@ -663,8 +661,8 @@ export async function clientMetrics( req, res ) {
|
|
|
663
661
|
},
|
|
664
662
|
);
|
|
665
663
|
}
|
|
666
|
-
|
|
667
|
-
const count = await aggregateAuditClientData( query );
|
|
664
|
+
logger.info( { query: query } );
|
|
665
|
+
const count = [];// await aggregateAuditClientData( query );
|
|
668
666
|
if ( count.length == 0 ) {
|
|
669
667
|
return res.sendError( 'No Data Found', 204 );
|
|
670
668
|
}
|
|
@@ -694,8 +692,8 @@ export async function clientMetrics( req, res ) {
|
|
|
694
692
|
);
|
|
695
693
|
}
|
|
696
694
|
|
|
697
|
-
|
|
698
|
-
const result = await aggregateAuditClientData( query );
|
|
695
|
+
logger.info( { query: query } );
|
|
696
|
+
const result = [];// await aggregateAuditClientData( query );
|
|
699
697
|
if ( inputData.isExport ) {
|
|
700
698
|
await download( result, res );
|
|
701
699
|
return;
|
|
@@ -1339,21 +1337,21 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
1339
1337
|
}
|
|
1340
1338
|
const storeQuery = inputData.clientId.length? { 'edge.firstFile': true, 'clientId': { $in: inputData. clientId } } : { 'edge.firstFile': true };
|
|
1341
1339
|
temp.installedStores = await countDocumentsStore( storeQuery );
|
|
1342
|
-
const auditClientDataQuery =[
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
];
|
|
1356
|
-
const auditClientData = await aggregateAuditClientData( auditClientDataQuery );
|
|
1340
|
+
// const auditClientDataQuery =[
|
|
1341
|
+
// {
|
|
1342
|
+
// $match: {
|
|
1343
|
+
// $and: filters,
|
|
1344
|
+
// },
|
|
1345
|
+
|
|
1346
|
+
// },
|
|
1347
|
+
// {
|
|
1348
|
+
// $group: {
|
|
1349
|
+
// _id: null,
|
|
1350
|
+
// totalFilesCount: { $sum: '$totalFilesCount' },
|
|
1351
|
+
// },
|
|
1352
|
+
// },
|
|
1353
|
+
// ];
|
|
1354
|
+
const auditClientData = [];// await aggregateAuditClientData( auditClientDataQuery );
|
|
1357
1355
|
if ( auditClientData.length >0 ) {
|
|
1358
1356
|
temp.auditStores = auditClientData[0].totalFilesCount;
|
|
1359
1357
|
}
|
|
@@ -1405,7 +1403,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
1405
1403
|
},
|
|
1406
1404
|
},
|
|
1407
1405
|
];
|
|
1408
|
-
const storeAudit =
|
|
1406
|
+
const storeAudit = await aggregateStoreAudit( storeAuditQuery );
|
|
1409
1407
|
if ( storeAudit.length > 0 ) {
|
|
1410
1408
|
temp.inprogreseStores= storeAudit[0].inprogreseStores;
|
|
1411
1409
|
temp.completedStores = storeAudit[0].completedStores;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { download, fileUpload, getJsonFileData, getUTC, insertOpenSearchData, listFileByPath, listFileWithoutLimit, sendMessageToQueue, signedUrl, sqsReceive } from 'tango-app-api-middleware';
|
|
2
2
|
import { aggregateZoneUserAudit, createZoneUserAudit, findOneZoneUserAudit, updateOneZoneUserAudit } from '../service/zoneUserAudit.service.js';
|
|
3
3
|
import { logger } from 'tango-app-api-middleware';
|
|
4
|
-
import { aggregateAssignZoneAudit } from '../service/assignZoneAudit.service.js';
|
|
5
|
-
import { aggregateStoreZoneAudit, createStoreZoneAudit, findOneStoreZoneAudit, updateOneStoreZoneAudit } from '../service/storeZoneAudit.service.js';
|
|
6
4
|
import { findOneUser } from '../service/user.service.js';
|
|
7
5
|
import { findOneStore } from '../service/store.service.js';
|
|
8
6
|
import dayjs from 'dayjs';
|
|
@@ -11,7 +9,6 @@ import { aggregateAssignAudit, createAssignAudit } from '../service/assignAudit.
|
|
|
11
9
|
import { createAuditLog, findOneAuditLog } from '../service/auditLog.service.js';
|
|
12
10
|
import { mapCustomer, mapEmployee, mapJunk, splitB20000, splitE0, splitG20000, zipDownloadImage } from '../validation/audit.validation.js';
|
|
13
11
|
import { aggregateClient, findClient, findOneClient } from '../service/client.service.js';
|
|
14
|
-
import { aggregateAuditClientData } from '../service/auditClientData.service.js';
|
|
15
12
|
import _ from 'lodash';
|
|
16
13
|
import mongoose from 'mongoose';
|
|
17
14
|
import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
@@ -73,7 +70,7 @@ export async function getZoneAuditFile( req, res ) {
|
|
|
73
70
|
},
|
|
74
71
|
];
|
|
75
72
|
|
|
76
|
-
const userAssign = await
|
|
73
|
+
const userAssign = await aggregateAssignAudit( query );
|
|
77
74
|
if ( userAssign.length > 0 ) {
|
|
78
75
|
logger.info( 'Hit in user assign', { inputData } );
|
|
79
76
|
} else {
|
|
@@ -776,38 +773,38 @@ export async function workSpace( req, res ) {
|
|
|
776
773
|
|
|
777
774
|
const clientDetails = await aggregateClient( clientQuery );
|
|
778
775
|
const clientList = clientDetails.map( ( i ) => i.clientId );
|
|
779
|
-
const query = [
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
];
|
|
776
|
+
// const query = [
|
|
777
|
+
// {
|
|
778
|
+
// $match: {
|
|
779
|
+
// $and: [
|
|
780
|
+
// {
|
|
781
|
+
// clientId: { $in: clientList },
|
|
782
|
+
// },
|
|
783
|
+
// {
|
|
784
|
+
// moduleType: 'zone',
|
|
785
|
+
// },
|
|
786
|
+
// ],
|
|
787
|
+
|
|
788
|
+
// },
|
|
789
|
+
// },
|
|
790
|
+
// {
|
|
791
|
+
// $group: {
|
|
792
|
+
// _id: '$clientId',
|
|
793
|
+
// clientId: { $last: '$clientId' },
|
|
794
|
+
// totalFilesCount: { $last: '$totalFilesCount' },
|
|
795
|
+
// clientName: { $last: '$clientName' },
|
|
796
|
+
// queueName: { $last: '$queueName' },
|
|
797
|
+
// },
|
|
798
|
+
// },
|
|
799
|
+
// {
|
|
800
|
+
// $project: {
|
|
801
|
+
// clientId: 1,
|
|
802
|
+
// totalFilesCount: 1,
|
|
803
|
+
// clientName: 1,
|
|
804
|
+
// queueName: 1,
|
|
805
|
+
// },
|
|
806
|
+
// },
|
|
807
|
+
// ];
|
|
811
808
|
|
|
812
809
|
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
813
810
|
|
|
@@ -977,7 +974,7 @@ export async function workSpace( req, res ) {
|
|
|
977
974
|
},
|
|
978
975
|
];
|
|
979
976
|
|
|
980
|
-
const auditDetails = await aggregateAuditClientData( query );
|
|
977
|
+
const auditDetails = [];// await aggregateAuditClientData( query );
|
|
981
978
|
const auditCount = await aggregateUserAudit( auditFiles );
|
|
982
979
|
const draftedCount = await aggregateUserAudit( draftedFiles );
|
|
983
980
|
const CompletedCount = await aggregateStoreZoneAudit( completedFiles );
|
|
@@ -1626,8 +1623,8 @@ export async function clientMetrics( req, res ) {
|
|
|
1626
1623
|
},
|
|
1627
1624
|
);
|
|
1628
1625
|
}
|
|
1629
|
-
|
|
1630
|
-
const count = await aggregateAuditClientData( query );
|
|
1626
|
+
logger.info( { query: query } );
|
|
1627
|
+
const count = [];// await aggregateAuditClientData( query );
|
|
1631
1628
|
if ( count.length == 0 ) {
|
|
1632
1629
|
return res.sendError( 'No Data Found', 204 );
|
|
1633
1630
|
}
|
|
@@ -1657,8 +1654,8 @@ export async function clientMetrics( req, res ) {
|
|
|
1657
1654
|
);
|
|
1658
1655
|
}
|
|
1659
1656
|
|
|
1660
|
-
|
|
1661
|
-
const result = await aggregateAuditClientData( query );
|
|
1657
|
+
logger.info( { query: query } );
|
|
1658
|
+
const result = [];// await aggregateAuditClientData( query );
|
|
1662
1659
|
if ( inputData.isExport ) {
|
|
1663
1660
|
await download( result, res );
|
|
1664
1661
|
return;
|
package/src/docs/audit.docs.js
CHANGED
|
@@ -26,6 +26,12 @@ export const auditDocs = {
|
|
|
26
26
|
scema: j2s( getFileSchema ).swagger,
|
|
27
27
|
require: false,
|
|
28
28
|
},
|
|
29
|
+
{
|
|
30
|
+
in: 'query',
|
|
31
|
+
name: 'moduleType',
|
|
32
|
+
scema: j2s( getFileSchema ).swagger,
|
|
33
|
+
require: true,
|
|
34
|
+
},
|
|
29
35
|
],
|
|
30
36
|
responses: {
|
|
31
37
|
200: { description: 'Successful' },
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -6,6 +6,7 @@ export const getFileSchema = joi.object(
|
|
|
6
6
|
queueName: joi.string().required(),
|
|
7
7
|
nextId: joi.string().optional().allow( '' ),
|
|
8
8
|
limit: joi.number().optional(),
|
|
9
|
+
moduleType: joi.string().required(),
|
|
9
10
|
},
|
|
10
11
|
);
|
|
11
12
|
|
|
@@ -18,6 +19,8 @@ export const saveDraftSchema = joi.object(
|
|
|
18
19
|
userCommands: joi.string().optional().allow( '' ),
|
|
19
20
|
storeId: joi.string().required(),
|
|
20
21
|
auditId: joi.string().required(),
|
|
22
|
+
moduleType: joi.string().required(),
|
|
23
|
+
zoneName: joi.string().required(),
|
|
21
24
|
auditType: joi.string().required(),
|
|
22
25
|
fileDate: joi.string().required(),
|
|
23
26
|
queueName: joi.string().required(),
|
|
@@ -42,6 +45,8 @@ export const getDraftedDataSchema = joi.object(
|
|
|
42
45
|
storeId: joi.string().required(),
|
|
43
46
|
fileDate: joi.string().required(),
|
|
44
47
|
userId: joi.string().optional(),
|
|
48
|
+
moduleType: joi.string().required(),
|
|
49
|
+
zoneName: joi.string().required(),
|
|
45
50
|
},
|
|
46
51
|
);
|
|
47
52
|
|
|
@@ -55,6 +60,8 @@ export const saveSchema = joi.object(
|
|
|
55
60
|
storeId: joi.string().required(),
|
|
56
61
|
fileDate: joi.string().required(),
|
|
57
62
|
auditType: joi.string().required(),
|
|
63
|
+
moduleType: joi.string().required(),
|
|
64
|
+
zoneName: joi.string().required(),
|
|
58
65
|
beforeCount: joi.number().required(),
|
|
59
66
|
junkCount: joi.number().required(),
|
|
60
67
|
junk: joi.array().required(),
|
|
@@ -62,6 +69,8 @@ export const saveSchema = joi.object(
|
|
|
62
69
|
employee: joi.array().required(),
|
|
63
70
|
customerCount: joi.number().required(),
|
|
64
71
|
customer: joi.array().required(),
|
|
72
|
+
moduleType: joi.string().required(),
|
|
73
|
+
zoneName: joi.string().required(),
|
|
65
74
|
},
|
|
66
75
|
);
|
|
67
76
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkFileExist, getJsonFileData, listFileWithoutLimit, signedUrl } from 'tango-app-api-middleware';
|
|
2
|
-
import {
|
|
2
|
+
import { findOneStoreAudit } from '../service/storeAudit.service.js';
|
|
3
3
|
|
|
4
4
|
export async function isAuditDocumentExist( req, res, next ) {
|
|
5
5
|
try {
|
|
@@ -9,7 +9,7 @@ export async function isAuditDocumentExist( req, res, next ) {
|
|
|
9
9
|
fileDate: inputData.fileDate,
|
|
10
10
|
zoneName: inputData.zoneName,
|
|
11
11
|
};
|
|
12
|
-
const auditInfo = await
|
|
12
|
+
const auditInfo = await findOneStoreAudit( query );
|
|
13
13
|
if ( auditInfo ) {
|
|
14
14
|
req.audit = auditInfo;
|
|
15
15
|
return next();
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import assignZoneAuditModel from 'tango-api-schema/schema/assignZoneAudit.model.js';
|
|
2
|
-
|
|
3
|
-
export function aggregateAssignZoneAudit( query ) {
|
|
4
|
-
return assignZoneAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
5
|
-
}
|
|
6
|
-
export function updateOneAssignZoneAudit( query, record ) {
|
|
7
|
-
return assignZoneAuditModel.updateOne( query, { $set: record } );
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function createAssignZoneAudit( query ) {
|
|
11
|
-
return assignZoneAuditModel.create( query );
|
|
12
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import storeZoneAuditModel from 'tango-api-schema/schema/storeZoneAudit.model.js';
|
|
2
|
-
|
|
3
|
-
export function updateOneStoreZoneAudit( query, record ) {
|
|
4
|
-
return storeZoneAuditModel.updateOne( query, { $set: record } );
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function createStoreZoneAudit( record ) {
|
|
8
|
-
return storeZoneAuditModel.create( record );
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function aggregateStoreZoneAudit( query ) {
|
|
12
|
-
return storeZoneAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function findOneStoreZoneAudit( query, fields ) {
|
|
16
|
-
return storeZoneAuditModel.findOne( query, fields );
|
|
17
|
-
}
|