tango-app-api-audit 3.4.68 → 3.4.69-beta.0
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/README.md +28 -28
- package/index.js +3 -1
- package/package.json +3 -3
- package/src/controllers/audit.controllers.js +303 -331
- package/src/controllers/eyeTestAudit.controllers.js +889 -0
- package/src/docs/eyeTestAudit.docs.js +163 -0
- package/src/dtos/eyeTestAudit.dtos.js +97 -0
- package/src/routes/eyeTestAudit.routes.js +18 -0
|
@@ -65,6 +65,7 @@ import { aggregateBinaryAudit } from '../service/binaryAudit.service.js';
|
|
|
65
65
|
import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
66
66
|
import { bulkWriteAuditUserWallet, createAuditUserWallet, findOneAuditUserWallet } from '../service/auditUserWallet.service.js';
|
|
67
67
|
import { updateOneAuditUsers } from '../service/auditUsers.service.js';
|
|
68
|
+
import { bulkUpdate, clearScroll, scrollResponse, searchOpenSearchData } from 'tango-app-api-middleware/src/utils/openSearch.js';
|
|
68
69
|
// import { aggregateAuditUsers } from '../service/auditUsers.service.js';
|
|
69
70
|
|
|
70
71
|
/* < -- *** Configuration *** --> */
|
|
@@ -104,7 +105,7 @@ export async function clients( req, res ) {
|
|
|
104
105
|
return res.sendSuccess( { result: getAuditClients, count: count.length } );
|
|
105
106
|
} catch ( error ) {
|
|
106
107
|
const err = error.message || 'Internal Server Error';
|
|
107
|
-
logger.
|
|
108
|
+
logger.error( { error: error, messgae: req.query, function: 'clients' } );
|
|
108
109
|
return res.sendError( err, 500 );
|
|
109
110
|
}
|
|
110
111
|
}
|
|
@@ -144,7 +145,7 @@ export async function auditStoreList( req, res ) {
|
|
|
144
145
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
145
146
|
} catch ( error ) {
|
|
146
147
|
const err = error.message || 'Internal Server Error';
|
|
147
|
-
logger.
|
|
148
|
+
logger.error( {
|
|
148
149
|
error: error,
|
|
149
150
|
messgae: req.body,
|
|
150
151
|
function: 'auditStoreList',
|
|
@@ -187,7 +188,7 @@ export async function auditUserList( req, res ) {
|
|
|
187
188
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
188
189
|
} catch ( error ) {
|
|
189
190
|
const err = error.message || 'Internal Server Error';
|
|
190
|
-
logger.
|
|
191
|
+
logger.error( {
|
|
191
192
|
error: error,
|
|
192
193
|
messgae: req.query,
|
|
193
194
|
function: 'auditUserList',
|
|
@@ -201,12 +202,11 @@ export async function auditUserList( req, res ) {
|
|
|
201
202
|
export async function getAuditFile( req, res ) {
|
|
202
203
|
try {
|
|
203
204
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
205
|
+
const url = JSON.parse( process.env.URL );
|
|
204
206
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
205
207
|
const inputData = req.query;
|
|
206
208
|
const previousDate = dayjs( new Date() ).subtract( 1, 'days' );
|
|
207
209
|
const data = await getDate( new Date( dayjs( previousDate ).format( 'YYYY-MM-DD' ) ), new Date() );
|
|
208
|
-
logger.info( { data: data, previousDate: previousDate, function: 'data', newDate: new Date() } );
|
|
209
|
-
logger.info( { userId: req.user._id, queueName: inputData.queueName, moduleType: inputData.moduleType } );
|
|
210
210
|
const start = data.start;
|
|
211
211
|
const end = data.end;
|
|
212
212
|
const fetchData = {};
|
|
@@ -233,7 +233,28 @@ export async function getAuditFile( req, res ) {
|
|
|
233
233
|
];
|
|
234
234
|
|
|
235
235
|
const userDetails = await aggregateUserAudit( userQuery );
|
|
236
|
-
|
|
236
|
+
let inserQuery = null;
|
|
237
|
+
if ( userDetails && userDetails.length > 0 ) {
|
|
238
|
+
inserQuery = [
|
|
239
|
+
{
|
|
240
|
+
$match: {
|
|
241
|
+
$and: [
|
|
242
|
+
{
|
|
243
|
+
fileDate: userDetails[0].fileDate,
|
|
244
|
+
storeId: userDetails[0].storeId,
|
|
245
|
+
moduleType: 'track',
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
$project: {
|
|
252
|
+
sqs: '$sqs.Body',
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
const auditInsertData = inserQuery? await aggregateUserAudit( inserQuery ): null;
|
|
237
258
|
const auditStatus =
|
|
238
259
|
userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
239
260
|
switch ( auditStatus ) {
|
|
@@ -259,6 +280,7 @@ export async function getAuditFile( req, res ) {
|
|
|
259
280
|
curr_date: userAssign[0].fileDate,
|
|
260
281
|
total_count: userAssign[0].fileCount,
|
|
261
282
|
zone_id: userAssign[0].zoneName,
|
|
283
|
+
index_name: auditInsertData[0]?.sqs?.index_name,
|
|
262
284
|
} ) :
|
|
263
285
|
( msg = {
|
|
264
286
|
store_id: userAssign[0].storeId,
|
|
@@ -266,6 +288,7 @@ export async function getAuditFile( req, res ) {
|
|
|
266
288
|
audit_type: userAssign[0].auditType,
|
|
267
289
|
total_count: userAssign[0].fileCount,
|
|
268
290
|
zone_id: userAssign[0].zoneName,
|
|
291
|
+
index_name: auditInsertData[0]?.sqs?.index_name,
|
|
269
292
|
} );
|
|
270
293
|
await updateOneAssignAudit(
|
|
271
294
|
{ _id: userAssign[0]._id },
|
|
@@ -362,7 +385,6 @@ export async function getAuditFile( req, res ) {
|
|
|
362
385
|
},
|
|
363
386
|
createdAt: new Date(),
|
|
364
387
|
};
|
|
365
|
-
logger.info( { logData: logData } );
|
|
366
388
|
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
367
389
|
}
|
|
368
390
|
const storeQuery = {
|
|
@@ -393,10 +415,11 @@ export async function getAuditFile( req, res ) {
|
|
|
393
415
|
audit_type: userDetails[0].auditType,
|
|
394
416
|
total_count: userDetails[0].beforeCount,
|
|
395
417
|
zone_id: userDetails[0].zoneName,
|
|
418
|
+
index_name: auditInsertData[0]?.sqs?.index_name,
|
|
396
419
|
};
|
|
397
420
|
break;
|
|
398
421
|
}
|
|
399
|
-
if ( msg.audit_type === 'ReAudit' ) {
|
|
422
|
+
if ( msg.audit_type === 'ReAudit' && msg.zone_id !== 'track' ) {
|
|
400
423
|
logger.info( 'Hit in user ReAudit', { inputData } );
|
|
401
424
|
let reauditInsert = {};
|
|
402
425
|
const [ filterData, auditImage ] = await Promise.all( [
|
|
@@ -502,32 +525,76 @@ export async function getAuditFile( req, res ) {
|
|
|
502
525
|
|
|
503
526
|
const files = [];
|
|
504
527
|
let insertData = {};
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
fetchData.
|
|
528
|
+
|
|
529
|
+
if ( inputData.moduleType !== 'track' ) {
|
|
530
|
+
fetchData.Bucket = bucket.auditInput; // need to change
|
|
531
|
+
fetchData.file_path = `${fileDate}/${storeId}/${msg.zone_id}/`;
|
|
532
|
+
if ( inputData.limit ) {
|
|
533
|
+
fetchData.MaxKeys = inputData.limit;
|
|
534
|
+
}
|
|
535
|
+
if ( inputData.nextId ) {
|
|
536
|
+
fetchData.ContinuationToken = decodeURIComponent( inputData.nextId );
|
|
537
|
+
}
|
|
509
538
|
}
|
|
510
|
-
|
|
511
|
-
|
|
539
|
+
|
|
540
|
+
const getQuery = {
|
|
541
|
+
size: inputData?.limit || 2,
|
|
542
|
+
_source: [ 'module', 'date', 'store_id', 'outputCluster', 'personPath', 'isEmployee' ], // Only fetch necessary fields
|
|
543
|
+
|
|
544
|
+
query: {
|
|
545
|
+
bool: {
|
|
546
|
+
must: [
|
|
547
|
+
{
|
|
548
|
+
term: { 'store_id.keyword': msg.store_id },
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
term: { isEmployee: false },
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
term: { 'date.keyword': msg.curr_date },
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
558
|
+
},
|
|
559
|
+
],
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
const list = msg.zone_id === 'track' ? inputData.nextId? await scrollResponse( inputData.nextId ):await searchOpenSearchData( msg.index_name, getQuery ): await listFileByPath( fetchData );
|
|
566
|
+
const folderPath = msg.zone_id === 'track' ? list?.body?.hits?.hits : list.data;
|
|
567
|
+
const nextQuery =msg.zone_id !== 'track' ? list.pageToken: '';
|
|
568
|
+
if ( msg.zone_id === 'track' ) {
|
|
569
|
+
if ( list?.body?.hits?.hits?.length ==0 ) {
|
|
570
|
+
await clearScroll( list?.body?._scroll_id );
|
|
571
|
+
}
|
|
512
572
|
}
|
|
513
|
-
const list = await listFileByPath( fetchData );
|
|
514
|
-
const folderPath = list.data;
|
|
515
|
-
const nextQuery = list.pageToken;
|
|
516
573
|
if ( folderPath?.length > 0 ) {
|
|
517
574
|
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
518
|
-
const img = folderPath[i].Key.split( '/' );
|
|
519
|
-
const image = img[3]
|
|
520
|
-
const indexes = image[0]
|
|
521
|
-
fetchData.file_path = folderPath[i].Key;
|
|
522
|
-
const data = await signedUrl( fetchData );
|
|
575
|
+
const img =msg.zone_id === 'track' ?folderPath[i]?._source?.personPath?.split( '/' ): folderPath[i].Key.split( '/' );
|
|
576
|
+
const image = img[3]?.split( '.' );
|
|
577
|
+
const indexes = msg.zone_id === 'track' ? folderPath[i]?._source?.outputCluster : image[0]?.split( '_' );
|
|
578
|
+
fetchData.file_path = msg.zone_id === 'track' ?folderPath[i]?._source?.personPath:folderPath[i].Key;
|
|
579
|
+
const data =msg.zone_id === 'track' ? `${url.trackInput}${folderPath[i]?._source?.personPath}` :await signedUrl( fetchData );
|
|
523
580
|
const mapimg = {
|
|
524
581
|
img_path: data,
|
|
525
|
-
img_name: indexes[1],
|
|
582
|
+
img_name: msg.zone_id === 'track' ?indexes: indexes[1],
|
|
526
583
|
img_id: image[0],
|
|
527
584
|
};
|
|
585
|
+
msg.zone_id === 'track' ? addUniqueFile( files, {
|
|
586
|
+
img_path: data,
|
|
587
|
+
img_name: msg.zone_id === 'track' ?indexes:indexes[1],
|
|
588
|
+
img_id: image[0],
|
|
589
|
+
selected: false,
|
|
590
|
+
dropped: false,
|
|
591
|
+
demographic: '',
|
|
592
|
+
count: 1,
|
|
593
|
+
mappedid: [ mapimg ],
|
|
594
|
+
} ):
|
|
528
595
|
files.push( {
|
|
529
596
|
img_path: data,
|
|
530
|
-
img_name: indexes[1],
|
|
597
|
+
img_name: msg.zone_id === 'track' ?indexes:indexes[1],
|
|
531
598
|
img_id: image[0],
|
|
532
599
|
selected: false,
|
|
533
600
|
dropped: false,
|
|
@@ -585,6 +652,9 @@ export async function getAuditFile( req, res ) {
|
|
|
585
652
|
} else {
|
|
586
653
|
insertData = userDetails[0];
|
|
587
654
|
}
|
|
655
|
+
} else if ( inputData.nextId !== '' && inputData.nextId !== null && inputData.nextId !== undefined && inputData.moduleType === 'track' ) {
|
|
656
|
+
list.body._scroll_id = '';
|
|
657
|
+
insertData = userDetails[0];
|
|
588
658
|
} else {
|
|
589
659
|
logger.error( {
|
|
590
660
|
error: { folderPath: folderPath, nextQuery: nextQuery },
|
|
@@ -593,7 +663,6 @@ export async function getAuditFile( req, res ) {
|
|
|
593
663
|
} );
|
|
594
664
|
return res.sendError( 'Bucket is Empty', 204 );
|
|
595
665
|
}
|
|
596
|
-
const userdata = await findOneUser( { _id: insertData.userId } );
|
|
597
666
|
const storeQuery = {
|
|
598
667
|
storeId: storeId,
|
|
599
668
|
};
|
|
@@ -604,8 +673,8 @@ export async function getAuditFile( req, res ) {
|
|
|
604
673
|
const storeInfo = await findOneStore( storeQuery, storeFields );
|
|
605
674
|
if ( inputData.nextId ) {
|
|
606
675
|
const logData = {
|
|
607
|
-
userId:
|
|
608
|
-
userName:
|
|
676
|
+
userId: req?.user?._id,
|
|
677
|
+
userName: req?.user?.userName,
|
|
609
678
|
logType: 'audit',
|
|
610
679
|
logSubType: 'auditStart',
|
|
611
680
|
logData: {
|
|
@@ -638,7 +707,7 @@ export async function getAuditFile( req, res ) {
|
|
|
638
707
|
userId: insertData.userId,
|
|
639
708
|
zoneName: msg.zone_id,
|
|
640
709
|
moduleType: inputData.moduleType,
|
|
641
|
-
nextToken: nextQuery ? encodeURIComponent( nextQuery ) : null,
|
|
710
|
+
nextToken: msg.zone_id === 'track' ? list?.body?._scroll_id : nextQuery ? encodeURIComponent( nextQuery ) : null,
|
|
642
711
|
},
|
|
643
712
|
isDraft: insertData.isDraft,
|
|
644
713
|
} );
|
|
@@ -651,6 +720,12 @@ export async function getAuditFile( req, res ) {
|
|
|
651
720
|
return res.sendError( error, 500 );
|
|
652
721
|
}
|
|
653
722
|
}
|
|
723
|
+
function addUniqueFile( files, newFile ) {
|
|
724
|
+
const exists = files.some( ( file ) => file.img_name === newFile.img_name );
|
|
725
|
+
if ( !exists ) {
|
|
726
|
+
files.push( newFile );
|
|
727
|
+
}
|
|
728
|
+
}
|
|
654
729
|
|
|
655
730
|
export async function getFilterData( msg ) {
|
|
656
731
|
try {
|
|
@@ -719,7 +794,6 @@ export async function getAuditImage( msg ) {
|
|
|
719
794
|
img_name: indexes[1],
|
|
720
795
|
img_id: image[0],
|
|
721
796
|
selected: false,
|
|
722
|
-
// demographic: '',
|
|
723
797
|
dropped: false,
|
|
724
798
|
count: 1,
|
|
725
799
|
mappedid: [ mapimg ],
|
|
@@ -782,7 +856,11 @@ export async function workSpace( req, res ) {
|
|
|
782
856
|
clientId: 1,
|
|
783
857
|
queueName: {
|
|
784
858
|
$cond: [
|
|
785
|
-
{ $eq: [ inputData.moduleType, 'zone' ] }, '$auditConfigs.zoneQueueName',
|
|
859
|
+
{ $eq: [ inputData.moduleType, 'zone' ] }, '$auditConfigs.zoneQueueName', {
|
|
860
|
+
$cond: [
|
|
861
|
+
{ $eq: [ inputData.moduleType, 'track' ] }, '$auditConfigs.trackQueueName', '$auditConfigs.trafficQueueName',
|
|
862
|
+
],
|
|
863
|
+
},
|
|
786
864
|
],
|
|
787
865
|
},
|
|
788
866
|
},
|
|
@@ -1272,77 +1350,195 @@ export async function save( req, res ) {
|
|
|
1272
1350
|
moduleType: inputData.moduleType,
|
|
1273
1351
|
zoneName: inputData.zoneName,
|
|
1274
1352
|
} );
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
// type: 'DATABASE_RECORD_NOTFOUND',
|
|
1280
|
-
// } );
|
|
1281
|
-
// return res.sendError( storeAuditData, 204 );
|
|
1282
|
-
// }
|
|
1283
|
-
const params = {
|
|
1284
|
-
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1285
|
-
};
|
|
1353
|
+
if ( inputData.moduleType !=='track' ) {
|
|
1354
|
+
const params = {
|
|
1355
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1356
|
+
};
|
|
1286
1357
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1358
|
+
if ( inputData.auditType === 'ReAudit' ) {
|
|
1359
|
+
params.Bucket = bucket.auditUploadBucket;
|
|
1360
|
+
} else {
|
|
1361
|
+
params.Bucket = bucket.masterJson;
|
|
1362
|
+
}
|
|
1363
|
+
const fileData = await getJsonFileData( params );
|
|
1293
1364
|
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1365
|
+
if ( fileData?.statusCode ) {
|
|
1366
|
+
logger.error( {
|
|
1367
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1368
|
+
type: 'UPLOAD_ERROR',
|
|
1369
|
+
} );
|
|
1370
|
+
return res.sendError( fileData, 500 );
|
|
1371
|
+
}
|
|
1301
1372
|
|
|
1302
|
-
|
|
1373
|
+
const masterJsonData = JSON.parse( fileData.toString( 'utf-8' ) );
|
|
1303
1374
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1375
|
+
const [ G20000, B20000, E0 ] = await Promise.all( [
|
|
1376
|
+
splitG20000( masterJsonData.person_data ),
|
|
1377
|
+
splitB20000( masterJsonData.person_data ),
|
|
1378
|
+
splitE0( masterJsonData.person_data ),
|
|
1379
|
+
] );
|
|
1309
1380
|
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1381
|
+
const [ mappingData ] = await Promise.all( [
|
|
1382
|
+
mapEmployee( B20000, inputData.employee ),
|
|
1383
|
+
mapJunk( B20000, inputData.junk ),
|
|
1384
|
+
mapCustomer( B20000, inputData.customer ),
|
|
1385
|
+
] );
|
|
1315
1386
|
|
|
1316
|
-
|
|
1387
|
+
const tempData = _.sortBy( [ ...mappingData, ...G20000, ...E0 ], 'index' );
|
|
1317
1388
|
|
|
1318
|
-
|
|
1389
|
+
const tempObject = { person_data: tempData };
|
|
1319
1390
|
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1391
|
+
const uploadDataParams = {
|
|
1392
|
+
Bucket: bucket.auditUploadBucket,
|
|
1393
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/`,
|
|
1394
|
+
ContentType: 'application/json',
|
|
1395
|
+
fileName: `${bucket.masterJsonFile}`,
|
|
1396
|
+
body: JSON.stringify( tempObject ),
|
|
1397
|
+
};
|
|
1398
|
+
const mappingUpload = await fileUpload( uploadDataParams );
|
|
1328
1399
|
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1400
|
+
if ( mappingUpload?.statusCode ) {
|
|
1401
|
+
logger.error( {
|
|
1402
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1403
|
+
type: 'UPLOAD_ERROR',
|
|
1404
|
+
} );
|
|
1405
|
+
return res.sendError( mappingUpload, 500 );
|
|
1406
|
+
}
|
|
1407
|
+
} else {
|
|
1408
|
+
// Junk Mapping
|
|
1409
|
+
if ( inputData.junkCount >0 ) {
|
|
1410
|
+
const chunkedJunkMappingData = await filteredMap( inputData.junk );
|
|
1411
|
+
logger.info( { chunkedJunkMappingData: chunkedJunkMappingData } );
|
|
1412
|
+
const getQuery = {
|
|
1413
|
+
size: 10000,
|
|
1414
|
+
_source: false, // do not fetch full source
|
|
1415
|
+
stored_fields: [], // exclude all stored fields
|
|
1416
|
+
query: {
|
|
1417
|
+
bool: {
|
|
1418
|
+
must: [
|
|
1419
|
+
{
|
|
1420
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
1421
|
+
},
|
|
1422
|
+
{
|
|
1423
|
+
terms: { outputCluster: chunkedJunkMappingData },
|
|
1424
|
+
},
|
|
1425
|
+
{
|
|
1426
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
1427
|
+
},
|
|
1428
|
+
{
|
|
1429
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
1430
|
+
},
|
|
1431
|
+
],
|
|
1432
|
+
},
|
|
1433
|
+
},
|
|
1336
1434
|
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1435
|
+
};
|
|
1436
|
+
const getId = await getOpenSearchData( 'tracker_process', getQuery );
|
|
1437
|
+
const ids = getId?.body?.hits?.total?.value || null;
|
|
1438
|
+
if ( ids ) {
|
|
1439
|
+
const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
|
|
1440
|
+
const updatedField = { isJunk: true }; // your field updates
|
|
1441
|
+
const body = temp.flatMap( ( id ) => [
|
|
1442
|
+
{ update: { _index: 'tracker_process', _id: id } },
|
|
1443
|
+
{ doc: updatedField },
|
|
1444
|
+
] );
|
|
1445
|
+
const re= await bulkUpdate( body );
|
|
1446
|
+
logger.info( { getId: getId, re: re } );
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
// Employee Mapping
|
|
1451
|
+
if ( inputData.employeeCount >0 ) {
|
|
1452
|
+
const chunkedEmpMappingData = await filteredMap( inputData.employee );
|
|
1453
|
+
logger.info( { chunkedEmpMappingData: chunkedEmpMappingData } );
|
|
1454
|
+
const getQuery = {
|
|
1455
|
+
size: 10000,
|
|
1456
|
+
_source: false, // do not fetch full source
|
|
1457
|
+
stored_fields: [], // exclude all stored fields
|
|
1458
|
+
query: {
|
|
1459
|
+
bool: {
|
|
1460
|
+
must: [
|
|
1461
|
+
{
|
|
1462
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
1463
|
+
},
|
|
1464
|
+
{
|
|
1465
|
+
terms: { outputCluster: chunkedEmpMappingData },
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
1469
|
+
},
|
|
1470
|
+
{
|
|
1471
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
1472
|
+
},
|
|
1473
|
+
],
|
|
1474
|
+
},
|
|
1475
|
+
},
|
|
1476
|
+
|
|
1477
|
+
};
|
|
1478
|
+
const getId = await getOpenSearchData( 'tracker_process', getQuery );
|
|
1479
|
+
const ids = getId?.body?.hits?.total?.value || null;
|
|
1480
|
+
if ( ids ) {
|
|
1481
|
+
const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
|
|
1482
|
+
const updatedField = { isEmployee: true }; // your field updates
|
|
1483
|
+
const body = temp.flatMap( ( id ) => [
|
|
1484
|
+
{ update: { _index: 'tracker_process', _id: id } },
|
|
1485
|
+
{ doc: updatedField },
|
|
1486
|
+
] );
|
|
1487
|
+
const re= await bulkUpdate( body );
|
|
1488
|
+
logger.info( { getId: getId, re: re } );
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
// Customer Mapping
|
|
1493
|
+
if ( inputData?.customer?.length > 0 ) {
|
|
1494
|
+
logger.info( { lenght: inputData?.customer?.length } );
|
|
1495
|
+
const filterCustomerData = await filteredCustomerMap( inputData.customer );
|
|
1496
|
+
const chunkedMappingData = await chunkArray( filterCustomerData, 10 );
|
|
1497
|
+
|
|
1498
|
+
chunkedMappingData.map( async ( chunk ) => {
|
|
1499
|
+
logger.info( { chunk: chunk } );
|
|
1500
|
+
|
|
1501
|
+
chunk.map( async ( item ) => {
|
|
1502
|
+
const imgName= item.img_name;
|
|
1503
|
+
const mappedId= item.mappedid.map( ( m ) => m.img_name );
|
|
1504
|
+
const searchQuery = {
|
|
1505
|
+
size: 10000,
|
|
1506
|
+
_source: false, // do not fetch full source
|
|
1507
|
+
stored_fields: [], // exclude all stored fields
|
|
1508
|
+
query: {
|
|
1509
|
+
bool: {
|
|
1510
|
+
must: [
|
|
1511
|
+
{
|
|
1512
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
1513
|
+
},
|
|
1514
|
+
{
|
|
1515
|
+
terms: { outputCluster: mappedId },
|
|
1516
|
+
},
|
|
1517
|
+
{
|
|
1518
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
1522
|
+
},
|
|
1523
|
+
],
|
|
1524
|
+
},
|
|
1525
|
+
},
|
|
1526
|
+
|
|
1527
|
+
};
|
|
1528
|
+
const getData =await getOpenSearchData( 'tracker_process', searchQuery );
|
|
1529
|
+
if ( getData?.body?.hits?.hits?.length > 0 ) {
|
|
1530
|
+
const temp = getData?.body?.hits?.hits?.map( ( item ) => item._id );
|
|
1531
|
+
const body = temp.flatMap( ( id ) => [
|
|
1532
|
+
{ update: { _index: 'tracker_process', _id: id } },
|
|
1533
|
+
{ doc: { outputCluster: imgName } },
|
|
1534
|
+
] );
|
|
1535
|
+
const re= await bulkUpdate( body );
|
|
1536
|
+
logger.info( { re: re } );
|
|
1537
|
+
}
|
|
1538
|
+
} );
|
|
1539
|
+
} );
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1346
1542
|
|
|
1347
1543
|
await updateOneUserAudit(
|
|
1348
1544
|
{ _id: new mongoose.Types.ObjectId( inputData.auditId ) },
|
|
@@ -1466,7 +1662,6 @@ export async function save( req, res ) {
|
|
|
1466
1662
|
fileDate: inputData.fileDate,
|
|
1467
1663
|
moduleType: inputData.moduleType,
|
|
1468
1664
|
zoneName: inputData.zoneName,
|
|
1469
|
-
// auditType: inputData.auditType,
|
|
1470
1665
|
},
|
|
1471
1666
|
{
|
|
1472
1667
|
status: 'completed',
|
|
@@ -1500,6 +1695,15 @@ export async function save( req, res ) {
|
|
|
1500
1695
|
}
|
|
1501
1696
|
}
|
|
1502
1697
|
|
|
1698
|
+
const filteredMap = async ( data ) => {
|
|
1699
|
+
const temp = data.map( ( item ) => item.img_name );
|
|
1700
|
+
return temp;
|
|
1701
|
+
};
|
|
1702
|
+
|
|
1703
|
+
const filteredCustomerMap = async ( data ) => {
|
|
1704
|
+
return data.filter( ( map ) => map.count >= 1 );
|
|
1705
|
+
};
|
|
1706
|
+
|
|
1503
1707
|
/* < -- *** Audit Metrics *** --> */
|
|
1504
1708
|
|
|
1505
1709
|
export async function userAuditHistory( req, res ) {
|
|
@@ -1968,7 +2172,6 @@ export async function clientMetrics( req, res ) {
|
|
|
1968
2172
|
);
|
|
1969
2173
|
}
|
|
1970
2174
|
|
|
1971
|
-
logger.info( { query: query } );
|
|
1972
2175
|
const result = await aggregateAuditStoreData( query );
|
|
1973
2176
|
if ( result.length == 0 ) {
|
|
1974
2177
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -1980,7 +2183,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1980
2183
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1981
2184
|
} catch ( error ) {
|
|
1982
2185
|
const err = error.error || 'Internal Server Error';
|
|
1983
|
-
logger.
|
|
2186
|
+
logger.error( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
1984
2187
|
return res.sendError( err, 500 );
|
|
1985
2188
|
}
|
|
1986
2189
|
}
|
|
@@ -2234,8 +2437,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2234
2437
|
'File Date': element.fileDate,
|
|
2235
2438
|
'Store Name': element.storeName,
|
|
2236
2439
|
'Store ID': element.storeId,
|
|
2237
|
-
// 'Client Id': element.clientId,
|
|
2238
|
-
// 'Client Name': element.clientName,
|
|
2239
2440
|
'Product Type': element.moduleType,
|
|
2240
2441
|
'Zone Name': element.zoneName,
|
|
2241
2442
|
'User Name': element.userName,
|
|
@@ -2252,8 +2453,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2252
2453
|
'File Date': element.fileDate,
|
|
2253
2454
|
'Store Name': element.storeName,
|
|
2254
2455
|
'Store ID': element.storeId,
|
|
2255
|
-
// 'Client Id': element.clientId,
|
|
2256
|
-
// 'Client Name': element.clientName,
|
|
2257
2456
|
'Product Type': element.moduleType,
|
|
2258
2457
|
'User Name': element.userName,
|
|
2259
2458
|
'User Email': element.userEmail,
|
|
@@ -2307,7 +2506,6 @@ export async function userMetrics( req, res ) {
|
|
|
2307
2506
|
}
|
|
2308
2507
|
if ( inputData?.filterByUser?.length > 0 ) {
|
|
2309
2508
|
const temp = inputData.filterByUser.map( ( item ) => new mongoose.Types.ObjectId( item ) );
|
|
2310
|
-
logger.info( { temp: temp } );
|
|
2311
2509
|
filter.push(
|
|
2312
2510
|
{ userId: { $in: temp } },
|
|
2313
2511
|
);
|
|
@@ -3514,7 +3712,6 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3514
3712
|
{ createdAt: -1 },
|
|
3515
3713
|
);
|
|
3516
3714
|
const latestTraxDate = geTraxData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
|
|
3517
|
-
logger.info( { geTraxData: geTraxData } );
|
|
3518
3715
|
|
|
3519
3716
|
const query = [
|
|
3520
3717
|
{
|
|
@@ -3720,97 +3917,15 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3720
3917
|
},
|
|
3721
3918
|
},
|
|
3722
3919
|
];
|
|
3723
|
-
|
|
3724
|
-
// {
|
|
3725
|
-
// $match: {
|
|
3726
|
-
// fileDate: { $eq: latestDate },
|
|
3727
|
-
// },
|
|
3728
|
-
// },
|
|
3729
|
-
// {
|
|
3730
|
-
// $project: {
|
|
3731
|
-
// inprogressAuditCount: {
|
|
3732
|
-
// $cond: [
|
|
3733
|
-
// { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
|
|
3734
|
-
// ],
|
|
3735
|
-
// },
|
|
3736
|
-
// inprogressZoneCount: { $cond: [
|
|
3737
|
-
// { $and: [ { $eq: [ '$moduleType', 'zone' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3738
|
-
// ] },
|
|
3739
|
-
// inprogressTrafficCount: { $cond: [
|
|
3740
|
-
// { $and: [ { $eq: [ '$moduleType', 'traffic' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3741
|
-
// ] },
|
|
3742
|
-
|
|
3743
|
-
// },
|
|
3744
|
-
// },
|
|
3745
|
-
// {
|
|
3746
|
-
// $group: {
|
|
3747
|
-
// _id: null,
|
|
3748
|
-
// inprogressAuditCount: { $sum: '$inprogressAuditCount' },
|
|
3749
|
-
// inprogressZoneCount: { $sum: '$inprogressZoneCount' },
|
|
3750
|
-
// inprogressTrafficCount: { $sum: '$inprogressTrafficCount' },
|
|
3751
|
-
|
|
3752
|
-
// },
|
|
3753
|
-
// },
|
|
3754
|
-
// {
|
|
3755
|
-
// $project: {
|
|
3756
|
-
// _id: 0,
|
|
3757
|
-
// inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
|
|
3758
|
-
// inprogressZoneCount: { $ifNull: [ '$inprogressZoneCount', 0 ] },
|
|
3759
|
-
// inprogressTrafficCount: { $ifNull: [ '$inprogressTrafficCount', 0 ] },
|
|
3760
|
-
// },
|
|
3761
|
-
// },
|
|
3762
|
-
// ];
|
|
3763
|
-
// const mappingInprogressCount=[
|
|
3764
|
-
// {
|
|
3765
|
-
// $match: {
|
|
3766
|
-
// fileDate: { $eq: latestDate },
|
|
3767
|
-
// },
|
|
3768
|
-
// },
|
|
3769
|
-
// {
|
|
3770
|
-
// $project: {
|
|
3771
|
-
// inprogressAuditCount: {
|
|
3772
|
-
// $cond: [
|
|
3773
|
-
// { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
|
|
3774
|
-
// ],
|
|
3775
|
-
// },
|
|
3776
|
-
// inprogressZoneCount: { $cond: [
|
|
3777
|
-
// { $and: [ { $eq: [ '$moduleType', 'zone' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3778
|
-
// ] },
|
|
3779
|
-
// inprogressTrafficCount: { $cond: [
|
|
3780
|
-
// { $and: [ { $eq: [ '$moduleType', 'traffic' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3781
|
-
// ] },
|
|
3782
|
-
|
|
3783
|
-
// },
|
|
3784
|
-
// },
|
|
3785
|
-
// {
|
|
3786
|
-
// $group: {
|
|
3787
|
-
// _id: null,
|
|
3788
|
-
// inprogressAuditCount: { $sum: '$inprogressAuditCount' },
|
|
3789
|
-
// inprogressZoneCount: { $sum: '$inprogressZoneCount' },
|
|
3790
|
-
// inprogressTrafficCount: { $sum: '$inprogressTrafficCount' },
|
|
3791
|
-
|
|
3792
|
-
// },
|
|
3793
|
-
// },
|
|
3794
|
-
// {
|
|
3795
|
-
// $project: {
|
|
3796
|
-
// _id: 0,
|
|
3797
|
-
// inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
|
|
3798
|
-
// inprogressZoneCount: { $ifNull: [ '$inprogressZoneCount', 0 ] },
|
|
3799
|
-
// inprogressTrafficCount: { $ifNull: [ '$inprogressTrafficCount', 0 ] },
|
|
3800
|
-
// },
|
|
3801
|
-
// },
|
|
3802
|
-
// ];
|
|
3920
|
+
|
|
3803
3921
|
const getTotalcount = await aggregateAuditStoreData( query );
|
|
3804
3922
|
const getTotalTraxAudit = await aggregateTraxAuditData( traxQuery );
|
|
3805
3923
|
const getInprogressCount = await aggregateStoreAudit( inprogressCount );
|
|
3806
3924
|
const getBinaryInprogressCount = await aggregateBinaryAudit( binaryInprogressCount );
|
|
3807
3925
|
const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3808
|
-
logger.info( { getMappingInprogressCount: getMappingInprogressCount } );
|
|
3809
|
-
// const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3810
3926
|
if ( getTotalcount.length == 0 && getTotalTraxAudit.length == 0 ) {
|
|
3811
3927
|
return res.sendError( 'No Data Found', 204 );
|
|
3812
3928
|
}
|
|
3813
|
-
logger.info( { getTotalTraxAudit: getTotalTraxAudit } );
|
|
3814
3929
|
if ( getInprogressCount.length > 0 ) {
|
|
3815
3930
|
notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount > getInprogressCount[0]?.inprogressAuditCount ? getTotalcount[0].totalAuditCount - getInprogressCount[0]?.inprogressAuditCount : 0;
|
|
3816
3931
|
notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount > getInprogressCount[0]?.inprogressZoneCount ? getTotalcount[0].totalZoneCount - getInprogressCount[0]?.inprogressZoneCount : 0;
|
|
@@ -3858,11 +3973,9 @@ export async function auditImages( req, res ) {
|
|
|
3858
3973
|
|
|
3859
3974
|
if ( inputData.export == true ) {
|
|
3860
3975
|
auditImageDownload = await zipDownloadImage( auditImageBC );
|
|
3861
|
-
// Set response headers for the zip file
|
|
3862
3976
|
res.set( 'Content-Type', 'application/zip' );
|
|
3863
3977
|
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
3864
3978
|
|
|
3865
|
-
// Send the zip file as the API response
|
|
3866
3979
|
return res.send( auditImageDownload );
|
|
3867
3980
|
}
|
|
3868
3981
|
res.sendSuccess( { result: auditImageBC } );
|
|
@@ -3879,12 +3992,10 @@ export async function auditImages( req, res ) {
|
|
|
3879
3992
|
}
|
|
3880
3993
|
|
|
3881
3994
|
const reauditImg = await getReauditImg( filterData, auditImageAC );
|
|
3882
|
-
logger.info( { reauditImg: reauditImg } );
|
|
3883
3995
|
if ( reauditImg?.length == 0 ) {
|
|
3884
3996
|
return res.sendError( 'No Data Found', 204 );
|
|
3885
3997
|
}
|
|
3886
3998
|
|
|
3887
|
-
logger.info( { auditImageAC: auditImageAC, filterData: filterData, reauditImg: reauditImg } );
|
|
3888
3999
|
if ( inputData.export == true ) {
|
|
3889
4000
|
auditImageDownload = await zipDownloadImage( reauditImg );
|
|
3890
4001
|
// Set response headers for the zip file
|
|
@@ -3900,12 +4011,9 @@ export async function auditImages( req, res ) {
|
|
|
3900
4011
|
res.sendError( 'No Data Found', 204 );
|
|
3901
4012
|
break;
|
|
3902
4013
|
}
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
// return res.sendSuccess( { result: inputData } );
|
|
3906
4014
|
} catch ( error ) {
|
|
3907
4015
|
const err = error.message || 'Internal Server Error';
|
|
3908
|
-
logger.
|
|
4016
|
+
logger.error( { error: error, message: req.body, function: 'auditImages' } );
|
|
3909
4017
|
return res.sendError( err, 500 );
|
|
3910
4018
|
}
|
|
3911
4019
|
}
|
|
@@ -3924,7 +4032,7 @@ export async function getUserCredit( req, res ) {
|
|
|
3924
4032
|
return res.sendSuccess( { result: getWallet, isAuditUser: true } );
|
|
3925
4033
|
} catch ( error ) {
|
|
3926
4034
|
const err = error.message || 'Internal Server Error';
|
|
3927
|
-
logger.
|
|
4035
|
+
logger.error( { error: error, function: 'getUserCredit' } );
|
|
3928
4036
|
return res.sendError( err, 500 );
|
|
3929
4037
|
}
|
|
3930
4038
|
}
|
|
@@ -3948,7 +4056,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3948
4056
|
|
|
3949
4057
|
// Calculate the difference in days
|
|
3950
4058
|
const differenceInDays = ( yesterday.getDate() - firstDateOfMonth.getDate() );
|
|
3951
|
-
logger.info( { differenceInDays: differenceInDays } );
|
|
3952
4059
|
|
|
3953
4060
|
const auditUserQuery=[
|
|
3954
4061
|
{
|
|
@@ -4110,7 +4217,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4110
4217
|
return res.sendError( 'No Data Found', 204 );
|
|
4111
4218
|
}
|
|
4112
4219
|
const minimumTarget =userCount[0]?.userCount?.length !== 0 && userCount[0]?.filesCount !==0 ? Math.floor( userCount[0].filesCount/userCount[0].userCount.length ) : 0;
|
|
4113
|
-
logger.info( { bc: userWallet?.beforeCountCredit, ac: userWallet?.afterCountCredit } );
|
|
4114
4220
|
const beforeCreditCal = userWallet?.beforeCountCredit/minimumTarget;
|
|
4115
4221
|
const afterCountCredit = userWallet?.afterCountCredit;
|
|
4116
4222
|
const filter = [
|
|
@@ -4415,7 +4521,7 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4415
4521
|
}
|
|
4416
4522
|
} catch ( error ) {
|
|
4417
4523
|
const err = error.message || 'Internal Server Error';
|
|
4418
|
-
logger.
|
|
4524
|
+
logger.error( { error: error, message: req.body, function: 'getUserAuditCount' } );
|
|
4419
4525
|
return res.sendError( err, 500 );
|
|
4420
4526
|
}
|
|
4421
4527
|
}
|
|
@@ -4428,89 +4534,11 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4428
4534
|
yesterday.setDate( today.getDate() - 1 );
|
|
4429
4535
|
let firstDayOfMonth = new Date( yesterday.getFullYear(), today.getMonth(), 1 );
|
|
4430
4536
|
const previousDate = dayjs( new Date() ).subtract( 1, 'days' );
|
|
4431
|
-
// let firstDayOfMonth = new Date( previousDate.getFullYear(), previousDate.getMonth(), 1 );
|
|
4432
|
-
logger.info( { previousDate: previousDate, firstDayOfMonth: firstDayOfMonth } );
|
|
4433
4537
|
const dateRange = await getDate( firstDayOfMonth, new Date( dayjs( previousDate ).format( 'YYYY-MM-DD' ) ) );
|
|
4434
|
-
logger.info( { dateRange: dateRange } );
|
|
4435
4538
|
const configTimeSpentSec = userWallet.minTimeSpentSec; // 18000;
|
|
4436
4539
|
const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
|
|
4437
4540
|
const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
|
|
4438
4541
|
const reduce = userWallet.reductionPerc; // 0.05;
|
|
4439
|
-
// const userCountQuery= [
|
|
4440
|
-
// {
|
|
4441
|
-
// $match: {
|
|
4442
|
-
// $and: [
|
|
4443
|
-
// {
|
|
4444
|
-
// $match: {
|
|
4445
|
-
// fileDateISO: { $gte: dateRange?.start },
|
|
4446
|
-
// fileDateISO: { $gte: dateRange?.start },
|
|
4447
|
-
// },
|
|
4448
|
-
// },
|
|
4449
|
-
// ],
|
|
4450
|
-
// },
|
|
4451
|
-
// },
|
|
4452
|
-
// {
|
|
4453
|
-
// $project: {
|
|
4454
|
-
|
|
4455
|
-
// trafficUserCount: { $cond: [
|
|
4456
|
-
// { $eq: [ '$moduleType', 'traffic' ] }, '$userId', '$$REMOVE',
|
|
4457
|
-
// ] },
|
|
4458
|
-
// zoneUserCount: { $cond: [
|
|
4459
|
-
// { $eq: [ '$moduleType', 'zone' ] }, '$userId', '$$REMOVE',
|
|
4460
|
-
// ] },
|
|
4461
|
-
|
|
4462
|
-
// },
|
|
4463
|
-
// },
|
|
4464
|
-
// {
|
|
4465
|
-
// $group: {
|
|
4466
|
-
// _id: '$moduleType',
|
|
4467
|
-
// trafficUserCount: { $addToSet: '$trafficUserCount' },
|
|
4468
|
-
// zoneUserCount: { $addToSet: '$zoneUserCount' },
|
|
4469
|
-
// },
|
|
4470
|
-
// },
|
|
4471
|
-
// ];
|
|
4472
|
-
|
|
4473
|
-
// const storeDataQuery= [
|
|
4474
|
-
// {
|
|
4475
|
-
// $match: {
|
|
4476
|
-
// fileDate: { $eq: fileDate },
|
|
4477
|
-
// },
|
|
4478
|
-
// },
|
|
4479
|
-
// {
|
|
4480
|
-
// $project: {
|
|
4481
|
-
|
|
4482
|
-
// trafficFilesCount: { $cond: [
|
|
4483
|
-
// { $eq: [ '$moduleType', 'traffic' ] }, '$totalFilesCount', '$$REMOVE',
|
|
4484
|
-
// ] },
|
|
4485
|
-
// zoneFilesCount: { $cond: [
|
|
4486
|
-
// { $eq: [ '$moduleType', 'zone' ] }, '$totalFilesCount', '$$REMOVE',
|
|
4487
|
-
// ] },
|
|
4488
|
-
|
|
4489
|
-
// },
|
|
4490
|
-
// },
|
|
4491
|
-
// {
|
|
4492
|
-
// $group: {
|
|
4493
|
-
// _id: '$moduleType',
|
|
4494
|
-
// trafficFilesCount: { $sum: '$trafficFilesCount' },
|
|
4495
|
-
// zoneFilesCount: { $sum: '$zoneFilesCount' },
|
|
4496
|
-
// },
|
|
4497
|
-
// },
|
|
4498
|
-
// {
|
|
4499
|
-
// $project: {
|
|
4500
|
-
// _id: 0,
|
|
4501
|
-
// trafficFilesCount: { $ifNull: [ '$trafficFilesCount', 0 ] },
|
|
4502
|
-
// zoneFilesCount: { $ifNull: [ '$zoneFilesCount', 0 ] },
|
|
4503
|
-
// },
|
|
4504
|
-
// },
|
|
4505
|
-
// ];
|
|
4506
|
-
// const userCount = await aggregateUserAuditCount( userCountQuery );
|
|
4507
|
-
|
|
4508
|
-
// const totalStoreData = await aggregateAuditStoreData( storeDataQuery );
|
|
4509
|
-
// if ( userCount?.length == 0 || totalStoreData?.length == 0 ) {
|
|
4510
|
-
// return res.sendError( 'No Data Found', 204 );
|
|
4511
|
-
// }
|
|
4512
|
-
// const zoneMinimumTarget =userCount[0]?.zoneUserCount?.length !== 0 && totalStoreData[0]?.zoneFilesCount !==0 ? Math.floor( totalStoreData[0].zoneFilesCount/userCount[0].zoneUserCount.length ) : 0;
|
|
4513
|
-
// const trafficMinimumTarget =userCount[0]?.trafficUserCount?.length !== 0 && totalStoreData[0]?.trafficFilesCount !==0 ? Math.floor( totalStoreData[0].trafficFilesCount/userCount[0].trafficUserCount.length ) : 0;
|
|
4514
4542
|
const query = [
|
|
4515
4543
|
{
|
|
4516
4544
|
$match: {
|
|
@@ -4523,9 +4551,6 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4523
4551
|
],
|
|
4524
4552
|
},
|
|
4525
4553
|
},
|
|
4526
|
-
// {
|
|
4527
|
-
// $set: { minimumTarget: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, trafficMinimumTarget, zoneMinimumTarget ] } },
|
|
4528
|
-
// },
|
|
4529
4554
|
{
|
|
4530
4555
|
$project: {
|
|
4531
4556
|
userId: 1,
|
|
@@ -4586,25 +4611,6 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4586
4611
|
totalCredit: { $first: '$totalCredit' },
|
|
4587
4612
|
},
|
|
4588
4613
|
},
|
|
4589
|
-
// {
|
|
4590
|
-
// $lookup: {
|
|
4591
|
-
// from: 'userAudit',
|
|
4592
|
-
// let:{fileDate: "$fileDate"},
|
|
4593
|
-
// pipeline: [
|
|
4594
|
-
// {
|
|
4595
|
-
// $match: {
|
|
4596
|
-
// $expr: {
|
|
4597
|
-
// $and: [
|
|
4598
|
-
// {
|
|
4599
|
-
// fi
|
|
4600
|
-
// },
|
|
4601
|
-
// ],
|
|
4602
|
-
// },
|
|
4603
|
-
// },
|
|
4604
|
-
// },
|
|
4605
|
-
// ],as:"userAudit"
|
|
4606
|
-
// },
|
|
4607
|
-
// },
|
|
4608
4614
|
{
|
|
4609
4615
|
$project: {
|
|
4610
4616
|
totalCount: 1,
|
|
@@ -4716,7 +4722,7 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4716
4722
|
return res.sendSuccess( { message: 'Inserted successfully!' } );
|
|
4717
4723
|
} catch ( error ) {
|
|
4718
4724
|
const err = error.message || 'Internal Server Error';
|
|
4719
|
-
logger.
|
|
4725
|
+
logger.error( { error: error, message: req.body, function: 'getUserAuditCount' } );
|
|
4720
4726
|
return res.sendError( err, 500 );
|
|
4721
4727
|
}
|
|
4722
4728
|
}
|
|
@@ -4961,44 +4967,10 @@ export async function auditViewLogs( req, res ) {
|
|
|
4961
4967
|
break;
|
|
4962
4968
|
|
|
4963
4969
|
case 'cleaning':
|
|
4964
|
-
// logsQuery = {
|
|
4965
|
-
// 'size': 100,
|
|
4966
|
-
// 'query': {
|
|
4967
|
-
// 'bool': {
|
|
4968
|
-
// 'must': [
|
|
4969
|
-
// {
|
|
4970
|
-
// 'term': {
|
|
4971
|
-
// 'logData.fileDate.keyword': inputData.fileDate,
|
|
4972
|
-
// },
|
|
4973
|
-
// },
|
|
4974
|
-
// {
|
|
4975
|
-
// 'term': {
|
|
4976
|
-
// 'logData.storeId.keyword': inputData.storeId,
|
|
4977
|
-
// },
|
|
4978
|
-
// },
|
|
4979
|
-
// {
|
|
4980
|
-
// 'term': {
|
|
4981
|
-
// 'logData.moduleType.keyword': inputData.moduleType,
|
|
4982
|
-
// },
|
|
4983
|
-
// },
|
|
4984
|
-
// {
|
|
4985
|
-
// 'terms': {
|
|
4986
|
-
// 'logSubType.keyword': [ 'auditDone', 'reTrigger' ],
|
|
4987
|
-
// },
|
|
4988
|
-
// },
|
|
4989
|
-
// ],
|
|
4990
|
-
// },
|
|
4991
|
-
// },
|
|
4992
|
-
// 'sort': [
|
|
4993
|
-
// { createdAt: { order: 'desc' } },
|
|
4994
|
-
// ],
|
|
4995
|
-
// };
|
|
4996
|
-
// break;
|
|
4997
4970
|
default:
|
|
4998
4971
|
return res.sendError( 'Please give valid modueType', 400 );
|
|
4999
4972
|
}
|
|
5000
4973
|
}
|
|
5001
|
-
logger.info( { query: logsQuery, message: 'unattended' } );
|
|
5002
4974
|
const logs = await getOpenSearchData( parsedOpenSearch.auditLog, logsQuery );
|
|
5003
4975
|
if ( logs.body.hits.hits.length > 0 ) {
|
|
5004
4976
|
const sourcesArray = logs.body.hits.hits.map( ( hit ) => hit._source );
|
|
@@ -5023,7 +4995,7 @@ export async function auditViewLogs( req, res ) {
|
|
|
5023
4995
|
}
|
|
5024
4996
|
} catch ( error ) {
|
|
5025
4997
|
const err = error.message || 'Internal Server Error';
|
|
5026
|
-
logger.
|
|
4998
|
+
logger.error( { error: error, message: req.body, function: 'auditViewLogs' } );
|
|
5027
4999
|
return res.sendError( err, 500 );
|
|
5028
5000
|
}
|
|
5029
5001
|
}
|