tango-app-api-audit 1.0.41 → 1.0.43

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -10,12 +10,13 @@ import { countDocumentsStore } from '../service/store.service.js';
10
10
  import { findOneClient } from '../service/client.service.js';
11
11
  import { getAuditFilterData, getAuditImageData, zipDownloadImage } from '../validation/audit.validation.js';
12
12
  import { getReauditImg } from './audit.controllers.js';
13
+ import { aggregateStoreZoneAudit } from '../service/storeZoneAudit.service.js';
13
14
  // import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
14
15
 
15
16
  export async function userAuditHistory( req, res ) {
16
17
  try {
17
18
  const inputData = req.body;
18
- const userId = inputData.userId || req.user._id;
19
+ const userId = inputData.userId? new mongoose.Types.ObjectId( inputData.userId ) : req.user._id;
19
20
  const limit = inputData.limit || 10;
20
21
  const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
21
22
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
@@ -63,14 +64,6 @@ export async function userAuditHistory( req, res ) {
63
64
  ];
64
65
 
65
66
 
66
- if ( inputData.sortColumnName ) {
67
- const sortBy = inputData.sortBy || -1;
68
- query.push( {
69
- $sort: { [inputData.sortColumName]: sortBy },
70
- },
71
- );
72
- }
73
-
74
67
  query.push( {
75
68
  $lookup: {
76
69
  from: 'stores',
@@ -93,17 +86,50 @@ export async function userAuditHistory( req, res ) {
93
86
 
94
87
  } );
95
88
 
89
+
96
90
  query.push( {
97
91
  $unwind: {
98
92
  path: '$store', preserveNullAndEmptyArrays: true,
99
93
  },
100
94
  } );
101
95
 
96
+ query.push( {
97
+ $lookup: {
98
+ from: 'clients',
99
+ let: { clientId: '$clientId' },
100
+ pipeline: [
101
+ {
102
+ $match: {
103
+ $expr: {
104
+ $eq: [ '$clientId', '$$clientId' ],
105
+ },
106
+ },
107
+ },
108
+ {
109
+ $project: {
110
+ clientName: 1,
111
+ },
112
+ },
113
+ ], as: 'client',
114
+ },
115
+
116
+ } );
117
+
118
+
119
+ query.push( {
120
+ $unwind: {
121
+ path: '$client', preserveNullAndEmptyArrays: true,
122
+ },
123
+ } );
124
+
102
125
  query.push( {
103
126
  $project: {
104
127
  storeId: 1,
105
128
  userId: 1,
106
129
  storeName: '$store.storeName',
130
+ clientId: 1,
131
+ clientName: 'client.clientName',
132
+ fileDate: 1,
107
133
  auditType: 1,
108
134
  zoneName: 1,
109
135
  moduleType: 1,
@@ -112,14 +138,51 @@ export async function userAuditHistory( req, res ) {
112
138
  accuracy: { $round: [
113
139
  {
114
140
  $divide: [ { $multiply: [ '$beforeCount', { $ifNull: [ '$afterCount', 0 ] } ] }, 100 ],
115
- }, 2,
141
+ }, 1,
116
142
  ],
117
143
  },
118
- startTime: 1,
119
- endTime: 1,
120
- timeSpent: { $round: [
121
- { $divide: [ '$timeSpent', 60 ] }, 2,
122
- ] },
144
+ startTime: {
145
+ $dateToString: {
146
+ format: '%Y-%m-%d %H:%M:%S',
147
+ date: '$startTime',
148
+ timezone: 'Asia/Kolkata',
149
+ },
150
+ },
151
+ endTime: {
152
+ $dateToString: {
153
+ format: '%Y-%m-%d %H:%M:%S',
154
+ date: '$endTime',
155
+ timezone: 'Asia/Kolkata',
156
+ },
157
+ },
158
+ // timeSpent: { $round: [
159
+ // { $divide: [ '$timeSpent', 60 ] }, 2,
160
+ // ] },
161
+ timeSpent: {
162
+
163
+ $cond: [
164
+ { $lt: [ '$timeSpent', 60 ] }, // Case 1: If less than 60 seconds
165
+ { $concat: [ { $toString: '$timeSpent' }, ' sec' ] },
166
+ {
167
+ $cond: [
168
+ { $lt: [ '$timeSpent', 3600 ] }, // Case 2: If less than 60 minutes (3600 seconds)
169
+ {
170
+ $concat: [
171
+ { $toString: { $round: [ { $divide: [ '$timeSpent', 60 ] }, 1 ] } }, // Convert to minutes
172
+ ' min',
173
+ ],
174
+ },
175
+ {
176
+ $concat: [
177
+ { $toString: { $round: [ { $divide: [ '$timeSpent', 3600 ] }, 1 ] } }, // Convert to hours
178
+ ' hr',
179
+ ],
180
+ },
181
+ ],
182
+ },
183
+ ],
184
+
185
+ },
123
186
  auditStatus: 1,
124
187
  createdAt: 1,
125
188
  },
@@ -129,17 +192,26 @@ export async function userAuditHistory( req, res ) {
129
192
  query.push( {
130
193
  $match: {
131
194
  $or: [
195
+ { clientName: { $regex: inputData.searchValue, $options: 'i' } },
196
+ { clientType: { $regex: inputData.searchValue, $options: 'i' } },
132
197
  { zoneName: { $regex: inputData.searchValue, $options: 'i' } },
133
- { storeId: { $regex: inputData.storeId, $options: 'i' } },
134
- { storeName: { $regex: inputData.storeName, $options: 'i' } },
135
- { moduleType: { $regex: inputData.moduleType, $options: 'i' } },
136
- { auditStatus: { $regex: inputData.auditStatus, $options: 'i' } },
198
+ { storeId: { $regex: inputData.searchValue, $options: 'i' } },
199
+ { storeName: { $regex: inputData.searchValue, $options: 'i' } },
200
+ { moduleType: { $regex: inputData.searchValue, $options: 'i' } },
201
+ { auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
137
202
  ],
138
203
 
139
204
  },
140
205
  } );
141
206
  }
142
207
 
208
+ if ( inputData.sortColumnName ) {
209
+ const sortBy = inputData.sortBy || -1;
210
+ query.push( {
211
+ $sort: { [inputData.sortColumName]: sortBy },
212
+ },
213
+ );
214
+ }
143
215
  const count = await aggregateUserAudit( query );
144
216
  if ( count.length == 0 ) {
145
217
  return res.sendError( 'No Data Found', 204 );
@@ -151,6 +223,8 @@ export async function userAuditHistory( req, res ) {
151
223
  const exportData = [];
152
224
  chunk.forEach( ( element ) => {
153
225
  exportData.push( {
226
+ 'Client Id': element.clientId,
227
+ 'Client Name': element.clientName,
154
228
  'Store Id': element.storeId,
155
229
  'Store Name': element.storeName,
156
230
  'Type': element.auditType,
@@ -163,7 +237,7 @@ export async function userAuditHistory( req, res ) {
163
237
  'End Time': element.endTime,
164
238
  'Time Spent': element.timeSpent,
165
239
  'Audit Status': element.auditStatus,
166
- 'CreatedAt': element.createdAt,
240
+ 'CreatedAt': dayjs( element.createdAt ).format( 'YYYY,MMM D' ),
167
241
 
168
242
  } );
169
243
  } );
@@ -184,7 +258,7 @@ export async function userAuditHistory( req, res ) {
184
258
  } );
185
259
  const result = await aggregateUserAudit( query );
186
260
 
187
- return res.sendSuccess( { result: result } );
261
+ return res.sendSuccess( { result: result, count: count.length } );
188
262
  } catch ( error ) {
189
263
  const err = error.message || 'Internal Server Error';
190
264
  logger.info( { error: error, message: req.body, function: 'userAuditHistory' } );
@@ -214,6 +288,10 @@ export async function storeMetrics( req, res ) {
214
288
  filter.push( { status: { $in: inputData.filterByStatus } } );
215
289
  }
216
290
 
291
+ if ( inputData.filterByType && inputData.filterByType?.length > 0 ) {
292
+ filter.push( { auditType: { $in: inputData.filterByType } } );
293
+ }
294
+
217
295
 
218
296
  const query = [
219
297
  {
@@ -221,16 +299,45 @@ export async function storeMetrics( req, res ) {
221
299
  $and: filter,
222
300
  },
223
301
  },
302
+
303
+ {
304
+ $lookup: {
305
+ from: 'stores',
306
+ let: { storeId: '$storeId' },
307
+ pipeline: [
308
+ {
309
+ $match: {
310
+ $expr: {
311
+ $eq: [ '$storeId', '$$storeId' ],
312
+ },
313
+ },
314
+ },
315
+ {
316
+ $project: {
317
+ _id: 0,
318
+ storeName: 1,
319
+ },
320
+ },
321
+ ], as: 'stores',
322
+ },
323
+ },
324
+ {
325
+ $unwind: {
326
+ path: '$stores',
327
+ preserveNullAndEmptyArrays: true,
328
+ },
329
+ },
224
330
  {
225
331
  $project: {
226
332
  _id: 0,
227
333
  fileDate: 1,
228
334
  storeId: 1,
229
- storeName: '$storeId',
335
+ storeName: '$store.storeName',
336
+ clientName: '',
337
+ clientId: 1,
230
338
  userId: {
231
339
  $arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ],
232
340
  },
233
- clientId: 1,
234
341
  auditType: 1,
235
342
  beforeCount: 1,
236
343
  afterCount: { $ifNull: [ '$afterCount', null ] },
@@ -247,56 +354,56 @@ export async function storeMetrics( req, res ) {
247
354
  },
248
355
  {
249
356
  $lookup: {
250
- from: 'stores',
251
- let: { storeId: '$storeId' },
357
+ from: 'users',
358
+ let: { userId: '$userId' },
252
359
  pipeline: [
253
360
  {
254
361
  $match: {
255
362
  $expr: {
256
- $eq: [ '$storeId', '$$storeId' ],
363
+ $eq: [ '$_id', '$$userId' ],
257
364
  },
258
365
  },
259
366
  },
260
367
  {
261
368
  $project: {
262
369
  _id: 0,
263
- storeName: 1,
370
+ userName: 1,
371
+ userEmail: '$email',
264
372
  },
265
373
  },
266
- ], as: 'stores',
374
+ ], as: 'users',
267
375
  },
268
376
  },
269
377
  {
270
378
  $unwind: {
271
- path: '$stores',
379
+ path: '$users',
272
380
  preserveNullAndEmptyArrays: true,
273
381
  },
274
382
  },
275
383
  {
276
384
  $lookup: {
277
- from: 'users',
278
- let: { userId: '$userId' },
385
+ from: 'clients',
386
+ let: { clientId: '$clientId' },
279
387
  pipeline: [
280
388
  {
281
389
  $match: {
282
390
  $expr: {
283
- $eq: [ '$_id', '$$userId' ],
391
+ $eq: [ '$clientId', '$$clientId' ],
284
392
  },
285
393
  },
286
394
  },
287
395
  {
288
396
  $project: {
289
397
  _id: 0,
290
- userName: 1,
291
- userEmail: '$email',
398
+ clientName: 1,
292
399
  },
293
400
  },
294
- ], as: 'users',
401
+ ], as: 'client',
295
402
  },
296
403
  },
297
404
  {
298
405
  $unwind: {
299
- path: '$users',
406
+ path: '$client',
300
407
  preserveNullAndEmptyArrays: true,
301
408
  },
302
409
  },
@@ -308,19 +415,43 @@ export async function storeMetrics( req, res ) {
308
415
  storeName: '$stores.storeName',
309
416
  userName: '$users.userName',
310
417
  userEmail: '$users.userEmail',
311
-
312
418
  clientId: 1,
419
+ clientName: '$client.clientName',
313
420
  auditType: 1,
314
421
  beforeCount: 1,
315
422
  afterCount: { $ifNull: [ '$afterCount', null ] },
316
423
  accuracy: { $round: [
317
424
  { $divide: [
318
425
  { $multiply: [ { $ifNull: [ '$afterCount', 0 ] }, '$beforeCount' ] }, 100,
319
- ] }, 2,
426
+ ] }, 1,
320
427
  ],
321
428
 
322
429
  },
323
- timeSpent: 1,
430
+ timeSpent: {
431
+
432
+ $cond: [
433
+ { $lt: [ '$timeSpent', 60 ] }, // Case 1: If less than 60 seconds
434
+ { $concat: [ { $toString: '$timeSpent' }, ' sec' ] },
435
+ {
436
+ $cond: [
437
+ { $lt: [ '$timeSpent', 3600 ] }, // Case 2: If less than 60 minutes (3600 seconds)
438
+ {
439
+ $concat: [
440
+ { $toString: { $round: [ { $divide: [ '$timeSpent', 60 ] }, 1 ] } }, // Convert to minutes
441
+ ' min',
442
+ ],
443
+ },
444
+ {
445
+ $concat: [
446
+ { $toString: { $round: [ { $divide: [ '$timeSpent', 3600 ] }, 1 ] } }, // Convert to hours
447
+ ' hr',
448
+ ],
449
+ },
450
+ ],
451
+ },
452
+ ],
453
+
454
+ },
324
455
  status: 1,
325
456
  },
326
457
  },
@@ -333,10 +464,23 @@ export async function storeMetrics( req, res ) {
333
464
  $or: [
334
465
  { clientId: { $regex: inputData.searchValue, $options: 'i' } },
335
466
  { clientName: { $regex: inputData.searchValue, $options: 'i' } },
467
+ { storeId: { $regex: inputData.searchValue, $options: 'i' } },
468
+ { storeName: { $regex: inputData.searchValue, $options: 'i' } },
469
+ { userName: { $regex: inputData.searchValue, $options: 'i' } },
470
+ { status: { $regex: inputData.searchValue, $options: 'i' } },
471
+ { auditType: { $regex: inputData.searchValue, $options: 'i' } },
336
472
  ],
337
473
  },
338
474
  } );
339
475
  }
476
+
477
+ if ( inputData.sortColumnName ) {
478
+ const sortBy = inputData.sortBy || -1;
479
+ query.push( {
480
+ $sort: { [inputData.sortColumName]: sortBy },
481
+ },
482
+ );
483
+ }
340
484
  const count = await aggregateStoreAudit( query );
341
485
 
342
486
  if ( count.length == 0 ) {
@@ -361,6 +505,7 @@ export async function storeMetrics( req, res ) {
361
505
  'Store Id': element.storeId,
362
506
  'Store Name': element.storeName,
363
507
  'Client Id': element.clientId,
508
+ 'Client Name': element.clientName,
364
509
  'User Name': element.userName,
365
510
  'User Email': element.userEmail,
366
511
  'Audit Type': element.auditType,
@@ -389,6 +534,7 @@ export async function clientMetrics( req, res ) {
389
534
  let filter = [
390
535
  { fileDateISO: { $gte: dateRange.start } },
391
536
  { fileDateISO: { $lte: dateRange.end } },
537
+ { moduleType: { $eq: 'traffic' } },
392
538
 
393
539
  ];
394
540
  if ( inputData?.filterByClient?.length> 0 ) {
@@ -396,11 +542,6 @@ export async function clientMetrics( req, res ) {
396
542
  { clientId: { $in: inputData.filterByClient } },
397
543
  );
398
544
  }
399
- if ( inputData?.filterByAuditType?.length> 0 ) {
400
- filter.push(
401
- { clientId: { $in: inputData.filterByAuditType } },
402
- );
403
- }
404
545
  const query = [
405
546
  {
406
547
  $match: {
@@ -438,6 +579,7 @@ export async function clientMetrics( req, res ) {
438
579
  {
439
580
  $project: {
440
581
  completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
582
+ notAssignedStores: { $cond: [ { $eq: [ '$status', 'not_assign' ] }, 1, 0 ] },
441
583
  inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
442
584
  },
443
585
  },
@@ -446,6 +588,8 @@ export async function clientMetrics( req, res ) {
446
588
  _id: { clientId: '$clientId', fileDate: '$fileDate' },
447
589
  completedStores: { $sum: '$completedStores' },
448
590
  inprogressStores: { $sum: '$inprogressStores' },
591
+ notAssignedStores: { $sum: '$notAssignedStores' },
592
+ fileCount: { $sum: 1 },
449
593
  },
450
594
  },
451
595
  {
@@ -453,6 +597,8 @@ export async function clientMetrics( req, res ) {
453
597
  _id: 0,
454
598
  completedStores: 1,
455
599
  inprogressStores: 1,
600
+ notAssignedStores: 1,
601
+ fileCount: 1,
456
602
  completionPercentage: { $ifNull: [
457
603
  {
458
604
  $round: [ {
@@ -487,15 +633,18 @@ export async function clientMetrics( req, res ) {
487
633
  clientName: 1,
488
634
  totalFilesCount: 1,
489
635
  installedStore: 1,
636
+ notAssignedStores: '$storeAudit.notAssignedStores',
490
637
  inprogressStoresCount: '$storeAudit.inprogressStores',
638
+ fileCount: '$storeAudit.fileCount',
491
639
  notAssignedCount: 1,
492
- clientStatus: { $cond: [ { $gt: [ '$storeAudit.inprogressStores', 0 ] }, 'not-taken', { $cond: [ { $gt: [ '$notAssignedCount', 0 ] }, 'pending', 'completed' ] } ] },
640
+ clientStatus: { $cond: [ { $eq: [ '$storeAudit.fileCount', 0 ] }, 'not-taken', { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$storeAudit.notAssignedStores', 0 ] } ] }, 'pending', 'completed' ] } ] },
493
641
  completedStores: '$storeAudit.completedStores',
494
642
  completionPercentage: '$storeAudit.completionPercentage',
495
643
 
496
644
  },
497
645
  },
498
646
  ];
647
+
499
648
  if ( inputData.searchValue && inputData.searchValue!== '' ) {
500
649
  query.push( {
501
650
  $match: {
@@ -537,6 +686,7 @@ export async function clientMetrics( req, res ) {
537
686
  'Audit Stores': '$totalFilesCount',
538
687
  'Inprogress Stores': '$inprogressStoresCount',
539
688
  'Not Assigned': '$notAssignedCount',
689
+ 'Not Assigned Stores': '$notAssignedStores',
540
690
  'Completed': '$completedStores',
541
691
  'Status': '$clientStatus',
542
692
  },
@@ -580,7 +730,7 @@ export async function userMetrics( req, res ) {
580
730
  }
581
731
  if ( inputData?.filterByAuditType?.length> 0 ) {
582
732
  filter.push(
583
- { clientId: { $in: inputData.filterByAuditType } },
733
+ { moduleType: { $in: inputData.filterByAuditType } },
584
734
  );
585
735
  }
586
736
  if ( inputData?.filterByStatus?.length> 0 ) {
@@ -609,9 +759,8 @@ export async function userMetrics( req, res ) {
609
759
  startTime: 1,
610
760
  endTime: 1,
611
761
  totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
612
- beforeCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$beforeCount', 0 ] },
762
+ beforeCount: 1,
613
763
  afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
614
- zoneName: 1,
615
764
  },
616
765
  },
617
766
  {
@@ -624,7 +773,6 @@ export async function userMetrics( req, res ) {
624
773
  afterCount: { $sum: '$afterCount' },
625
774
  checkIntime: { $first: '$startTime' },
626
775
  checkOutTime: { $last: '$endTime' },
627
- zoneName: { $last: '$zoneNmae' },
628
776
 
629
777
  },
630
778
  },
@@ -636,7 +784,6 @@ export async function userMetrics( req, res ) {
636
784
  totalCompletedFiles: 1,
637
785
  beforeCount: 1,
638
786
  afterCount: 1,
639
- zoneName: 1,
640
787
  mappingPerc: { $round: [
641
788
  { $multiply: [
642
789
  { $divide: [ '$afterCount', '$beforeCount' ] }, 100,
@@ -658,7 +805,6 @@ export async function userMetrics( req, res ) {
658
805
  afterCount: 1,
659
806
  checkIntime: 1,
660
807
  checkOutTime: 1,
661
- zoneName: 1,
662
808
  mappingPerc: 1,
663
809
  hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
664
810
  minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
@@ -675,7 +821,6 @@ export async function userMetrics( req, res ) {
675
821
  afterCount: 1,
676
822
  checkIntime: 1,
677
823
  checkOutTime: 1,
678
- zoneName: 1,
679
824
  hours: {
680
825
  $cond: {
681
826
  if: { $lt: [ '$hours', 10 ] },
@@ -748,12 +893,23 @@ export async function userMetrics( req, res ) {
748
893
  userName: '$userInfo.userName',
749
894
  userId: 1,
750
895
  fileDate: 1,
751
- zoneName: 1,
752
896
  totalCompletedFiles: 1,
753
897
  beforeCount: 1,
754
898
  afterCount: 1,
755
- checkIntime: 1,
756
- checkOutTime: 1,
899
+ checkIntime: {
900
+ $dateToString: {
901
+ format: '%Y-%m-%d %H:%M:%S',
902
+ date: '$checkIntime',
903
+ timezone: 'Asia/Kolkata',
904
+ },
905
+ },
906
+ checkOutTime: {
907
+ $dateToString: {
908
+ format: '%Y-%m-%d %H:%M:%S',
909
+ date: '$checkOutTime',
910
+ timezone: 'Asia/Kolkata',
911
+ },
912
+ },
757
913
  workingHours: 1,
758
914
  },
759
915
  },
@@ -762,7 +918,7 @@ export async function userMetrics( req, res ) {
762
918
  query.push( {
763
919
  $match: {
764
920
  $or: [
765
- { clientId: { $regex: inputData.searchValue, $options: 'i' } },
921
+ { userName: { $regex: inputData.searchValue, $options: 'i' } },
766
922
  { clientName: { $regex: inputData.searchValue, $options: 'i' } },
767
923
  ],
768
924
 
@@ -794,7 +950,6 @@ export async function userMetrics( req, res ) {
794
950
  'File Date': '$fileDate',
795
951
  'User Name': '$userName',
796
952
  'User Id': '$userId',
797
- 'Zone Name': '$zoneName',
798
953
  'Total Completed Files Count': '$totalCompletedFiles',
799
954
  'Total efore Count': '$beforeCount',
800
955
  'Total After Count': '$afterCount',
@@ -1020,12 +1175,15 @@ export async function overViewTable( req, res ) {
1020
1175
  { fileDateISO: { $gte: dateRange.start } },
1021
1176
  { fileDateISO: { $lte: dateRange.end } },
1022
1177
  { auditStatus: { $in: inputData.filterByStatus } },
1023
- { auditType: { $in: inputData.filterByAuditType } },
1178
+ { auditType: { $in: inputData.filterByType } },
1024
1179
 
1025
1180
  ];
1026
1181
  if ( inputData.clientId.length > 0 ) {
1027
1182
  filters.push( { clientId: { $in: inputData.clientId } } );
1028
1183
  }
1184
+ if ( inputData.filterByAuditType.length > 0 ) {
1185
+ filters.push( { moduleType: { $in: inputData.filterByAuditType } } );
1186
+ }
1029
1187
 
1030
1188
  const query =[
1031
1189
  {
@@ -1044,8 +1202,6 @@ export async function overViewTable( req, res ) {
1044
1202
  auditType: 1,
1045
1203
  auditStatus: 1,
1046
1204
  userId: 1,
1047
-
1048
-
1049
1205
  },
1050
1206
  },
1051
1207
  {
@@ -1083,8 +1239,8 @@ export async function overViewTable( req, res ) {
1083
1239
  startTime: 1,
1084
1240
  auditType: 1,
1085
1241
  auditStatus: 1,
1086
- userName: '$users.userName',
1087
- userEmail: '$users.userEmail',
1242
+ userName: '$user.userName',
1243
+ userEmail: '$user.userEmail',
1088
1244
 
1089
1245
  },
1090
1246
  },
@@ -1093,8 +1249,12 @@ export async function overViewTable( req, res ) {
1093
1249
  query.push( {
1094
1250
  $match: {
1095
1251
  $or: [
1096
- { clientId: { $regex: inputData.searchValue, $options: 'i' } },
1097
- { clientName: { $regex: inputData.searchValue, $options: 'i' } },
1252
+ { storeId: { $regex: inputData.searchValue, $options: 'i' } },
1253
+ { fileDate: { $regex: inputData.searchValue, $options: 'i' } },
1254
+ { auditType: { $regex: inputData.searchValue, $options: 'i' } },
1255
+ { auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
1256
+ { userName: { $regex: inputData.searchValue, $options: 'i' } },
1257
+ { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
1098
1258
  ],
1099
1259
 
1100
1260
  },
@@ -1130,12 +1290,13 @@ export async function overViewTable( req, res ) {
1130
1290
  exportdata.push( {
1131
1291
  'Store Id': element.storeId,
1132
1292
  'File Date': element.fileDtae,
1133
- 'Audit Type': element.audittype,
1293
+ 'Type': element.audittype,
1134
1294
  'Before Count': element.beforeCount,
1135
1295
  'Start Time': element.startTime,
1136
1296
  'User Name': element.userName,
1137
1297
  'User Email': element.userEmail,
1138
1298
  'Status': element.auditStatus,
1299
+ 'Audit Type': element.moduleType,
1139
1300
  } );
1140
1301
  } );
1141
1302
  await download( exportdata, res );
@@ -1244,7 +1405,7 @@ export async function overAllAuditSummary( req, res ) {
1244
1405
  },
1245
1406
  },
1246
1407
  ];
1247
- const storeAudit = await aggregateStoreAudit( storeAuditQuery );
1408
+ const storeAudit = inputData.moduleType == 'zone'?await aggregateStoreZoneAudit( storeAuditQuery ) : await aggregateStoreAudit( storeAuditQuery );
1248
1409
  if ( storeAudit.length > 0 ) {
1249
1410
  temp.inprogreseStores= storeAudit[0].inprogreseStores;
1250
1411
  temp.completedStores = storeAudit[0].completedStores;
@@ -1286,7 +1447,7 @@ export async function reTrigger( req, res ) {
1286
1447
  const msg = {
1287
1448
  store_id: inputData.storeId,
1288
1449
  curr_date: inputData.fileDate,
1289
- audit_type: inputData.auditType,
1450
+ audit_type: inputData.type,
1290
1451
  total_count: inputData.totalCount,
1291
1452
  };
1292
1453
 
@@ -1328,7 +1489,7 @@ export async function reTrigger( req, res ) {
1328
1489
  beforeCount: inputData.totalCount,
1329
1490
  afterCount: '',
1330
1491
  fileDate: inputData.fileDate,
1331
- auditType: inputData.auditType,
1492
+ auditType: inputData.type,
1332
1493
  storeId: inputData.storeId,
1333
1494
  queueName: queueName,
1334
1495
  message: inputData.comments,
@@ -1346,8 +1507,9 @@ export async function reTrigger( req, res ) {
1346
1507
  storeId: inputData.storeId,
1347
1508
  clientId: req.audit.clientId,
1348
1509
  fileDate: inputData.fileDate,
1510
+ moduleType: 'traffic',
1349
1511
  fileDateISO: dayjs( inputData.fileDate, 'DD-MM-YYYY' ).format(),
1350
- auditType: inputData.auditType,
1512
+ auditType: inputData.type,
1351
1513
  fileCount: inputData.beforeCount,
1352
1514
  queueName: queueName,
1353
1515
  userId: inputData.userId,
@@ -1383,7 +1545,7 @@ export async function reTrigger( req, res ) {
1383
1545
  beforeCount: inputData.totalCount,
1384
1546
  afterCount: '',
1385
1547
  fileDate: inputData.fileDate,
1386
- auditType: inputData.auditType,
1548
+ auditType: inputData.type,
1387
1549
  storeId: inputData.storeId,
1388
1550
  queueName: queueName,
1389
1551
  message: inputData.comments,