tango-app-api-audit 1.0.47 → 1.0.49
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/index.js +1 -7
- package/package.json +2 -2
- package/src/controllers/audit.controllers.js +305 -88
- package/src/controllers/auditMetrics.controllers.js +20 -22
- package/src/controllers/zoneAudit.controller.js +38 -41
- package/src/docs/audit.docs.js +107 -6
- package/src/dtos/audit.dtos.js +53 -0
- package/src/routes/audit.routes.js +9 -2
- package/src/service/auditStoreData.service.js +10 -0
- package/src/validation/zoneAudit.validation.js +2 -2
- package/src/controllers/client.controllers.js +0 -42
- package/src/controllers/store.controllers.js +0 -42
- package/src/controllers/user.controllers.js +0 -41
- package/src/docs/client.docs.js +0 -33
- package/src/docs/store.docs.js +0 -27
- package/src/docs/user.docs.js +0 -33
- package/src/dtos/client.dtos.js +0 -13
- package/src/dtos/store.dtos.js +0 -14
- package/src/dtos/user.dtos.js +0 -14
- package/src/routes/client.routes.js +0 -10
- package/src/routes/store.routes.js +0 -10
- package/src/routes/user.routes.js +0 -9
- package/src/service/assignZoneAudit.service.js +0 -12
- package/src/service/auditClientData.service.js +0 -6
- package/src/service/storeZoneAudit.service.js +0 -17
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
aggregateAssignAudit,
|
|
20
20
|
updateOneAssignAudit,
|
|
21
21
|
} from '../service/assignAudit.service.js';
|
|
22
|
-
import { findOneUser } from '../service/user.service.js';
|
|
22
|
+
import { aggregateUser, findOneUser } from '../service/user.service.js';
|
|
23
23
|
import dayjs from 'dayjs';
|
|
24
24
|
import { aggregateClient, findClient } from '../service/client.service.js';
|
|
25
25
|
import { logger } from 'tango-app-api-middleware';
|
|
@@ -34,13 +34,12 @@ 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,
|
|
41
40
|
findOneAuditLog,
|
|
42
41
|
} from '../service/auditLog.service.js';
|
|
43
|
-
import { findOneStore } from '../service/store.service.js';
|
|
42
|
+
import { aggregateStore, findOneStore } from '../service/store.service.js';
|
|
44
43
|
import {
|
|
45
44
|
mapCustomer,
|
|
46
45
|
mapEmployee,
|
|
@@ -50,6 +49,140 @@ import {
|
|
|
50
49
|
splitG20000,
|
|
51
50
|
} from '../validation/audit.validation.js';
|
|
52
51
|
import mongoose from 'mongoose';
|
|
52
|
+
import {
|
|
53
|
+
aggregateAuditStoreDataSchema,
|
|
54
|
+
findOneStoreData,
|
|
55
|
+
} from '../service/auditStoreData.service.js';
|
|
56
|
+
|
|
57
|
+
/* < -- *** Configuration *** --> */
|
|
58
|
+
|
|
59
|
+
// client
|
|
60
|
+
export async function clients( req, res ) {
|
|
61
|
+
try {
|
|
62
|
+
const inputData = req.query;
|
|
63
|
+
const query = [
|
|
64
|
+
{
|
|
65
|
+
$match: {
|
|
66
|
+
'status': { $in: [ 'active', 'hold' ] },
|
|
67
|
+
'auditConfigs.audit': true,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
$project: {
|
|
72
|
+
_id: 0,
|
|
73
|
+
clientName: 1,
|
|
74
|
+
clientId: 1,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
const count = await aggregateClient( query );
|
|
80
|
+
if ( count.length == 0 ) {
|
|
81
|
+
return res.sendSuccess( { result: [], count: 0 } );
|
|
82
|
+
}
|
|
83
|
+
if ( inputData.limit ) {
|
|
84
|
+
const offset = inputData.offset ?
|
|
85
|
+
( inputData.offset - 1 ) * inputData.limit :
|
|
86
|
+
0;
|
|
87
|
+
query.push( { $skip: offset }, { $limit: limit } );
|
|
88
|
+
}
|
|
89
|
+
const getAuditClients = await aggregateClient( query );
|
|
90
|
+
|
|
91
|
+
return res.sendSuccess( { result: getAuditClients, count: count.length } );
|
|
92
|
+
} catch ( error ) {
|
|
93
|
+
const err = error.message || 'Internal Server Error';
|
|
94
|
+
logger.info( { error: error, messgae: req.query, function: 'clients' } );
|
|
95
|
+
return res.sendError( err, 500 );
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function auditStoreList( req, res ) {
|
|
100
|
+
try {
|
|
101
|
+
const inputData = req.body;
|
|
102
|
+
const query = [
|
|
103
|
+
{
|
|
104
|
+
$match: {
|
|
105
|
+
clientId: { $in: inputData.clientId },
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
$project: {
|
|
110
|
+
_id: 0,
|
|
111
|
+
clientId: 1,
|
|
112
|
+
storeId: 1,
|
|
113
|
+
storeName: 1,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const count = await aggregateStore( query );
|
|
119
|
+
if ( count.length == 0 ) {
|
|
120
|
+
return res.sendSuccess( { result: [], count: 0 } );
|
|
121
|
+
}
|
|
122
|
+
if ( inputData.limit ) {
|
|
123
|
+
const offset = inputData.offset ?
|
|
124
|
+
( inputData.offset - 1 ) * inputData.limit :
|
|
125
|
+
0;
|
|
126
|
+
query.push( { $skip: offset }, { $limit: limit } );
|
|
127
|
+
}
|
|
128
|
+
const result = await aggregateStore( query );
|
|
129
|
+
|
|
130
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
131
|
+
} catch ( error ) {
|
|
132
|
+
const err = error.message || 'Internal Server Error';
|
|
133
|
+
logger.info( {
|
|
134
|
+
error: error,
|
|
135
|
+
messgae: req.body,
|
|
136
|
+
function: 'auditStoreList',
|
|
137
|
+
} );
|
|
138
|
+
return res.sendError( err, 500 );
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function auditUserList( req, res ) {
|
|
143
|
+
try {
|
|
144
|
+
const inputData = req.query;
|
|
145
|
+
const query = [
|
|
146
|
+
{
|
|
147
|
+
$match: {
|
|
148
|
+
userType: { $eq: 'tango' },
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
$project: {
|
|
153
|
+
userName: 1,
|
|
154
|
+
userId: '$_id',
|
|
155
|
+
_id: 0,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
const count = await aggregateUser( query );
|
|
161
|
+
if ( count.length == 0 ) {
|
|
162
|
+
return res.sendSuccess( { result: [], count: 0 } );
|
|
163
|
+
}
|
|
164
|
+
if ( inputData.limit ) {
|
|
165
|
+
const offset = inputData.offset ?
|
|
166
|
+
( inputData.offset - 1 ) * inputData.limit :
|
|
167
|
+
0;
|
|
168
|
+
query.push( { $skip: offset }, { $limit: limit } );
|
|
169
|
+
}
|
|
170
|
+
const result = await aggregateUser( query );
|
|
171
|
+
|
|
172
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
173
|
+
} catch ( error ) {
|
|
174
|
+
const err = error.message || 'Internal Server Error';
|
|
175
|
+
logger.info( {
|
|
176
|
+
error: error,
|
|
177
|
+
messgae: req.query,
|
|
178
|
+
function: 'auditUserList',
|
|
179
|
+
} );
|
|
180
|
+
return res.sendError( err, 500 );
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* < -- *** Audit Mapping *** --> */
|
|
185
|
+
|
|
53
186
|
export async function getAuditFile( req, res ) {
|
|
54
187
|
try {
|
|
55
188
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
@@ -69,6 +202,7 @@ export async function getAuditFile( req, res ) {
|
|
|
69
202
|
{ auditStatus: { $nin: [ 'completed', 'skipped' ] } },
|
|
70
203
|
{ createdAt: { $gte: start } },
|
|
71
204
|
{ createdAt: { $lte: end } },
|
|
205
|
+
{ moduleType: inputData.moduleType },
|
|
72
206
|
],
|
|
73
207
|
},
|
|
74
208
|
},
|
|
@@ -83,7 +217,6 @@ export async function getAuditFile( req, res ) {
|
|
|
83
217
|
const userDetails = await aggregateUserAudit( userQuery );
|
|
84
218
|
const auditStatus =
|
|
85
219
|
userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
86
|
-
|
|
87
220
|
switch ( auditStatus ) {
|
|
88
221
|
case null:
|
|
89
222
|
const query = [
|
|
@@ -93,6 +226,7 @@ export async function getAuditFile( req, res ) {
|
|
|
93
226
|
{ userId: { $eq: req.user._id } },
|
|
94
227
|
{ isCompleted: { $eq: false } },
|
|
95
228
|
{ queueName: inputData.queueName },
|
|
229
|
+
{ moduleType: inputData.moduleType },
|
|
96
230
|
],
|
|
97
231
|
},
|
|
98
232
|
},
|
|
@@ -105,12 +239,14 @@ export async function getAuditFile( req, res ) {
|
|
|
105
239
|
store_id: userAssign[0].storeId,
|
|
106
240
|
curr_date: userAssign[0].fileDate,
|
|
107
241
|
total_count: userAssign[0].fileCount,
|
|
242
|
+
zone_id: userAssign[0].zoneName,
|
|
108
243
|
} ) :
|
|
109
244
|
( msg = {
|
|
110
245
|
store_id: userAssign[0].storeId,
|
|
111
246
|
curr_date: userAssign[0].fileDate,
|
|
112
247
|
audit_type: userAssign[0].fileType,
|
|
113
248
|
total_count: userAssign[0].fileCount,
|
|
249
|
+
zone_id: userAssign[0].zoneName,
|
|
114
250
|
} );
|
|
115
251
|
await updateOneAssignAudit(
|
|
116
252
|
{ _id: userAssign[0]._id },
|
|
@@ -143,6 +279,8 @@ export async function getAuditFile( req, res ) {
|
|
|
143
279
|
fileDate: userDetails[0].fileDate,
|
|
144
280
|
storeId: userDetails[0].storeId,
|
|
145
281
|
totalCount: userDetails[0].beforeCount,
|
|
282
|
+
moduleType: userDetails[0].moduleType,
|
|
283
|
+
zoneName: userDetails[0].zoneName,
|
|
146
284
|
},
|
|
147
285
|
{},
|
|
148
286
|
{ createdAt: -1 },
|
|
@@ -166,6 +304,8 @@ export async function getAuditFile( req, res ) {
|
|
|
166
304
|
type: userDetails[0].auditType,
|
|
167
305
|
queueName: log.queueName,
|
|
168
306
|
userId: log.userId,
|
|
307
|
+
moduleType: userDetails[0].moduleType,
|
|
308
|
+
zoneName: userDetails[0].zoneName,
|
|
169
309
|
};
|
|
170
310
|
const result = {
|
|
171
311
|
junk: log.junk,
|
|
@@ -196,6 +336,8 @@ export async function getAuditFile( req, res ) {
|
|
|
196
336
|
storeId: userDetails[0].storeId,
|
|
197
337
|
clientName: log.queueName,
|
|
198
338
|
auditId: userDetails[0]._id,
|
|
339
|
+
moduleType: userDetails[0].moduleType,
|
|
340
|
+
zoneName: userDetails[0].zoneName,
|
|
199
341
|
},
|
|
200
342
|
};
|
|
201
343
|
logger.info( { logData: logData } );
|
|
@@ -227,6 +369,7 @@ export async function getAuditFile( req, res ) {
|
|
|
227
369
|
curr_date: userDetails[0].fileDate,
|
|
228
370
|
audit_type: userDetails[0].auditType,
|
|
229
371
|
total_count: userDetails[0].beforeCount,
|
|
372
|
+
zone_id: userDetails[0].zoneName,
|
|
230
373
|
};
|
|
231
374
|
break;
|
|
232
375
|
}
|
|
@@ -261,6 +404,8 @@ export async function getAuditFile( req, res ) {
|
|
|
261
404
|
fileDateISO: start,
|
|
262
405
|
timeSpent: 0,
|
|
263
406
|
startTime: new Date(),
|
|
407
|
+
zoneName: msg.zone_id,
|
|
408
|
+
moduleType: inputData.moduleType,
|
|
264
409
|
};
|
|
265
410
|
const storeRecord = {
|
|
266
411
|
userId: req.user._id,
|
|
@@ -273,6 +418,8 @@ export async function getAuditFile( req, res ) {
|
|
|
273
418
|
status: 'inprogress',
|
|
274
419
|
fileDateISO: start,
|
|
275
420
|
timeSpent: 0,
|
|
421
|
+
zoneName: msg.zone_id,
|
|
422
|
+
moduleType: inputData.moduleType,
|
|
276
423
|
};
|
|
277
424
|
reauditInsert = await createUserAudit( record );
|
|
278
425
|
await createStoreAudit( storeRecord );
|
|
@@ -292,6 +439,8 @@ export async function getAuditFile( req, res ) {
|
|
|
292
439
|
storeId: msg.store_id,
|
|
293
440
|
clientName: inputData.queueName,
|
|
294
441
|
auditId: reauditInsert._id,
|
|
442
|
+
zoneName: msg.zone_id,
|
|
443
|
+
moduleType: inputData.moduleType,
|
|
295
444
|
},
|
|
296
445
|
};
|
|
297
446
|
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
@@ -319,16 +468,19 @@ export async function getAuditFile( req, res ) {
|
|
|
319
468
|
queueName: inputData.queueName,
|
|
320
469
|
auditId: reauditInsert._id,
|
|
321
470
|
userId: reauditInsert.userId,
|
|
471
|
+
zoneName: msg.zone_id,
|
|
472
|
+
moduleType: inputData.moduleType,
|
|
322
473
|
},
|
|
323
474
|
isDraft: reauditInsert.isDraft,
|
|
324
475
|
} );
|
|
325
476
|
}
|
|
326
477
|
const storeId = msg.store_id;
|
|
327
478
|
const fileDate = msg.curr_date;
|
|
479
|
+
|
|
328
480
|
const files = [];
|
|
329
481
|
let insertData = {};
|
|
330
482
|
fetchData.Bucket = bucket.auditInput; // need to change
|
|
331
|
-
fetchData.file_path = `${fileDate}/${storeId}/`;
|
|
483
|
+
fetchData.file_path = `${fileDate}/${storeId}/${msg.zone_id}/`;
|
|
332
484
|
if ( inputData.limit ) {
|
|
333
485
|
fetchData.MaxKeys = inputData.limit;
|
|
334
486
|
}
|
|
@@ -342,7 +494,7 @@ export async function getAuditFile( req, res ) {
|
|
|
342
494
|
if ( folderPath?.length > 0 ) {
|
|
343
495
|
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
344
496
|
const img = folderPath[i].Key.split( '/' );
|
|
345
|
-
const image = img[
|
|
497
|
+
const image = img[3].split( '.' );
|
|
346
498
|
const indexes = image[0].split( '_' );
|
|
347
499
|
fetchData.file_path = folderPath[i].Key;
|
|
348
500
|
const data = await signedUrl( fetchData );
|
|
@@ -382,6 +534,8 @@ export async function getAuditFile( req, res ) {
|
|
|
382
534
|
fileDateISO: start,
|
|
383
535
|
timeSpent: 0,
|
|
384
536
|
startTime: new Date(),
|
|
537
|
+
zoneName: msg.zone_id,
|
|
538
|
+
moduleType: inputData.moduleType,
|
|
385
539
|
};
|
|
386
540
|
const storeRecord = {
|
|
387
541
|
userId: req.user._id,
|
|
@@ -394,10 +548,12 @@ export async function getAuditFile( req, res ) {
|
|
|
394
548
|
status: 'inprogress',
|
|
395
549
|
fileDateISO: start,
|
|
396
550
|
timeSpent: 0,
|
|
551
|
+
zoneName: msg.zone_id,
|
|
552
|
+
moduleType: inputData.moduleType,
|
|
397
553
|
};
|
|
398
554
|
|
|
399
555
|
insertData = await createUserAudit( record );
|
|
400
|
-
await
|
|
556
|
+
await createStoreAudit( storeRecord );
|
|
401
557
|
} else {
|
|
402
558
|
insertData = userDetails[0];
|
|
403
559
|
}
|
|
@@ -430,6 +586,8 @@ export async function getAuditFile( req, res ) {
|
|
|
430
586
|
storeId: storeId,
|
|
431
587
|
clientName: inputData.queueName,
|
|
432
588
|
auditId: insertData._id,
|
|
589
|
+
zoneName: msg.zone_id,
|
|
590
|
+
moduleType: inputData.moduleType,
|
|
433
591
|
},
|
|
434
592
|
};
|
|
435
593
|
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
@@ -448,6 +606,8 @@ export async function getAuditFile( req, res ) {
|
|
|
448
606
|
type: 'Audit',
|
|
449
607
|
auditId: insertData._id,
|
|
450
608
|
userId: insertData.userId,
|
|
609
|
+
zoneName: msg.zone_id,
|
|
610
|
+
moduleType: inputData.moduleType,
|
|
451
611
|
nextToken: nextQuery ? encodeURIComponent( nextQuery ) : null,
|
|
452
612
|
},
|
|
453
613
|
isDraft: insertData.isDraft,
|
|
@@ -467,7 +627,7 @@ export async function getFilterData( msg ) {
|
|
|
467
627
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
468
628
|
const params = {
|
|
469
629
|
Bucket: `${bucket.auditOutput}`,
|
|
470
|
-
Key: `${msg.store_id}/${msg.curr_date}/${bucketName.masterJsonFile}`,
|
|
630
|
+
Key: `${msg.store_id}/${msg.zone_id}/${msg.curr_date}/${bucketName.masterJsonFile}`,
|
|
471
631
|
};
|
|
472
632
|
const mappingFile = await getJsonFileData( params );
|
|
473
633
|
if ( mappingFile.statusCode ) {
|
|
@@ -503,7 +663,7 @@ export async function getAuditImage( msg ) {
|
|
|
503
663
|
const files = [];
|
|
504
664
|
const fetchData = {};
|
|
505
665
|
fetchData.Bucket = `${bucket.auditInput}`;
|
|
506
|
-
fetchData.filePath = `${fileDate}/${storeId}
|
|
666
|
+
fetchData.filePath = `${fileDate}/${storeId}/${msg.zone_id}`;
|
|
507
667
|
const folderPath = await listFileWithoutLimit( fetchData );
|
|
508
668
|
if ( folderPath.statusCode == 404 ) {
|
|
509
669
|
return folderPath;
|
|
@@ -512,7 +672,7 @@ export async function getAuditImage( msg ) {
|
|
|
512
672
|
if ( auditImages && auditImages?.length > 0 ) {
|
|
513
673
|
for ( let i = 0; i < auditImages.length; i++ ) {
|
|
514
674
|
const img = auditImages[i].Key.split( '/' );
|
|
515
|
-
const image = img[
|
|
675
|
+
const image = img[3].split( '.' );
|
|
516
676
|
const indexes = image[0].split( '_' );
|
|
517
677
|
const params = {
|
|
518
678
|
file_path: auditImages[i].Key,
|
|
@@ -537,7 +697,7 @@ export async function getAuditImage( msg ) {
|
|
|
537
697
|
return files;
|
|
538
698
|
}
|
|
539
699
|
} catch ( error ) {
|
|
540
|
-
logger.error( { error: error, type: '
|
|
700
|
+
logger.error( { error: error, type: 'AWS BUCKET --getAuditImage' } );
|
|
541
701
|
return error;
|
|
542
702
|
}
|
|
543
703
|
}
|
|
@@ -601,50 +761,59 @@ export async function workSpace( req, res ) {
|
|
|
601
761
|
} );
|
|
602
762
|
}
|
|
603
763
|
const count = await aggregateClient( clientQuery );
|
|
604
|
-
logger.info( { count: count } );
|
|
605
764
|
if ( count?.length == 0 ) {
|
|
606
765
|
return res.sendError( 'No Data Found', 204 );
|
|
607
766
|
}
|
|
608
767
|
|
|
609
|
-
if (
|
|
768
|
+
if ( !inputData.isExport ) {
|
|
610
769
|
clientQuery.push( { $skip: offset }, { $limit: limit } );
|
|
611
770
|
}
|
|
612
771
|
|
|
613
772
|
const clientDetails = await aggregateClient( clientQuery );
|
|
614
773
|
const clientList = clientDetails.map( ( i ) => i.clientId );
|
|
615
|
-
const
|
|
774
|
+
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
775
|
+
const getStoreData = await findOneStoreData(
|
|
776
|
+
{},
|
|
777
|
+
{ fileDate: 1 },
|
|
778
|
+
{ createdAt: -1 },
|
|
779
|
+
);
|
|
780
|
+
const latestDate = getStoreData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
|
|
781
|
+
const auditStoreDataQuery = [
|
|
616
782
|
{
|
|
617
783
|
$match: {
|
|
618
784
|
clientId: { $in: clientList },
|
|
785
|
+
moduleType: { $eq: inputData.moduleType },
|
|
786
|
+
fileDate: { $eq: latestDate },
|
|
619
787
|
},
|
|
620
788
|
},
|
|
621
789
|
{
|
|
622
790
|
$group: {
|
|
623
791
|
_id: '$clientId',
|
|
624
792
|
clientId: { $last: '$clientId' },
|
|
625
|
-
totalFilesCount: { $last: '$totalFilesCount' },
|
|
626
793
|
clientName: { $last: '$clientName' },
|
|
794
|
+
installedStore: { $last: '$installedStore' },
|
|
627
795
|
queueName: { $last: '$queueName' },
|
|
796
|
+
totalCount: { $sum: 1 },
|
|
628
797
|
},
|
|
629
798
|
},
|
|
630
799
|
{
|
|
631
800
|
$project: {
|
|
801
|
+
_id: 0,
|
|
632
802
|
clientId: 1,
|
|
633
|
-
totalFilesCount: 1,
|
|
634
803
|
clientName: 1,
|
|
804
|
+
installedStore: 1,
|
|
635
805
|
queueName: 1,
|
|
806
|
+
totalCount: 1,
|
|
636
807
|
},
|
|
637
808
|
},
|
|
638
809
|
];
|
|
639
810
|
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
const completedFiles = [
|
|
811
|
+
const completedStores = [
|
|
643
812
|
{
|
|
644
813
|
$match: {
|
|
645
814
|
$and: [
|
|
646
815
|
{ clientId: { $in: clientList } },
|
|
647
|
-
{
|
|
816
|
+
{ fileDate: { $eq: latestDate } },
|
|
648
817
|
],
|
|
649
818
|
},
|
|
650
819
|
},
|
|
@@ -656,18 +825,26 @@ export async function workSpace( req, res ) {
|
|
|
656
825
|
},
|
|
657
826
|
},
|
|
658
827
|
},
|
|
828
|
+
// {
|
|
829
|
+
// $group: {
|
|
830
|
+
// _id: { clientId: '$clientId', storeId: '$storeId' },
|
|
831
|
+
// clientId: { $first: '$clientId' },
|
|
832
|
+
// completedStoresCount: { $sum: '$completed' },
|
|
833
|
+
// },
|
|
834
|
+
// },
|
|
659
835
|
{
|
|
660
836
|
$group: {
|
|
661
|
-
_id:
|
|
837
|
+
_id: '$clientId',
|
|
662
838
|
clientId: { $first: '$clientId' },
|
|
663
|
-
|
|
839
|
+
// completedStoresCount: { $first: '$completedStoresCount' },
|
|
840
|
+
completedStoresCount: { $sum: '$completed' },
|
|
664
841
|
},
|
|
665
842
|
},
|
|
666
843
|
{
|
|
667
|
-
$
|
|
668
|
-
_id:
|
|
669
|
-
clientId:
|
|
670
|
-
|
|
844
|
+
$project: {
|
|
845
|
+
_id: 0,
|
|
846
|
+
clientId: 1,
|
|
847
|
+
completedStoresCount: 1,
|
|
671
848
|
},
|
|
672
849
|
},
|
|
673
850
|
];
|
|
@@ -699,7 +876,7 @@ export async function workSpace( req, res ) {
|
|
|
699
876
|
_id: { clientId: '$clientId', storeId: '$storeId' },
|
|
700
877
|
clientId: { $first: '$clientId' },
|
|
701
878
|
pendingCount: { $sum: '$pending' },
|
|
702
|
-
|
|
879
|
+
totalFilesCount: { $sum: 1 },
|
|
703
880
|
},
|
|
704
881
|
},
|
|
705
882
|
{
|
|
@@ -707,17 +884,16 @@ export async function workSpace( req, res ) {
|
|
|
707
884
|
_id: '$clientId',
|
|
708
885
|
clientId: { $first: '$clientId' },
|
|
709
886
|
pendingCount: { $first: { $ifNull: [ '$pendingCount', 0 ] } },
|
|
710
|
-
|
|
887
|
+
totalFilesCount: { $first: '$totalFilesCount' },
|
|
711
888
|
},
|
|
712
889
|
},
|
|
713
890
|
];
|
|
714
|
-
|
|
715
|
-
const draftedFiles = [
|
|
891
|
+
const userIncompleteFiles = [
|
|
716
892
|
{
|
|
717
893
|
$match: {
|
|
718
894
|
$and: [
|
|
719
895
|
{ clientId: { $in: clientList } },
|
|
720
|
-
{ userId: { $eq:
|
|
896
|
+
{ userId: { $eq: req.user._id } },
|
|
721
897
|
{ createdAt: { $gte: dateRange.start } },
|
|
722
898
|
{ createdAt: { $lte: dateRange.end } },
|
|
723
899
|
],
|
|
@@ -745,13 +921,13 @@ export async function workSpace( req, res ) {
|
|
|
745
921
|
_id: '$clientId',
|
|
746
922
|
clientId: { $first: '$clientId' },
|
|
747
923
|
isDrafted: { $first: '$isDraft' },
|
|
748
|
-
|
|
749
|
-
|
|
924
|
+
userDraftCount: { $sum: '$draft' },
|
|
925
|
+
userInprogressCount: { $sum: '$inprogress' },
|
|
750
926
|
},
|
|
751
927
|
},
|
|
752
928
|
];
|
|
753
929
|
|
|
754
|
-
const
|
|
930
|
+
const userAsignAudit = [
|
|
755
931
|
{
|
|
756
932
|
$match: {
|
|
757
933
|
$and: [
|
|
@@ -765,14 +941,14 @@ export async function workSpace( req, res ) {
|
|
|
765
941
|
$group: {
|
|
766
942
|
_id: '$clientId',
|
|
767
943
|
clientId: { $first: '$clientId' },
|
|
768
|
-
|
|
944
|
+
userAsignedCount: { $sum: 1 },
|
|
769
945
|
},
|
|
770
946
|
},
|
|
771
947
|
{
|
|
772
948
|
$project: {
|
|
773
949
|
_id: 0,
|
|
774
950
|
clientId: 1,
|
|
775
|
-
|
|
951
|
+
userAsignedCount: 1,
|
|
776
952
|
},
|
|
777
953
|
},
|
|
778
954
|
];
|
|
@@ -787,44 +963,47 @@ export async function workSpace( req, res ) {
|
|
|
787
963
|
$group: {
|
|
788
964
|
_id: '$clientId',
|
|
789
965
|
clientId: { $first: '$clientId' },
|
|
790
|
-
|
|
966
|
+
clientAsignedCount: { $sum: 1 },
|
|
791
967
|
},
|
|
792
968
|
},
|
|
793
969
|
{
|
|
794
970
|
$project: {
|
|
795
971
|
_id: 0,
|
|
796
972
|
clientId: 1,
|
|
797
|
-
|
|
973
|
+
clientAsignedCount: { $ifNull: [ '$clientAsignedCount', 0 ] },
|
|
798
974
|
},
|
|
799
975
|
},
|
|
800
976
|
];
|
|
801
977
|
|
|
802
|
-
const
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
|
|
978
|
+
const auditUserCount = await aggregateUserAudit( auditFiles );
|
|
979
|
+
const userIncompleteFilesCount = await aggregateUserAudit(
|
|
980
|
+
userIncompleteFiles,
|
|
981
|
+
);
|
|
982
|
+
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
983
|
+
const completedStoresCount = await aggregateStoreAudit( completedStores );
|
|
984
|
+
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
985
|
+
const auditStoreData = await aggregateAuditStoreDataSchema(
|
|
986
|
+
auditStoreDataQuery,
|
|
987
|
+
);
|
|
806
988
|
|
|
807
|
-
const clientAssignresult = await aggregateAssignAudit( clientAssign );
|
|
808
|
-
const userAsignCount = await aggregateAssignAudit( userAsign );
|
|
809
989
|
const mergeAll = _.merge(
|
|
810
990
|
_.keyBy( clientDetails, 'clientId' ),
|
|
811
|
-
_.keyBy(
|
|
812
|
-
_.keyBy(
|
|
813
|
-
_.keyBy(
|
|
991
|
+
_.keyBy( auditUserCount, 'clientId' ),
|
|
992
|
+
_.keyBy( userIncompleteFilesCount, 'clientId' ),
|
|
993
|
+
_.keyBy( clientAssignedCount, 'clientId' ),
|
|
814
994
|
);
|
|
815
995
|
const finalResult = _.values( mergeAll );
|
|
816
996
|
const merge = _.values(
|
|
817
997
|
_.merge(
|
|
818
998
|
_.keyBy( finalResult, 'clientId' ),
|
|
819
|
-
_.keyBy(
|
|
820
|
-
_.keyBy(
|
|
821
|
-
_.keyBy(
|
|
999
|
+
_.keyBy( auditStoreData, 'clientId' ),
|
|
1000
|
+
_.keyBy( userAsignAuditCount, 'clientId' ),
|
|
1001
|
+
_.keyBy( completedStoresCount, 'clientId' ),
|
|
822
1002
|
),
|
|
823
1003
|
);
|
|
824
|
-
logger.info( { merge: merge } );
|
|
825
1004
|
let totalStores = 0;
|
|
826
1005
|
for ( let i = 0; i < merge.length; i++ ) {
|
|
827
|
-
totalStores =
|
|
1006
|
+
totalStores = merge[i]?.totalFilesCount || 0;
|
|
828
1007
|
|
|
829
1008
|
const pending = await listQueue( merge[i].queueName );
|
|
830
1009
|
|
|
@@ -832,41 +1011,43 @@ export async function workSpace( req, res ) {
|
|
|
832
1011
|
temp.push( {
|
|
833
1012
|
clientId: merge[i].clientId,
|
|
834
1013
|
clientName: merge[i].clientName,
|
|
835
|
-
|
|
836
|
-
Number( merge[i].
|
|
1014
|
+
completedStoresCount: merge[i].completedStoresCount ?
|
|
1015
|
+
Number( merge[i].completedStoresCount ) :
|
|
837
1016
|
0,
|
|
838
1017
|
pendingByQueue: Number( pending ),
|
|
839
1018
|
pendingByUser:
|
|
840
1019
|
merge[i].pendingCount >= 0 ?
|
|
841
1020
|
Number( merge[i].pendingCount ) +
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
1021
|
+
( merge[i].clientAsignedCount ?
|
|
1022
|
+
Number( merge[i].clientAsignedCount ) :
|
|
1023
|
+
0 ) :
|
|
845
1024
|
0,
|
|
846
1025
|
totalCount: merge[i].totalFilesCount,
|
|
847
1026
|
queueName: merge[i].queueName,
|
|
848
|
-
isDraft: merge[i]
|
|
1027
|
+
isDraft: merge[i]?.isDrafted || false,
|
|
849
1028
|
isEnable:
|
|
850
1029
|
Number( pending ) > 0 ||
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1030
|
+
merge[i].isDrafted ||
|
|
1031
|
+
( merge[i].userAsignedCount && merge[i].userAsignedCount > 0 ) ||
|
|
1032
|
+
( merge[i].userInprogressCount && merge[i].userInprogressCount > 0 ) ?
|
|
1033
|
+
1 :
|
|
1034
|
+
0,
|
|
856
1035
|
completedRatio: merge[i].totalFilesCount ?
|
|
857
|
-
merge[i].
|
|
1036
|
+
merge[i].completedStoresCount ?
|
|
858
1037
|
Math.round(
|
|
859
|
-
( Number( merge[i].
|
|
860
|
-
|
|
861
|
-
|
|
1038
|
+
( Number( merge[i].completedStoresCount ) /
|
|
1039
|
+
Number( merge[i].totalFilesCount ) ) *
|
|
1040
|
+
100,
|
|
862
1041
|
) :
|
|
863
1042
|
0 :
|
|
864
1043
|
0,
|
|
865
1044
|
isAssigned:
|
|
866
|
-
merge[i].
|
|
1045
|
+
merge[i].userAsignedCount && merge[i].userAsignedCount > 0 ?
|
|
1046
|
+
true :
|
|
1047
|
+
false,
|
|
867
1048
|
Assignedcount:
|
|
868
|
-
merge[i].
|
|
869
|
-
merge[i].
|
|
1049
|
+
merge[i].userAsignedCount && merge[i].userAsignedCount > 0 ?
|
|
1050
|
+
merge[i].userAsignedCount :
|
|
870
1051
|
0,
|
|
871
1052
|
} );
|
|
872
1053
|
}
|
|
@@ -878,10 +1059,10 @@ export async function workSpace( req, res ) {
|
|
|
878
1059
|
exportdata.push( {
|
|
879
1060
|
'Client Name': element.clientName,
|
|
880
1061
|
'Client Id': element.clientId,
|
|
1062
|
+
'Completed stores Count': element.completedStoresCount,
|
|
881
1063
|
'Completed Percentage': element.completedRatio + ' %',
|
|
882
1064
|
'Pending Queue': element.pendingByQueue,
|
|
883
1065
|
'Pending User': element.pendingByUser,
|
|
884
|
-
'Completed': element.completedCount,
|
|
885
1066
|
'Draft': element.isDraft ? 1 : 0,
|
|
886
1067
|
'Assigned': element.Assignedcount,
|
|
887
1068
|
} );
|
|
@@ -890,7 +1071,7 @@ export async function workSpace( req, res ) {
|
|
|
890
1071
|
return;
|
|
891
1072
|
} else {
|
|
892
1073
|
return res.sendSuccess( {
|
|
893
|
-
result: temp,
|
|
1074
|
+
result: temp.sort( ( a, b ) => a.isEnable-b.isEnable ),
|
|
894
1075
|
count: count.length,
|
|
895
1076
|
totalStores: totalStores,
|
|
896
1077
|
} );
|
|
@@ -956,6 +1137,8 @@ export async function saveDraft( req, res ) {
|
|
|
956
1137
|
beforeCount: inputData.totalCount,
|
|
957
1138
|
afterCount: inputData.customerCount,
|
|
958
1139
|
auditId: inputData.auditId,
|
|
1140
|
+
moduleType: inputData.moduleType,
|
|
1141
|
+
zoneName: inputData.zoneName,
|
|
959
1142
|
},
|
|
960
1143
|
};
|
|
961
1144
|
await insertOpenSearchData( openSearch.activityLog, logData );
|
|
@@ -981,6 +1164,8 @@ export async function getDraftedData( req, res ) {
|
|
|
981
1164
|
fileDate: inputData.fileDate,
|
|
982
1165
|
storeId: inputData.storeId,
|
|
983
1166
|
userId: userId,
|
|
1167
|
+
moduleType: inputData.moduleType,
|
|
1168
|
+
zoneName: inputData.zoneName,
|
|
984
1169
|
};
|
|
985
1170
|
const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
|
|
986
1171
|
|
|
@@ -1006,7 +1191,7 @@ export async function save( req, res ) {
|
|
|
1006
1191
|
|
|
1007
1192
|
const inputData = req.body;
|
|
1008
1193
|
const params = {
|
|
1009
|
-
Key: `${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1194
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1010
1195
|
};
|
|
1011
1196
|
|
|
1012
1197
|
if ( inputData.auditType === 'ReAudit' ) {
|
|
@@ -1044,7 +1229,7 @@ export async function save( req, res ) {
|
|
|
1044
1229
|
|
|
1045
1230
|
const uploadDataParams = {
|
|
1046
1231
|
Bucket: bucket.auditUploadBucket,
|
|
1047
|
-
Key: `${inputData.storeId}/${inputData.fileDate}/`,
|
|
1232
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/`,
|
|
1048
1233
|
ContentType: 'application/json',
|
|
1049
1234
|
fileName: `${bucket.masterJsonFile}`,
|
|
1050
1235
|
body: JSON.stringify( tempObject ),
|
|
@@ -1053,7 +1238,7 @@ export async function save( req, res ) {
|
|
|
1053
1238
|
|
|
1054
1239
|
if ( mappingUpload?.statusCode ) {
|
|
1055
1240
|
logger.error( {
|
|
1056
|
-
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1241
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1057
1242
|
type: 'UPLOAD_ERROR',
|
|
1058
1243
|
} );
|
|
1059
1244
|
return res.sendError( mappingUpload, 500 );
|
|
@@ -1061,6 +1246,8 @@ export async function save( req, res ) {
|
|
|
1061
1246
|
|
|
1062
1247
|
let getUserAuditData = await findOneUserAudit( {
|
|
1063
1248
|
_id: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1249
|
+
moduleType: inputData.moduleType,
|
|
1250
|
+
zoneName: inputData.zoneName,
|
|
1064
1251
|
} );
|
|
1065
1252
|
const isoDate = getUserAuditData.startTime;
|
|
1066
1253
|
const currentTime = dayjs();
|
|
@@ -1097,15 +1284,20 @@ export async function save( req, res ) {
|
|
|
1097
1284
|
let storeAuditData = await findOneStoreAudit( {
|
|
1098
1285
|
storeId: inputData.storeId,
|
|
1099
1286
|
fileDate: inputData.fileDate,
|
|
1287
|
+
moduleType: inputData.moduleType,
|
|
1288
|
+
zoneName: inputData.zoneName,
|
|
1289
|
+
auditType: inputData.auditType,
|
|
1100
1290
|
} );
|
|
1101
1291
|
|
|
1102
1292
|
let clientData = await findClient( { clientId: storeConfig.clientId } );
|
|
1103
1293
|
|
|
1104
|
-
if (
|
|
1294
|
+
if (
|
|
1105
1295
|
( storeAuditData.beforeCount - inputData.customerCount ) /
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1296
|
+
storeAuditData.beforeCount <
|
|
1297
|
+
storeConfig.auditConfigs.ratio &&
|
|
1298
|
+
inputData.auditType == 'Audit' &&
|
|
1299
|
+
inputData.moduleType == 'traffic'
|
|
1300
|
+
) {
|
|
1109
1301
|
logger.info(
|
|
1110
1302
|
`Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
|
|
1111
1303
|
'Reaudit',
|
|
@@ -1121,32 +1313,52 @@ export async function save( req, res ) {
|
|
|
1121
1313
|
before_count: storeAuditData.beforeCount,
|
|
1122
1314
|
} ),
|
|
1123
1315
|
};
|
|
1124
|
-
const sqsQueue = await sendMessageToQueue(
|
|
1125
|
-
|
|
1316
|
+
const sqsQueue = await sendMessageToQueue(
|
|
1317
|
+
sqsProduceQueue.QueueUrl,
|
|
1318
|
+
sqsProduceQueue.MessageBody,
|
|
1319
|
+
);
|
|
1126
1320
|
|
|
1127
1321
|
if ( sqsQueue.statusCode ) {
|
|
1128
1322
|
logger.error( {
|
|
1129
|
-
error:
|
|
1323
|
+
error: `${sqsQueue}`,
|
|
1130
1324
|
type: 'UPLOAD_ERROR',
|
|
1131
1325
|
} );
|
|
1132
1326
|
return res.sendError( mappingUpload, 500 );
|
|
1133
1327
|
}
|
|
1134
1328
|
|
|
1135
|
-
await updateOneStoreAudit(
|
|
1329
|
+
await updateOneStoreAudit(
|
|
1330
|
+
{
|
|
1331
|
+
storeId: inputData.storeId,
|
|
1332
|
+
fileDate: inputData.fileDate,
|
|
1333
|
+
moduleType: inputData.moduleType,
|
|
1334
|
+
zoneName: inputData.zoneName,
|
|
1335
|
+
auditType: inputData.auditType,
|
|
1336
|
+
},
|
|
1136
1337
|
{
|
|
1137
1338
|
status: 'not_assign',
|
|
1138
1339
|
afterCount: inputData.customerCount,
|
|
1139
1340
|
auditType: 'ReAudit',
|
|
1140
1341
|
timeSpent: timeDifferenceInMinutes,
|
|
1141
|
-
}
|
|
1342
|
+
},
|
|
1343
|
+
);
|
|
1142
1344
|
} else {
|
|
1143
|
-
logger.info( 'Hit in Features', {
|
|
1144
|
-
|
|
1345
|
+
logger.info( 'Hit in Features', {
|
|
1346
|
+
data: _.omit( inputData, [ 'junk', 'employee', 'customer' ] ),
|
|
1347
|
+
} );
|
|
1348
|
+
await updateOneStoreAudit(
|
|
1349
|
+
{
|
|
1350
|
+
storeId: inputData.storeId,
|
|
1351
|
+
fileDate: inputData.fileDate,
|
|
1352
|
+
moduleType: inputData.moduleType,
|
|
1353
|
+
zoneName: inputData.zoneName,
|
|
1354
|
+
auditType: inputData.auditType,
|
|
1355
|
+
},
|
|
1145
1356
|
{
|
|
1146
1357
|
status: 'completed',
|
|
1147
1358
|
afterCount: inputData.customerCount,
|
|
1148
1359
|
timeSpent: timeDifferenceInMinutes,
|
|
1149
|
-
}
|
|
1360
|
+
},
|
|
1361
|
+
);
|
|
1150
1362
|
|
|
1151
1363
|
const sqsProduceQueue = {
|
|
1152
1364
|
QueueUrl: `${sqs.url}${sqs.feature}`,
|
|
@@ -1155,10 +1367,15 @@ export async function save( req, res ) {
|
|
|
1155
1367
|
store_id: inputData.storeId,
|
|
1156
1368
|
store_date: inputData.fileDate,
|
|
1157
1369
|
bucket_name: `${bucket.auditUploadBucket}`,
|
|
1370
|
+
zone_id: inputData.zoneName,
|
|
1371
|
+
process_type: 'audit',
|
|
1158
1372
|
} ),
|
|
1159
1373
|
};
|
|
1160
1374
|
logger.info( { sqsProduceQueue: sqsProduceQueue } );
|
|
1161
|
-
const sqsQueue = await sendMessageToQueue(
|
|
1375
|
+
const sqsQueue = await sendMessageToQueue(
|
|
1376
|
+
sqsProduceQueue.QueueUrl,
|
|
1377
|
+
sqsProduceQueue.MessageBody,
|
|
1378
|
+
);
|
|
1162
1379
|
logger.info( { sqsQueue: sqsQueue } );
|
|
1163
1380
|
}
|
|
1164
1381
|
|