tango-app-api-audit 3.4.68 → 3.5.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 +334 -347
- 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, upsertOpenSearchData, 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,79 @@ 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', 'isJunk' ], // Only fetch necessary fields
|
|
543
|
+
|
|
544
|
+
query: {
|
|
545
|
+
bool: {
|
|
546
|
+
must: [
|
|
547
|
+
{
|
|
548
|
+
term: { 'store_id.keyword': msg.store_id },
|
|
549
|
+
},
|
|
550
|
+
// {
|
|
551
|
+
// term: { isJunk: false },
|
|
552
|
+
// },
|
|
553
|
+
{
|
|
554
|
+
term: { isEmployee: false },
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
term: { 'date.keyword': msg.curr_date },
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
561
|
+
},
|
|
562
|
+
],
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
const list = msg.zone_id === 'track' ? inputData.nextId? await scrollResponse( inputData.nextId ):await searchOpenSearchData( msg.index_name, getQuery ): await listFileByPath( fetchData );
|
|
569
|
+
const folderPath = msg.zone_id === 'track' ? list?.body?.hits?.hits : list.data;
|
|
570
|
+
const nextQuery =msg.zone_id !== 'track' ? list.pageToken: '';
|
|
571
|
+
if ( msg.zone_id === 'track' ) {
|
|
572
|
+
if ( list?.body?.hits?.hits?.length ==0 ) {
|
|
573
|
+
await clearScroll( list?.body?._scroll_id );
|
|
574
|
+
}
|
|
512
575
|
}
|
|
513
|
-
const list = await listFileByPath( fetchData );
|
|
514
|
-
const folderPath = list.data;
|
|
515
|
-
const nextQuery = list.pageToken;
|
|
516
576
|
if ( folderPath?.length > 0 ) {
|
|
517
577
|
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 );
|
|
578
|
+
const img =msg.zone_id === 'track' ?folderPath[i]?._source?.personPath?.split( '/' ): folderPath[i].Key.split( '/' );
|
|
579
|
+
const image = img[3]?.split( '.' );
|
|
580
|
+
const indexes = msg.zone_id === 'track' ? folderPath[i]?._source?.outputCluster : image[0]?.split( '_' );
|
|
581
|
+
fetchData.file_path = msg.zone_id === 'track' ?folderPath[i]?._source?.personPath:folderPath[i].Key;
|
|
582
|
+
const data =msg.zone_id === 'track' ? `${url.trackInput}${folderPath[i]?._source?.personPath}` :await signedUrl( fetchData );
|
|
523
583
|
const mapimg = {
|
|
524
584
|
img_path: data,
|
|
525
|
-
img_name: indexes[1],
|
|
585
|
+
img_name: msg.zone_id === 'track' ?indexes: indexes[1],
|
|
526
586
|
img_id: image[0],
|
|
527
587
|
};
|
|
588
|
+
msg.zone_id === 'track' ? addUniqueFile( files, {
|
|
589
|
+
img_path: data,
|
|
590
|
+
img_name: msg.zone_id === 'track' ?indexes:indexes[1],
|
|
591
|
+
img_id: image[0],
|
|
592
|
+
selected: false,
|
|
593
|
+
dropped: false,
|
|
594
|
+
demographic: '',
|
|
595
|
+
count: 1,
|
|
596
|
+
mappedid: [ mapimg ],
|
|
597
|
+
} ):
|
|
528
598
|
files.push( {
|
|
529
599
|
img_path: data,
|
|
530
|
-
img_name: indexes[1],
|
|
600
|
+
img_name: msg.zone_id === 'track' ?indexes:indexes[1],
|
|
531
601
|
img_id: image[0],
|
|
532
602
|
selected: false,
|
|
533
603
|
dropped: false,
|
|
@@ -585,6 +655,9 @@ export async function getAuditFile( req, res ) {
|
|
|
585
655
|
} else {
|
|
586
656
|
insertData = userDetails[0];
|
|
587
657
|
}
|
|
658
|
+
} else if ( inputData.nextId !== '' && inputData.nextId !== null && inputData.nextId !== undefined && inputData.moduleType === 'track' ) {
|
|
659
|
+
list.body._scroll_id = '';
|
|
660
|
+
insertData = userDetails[0];
|
|
588
661
|
} else {
|
|
589
662
|
logger.error( {
|
|
590
663
|
error: { folderPath: folderPath, nextQuery: nextQuery },
|
|
@@ -593,7 +666,6 @@ export async function getAuditFile( req, res ) {
|
|
|
593
666
|
} );
|
|
594
667
|
return res.sendError( 'Bucket is Empty', 204 );
|
|
595
668
|
}
|
|
596
|
-
const userdata = await findOneUser( { _id: insertData.userId } );
|
|
597
669
|
const storeQuery = {
|
|
598
670
|
storeId: storeId,
|
|
599
671
|
};
|
|
@@ -604,8 +676,8 @@ export async function getAuditFile( req, res ) {
|
|
|
604
676
|
const storeInfo = await findOneStore( storeQuery, storeFields );
|
|
605
677
|
if ( inputData.nextId ) {
|
|
606
678
|
const logData = {
|
|
607
|
-
userId:
|
|
608
|
-
userName:
|
|
679
|
+
userId: req?.user?._id,
|
|
680
|
+
userName: req?.user?.userName,
|
|
609
681
|
logType: 'audit',
|
|
610
682
|
logSubType: 'auditStart',
|
|
611
683
|
logData: {
|
|
@@ -638,7 +710,7 @@ export async function getAuditFile( req, res ) {
|
|
|
638
710
|
userId: insertData.userId,
|
|
639
711
|
zoneName: msg.zone_id,
|
|
640
712
|
moduleType: inputData.moduleType,
|
|
641
|
-
nextToken: nextQuery ? encodeURIComponent( nextQuery ) : null,
|
|
713
|
+
nextToken: msg.zone_id === 'track' ? list?.body?._scroll_id : nextQuery ? encodeURIComponent( nextQuery ) : null,
|
|
642
714
|
},
|
|
643
715
|
isDraft: insertData.isDraft,
|
|
644
716
|
} );
|
|
@@ -651,6 +723,12 @@ export async function getAuditFile( req, res ) {
|
|
|
651
723
|
return res.sendError( error, 500 );
|
|
652
724
|
}
|
|
653
725
|
}
|
|
726
|
+
function addUniqueFile( files, newFile ) {
|
|
727
|
+
const exists = files.some( ( file ) => file.img_name === newFile.img_name );
|
|
728
|
+
if ( !exists ) {
|
|
729
|
+
files.push( newFile );
|
|
730
|
+
}
|
|
731
|
+
}
|
|
654
732
|
|
|
655
733
|
export async function getFilterData( msg ) {
|
|
656
734
|
try {
|
|
@@ -719,7 +797,6 @@ export async function getAuditImage( msg ) {
|
|
|
719
797
|
img_name: indexes[1],
|
|
720
798
|
img_id: image[0],
|
|
721
799
|
selected: false,
|
|
722
|
-
// demographic: '',
|
|
723
800
|
dropped: false,
|
|
724
801
|
count: 1,
|
|
725
802
|
mappedid: [ mapimg ],
|
|
@@ -782,7 +859,11 @@ export async function workSpace( req, res ) {
|
|
|
782
859
|
clientId: 1,
|
|
783
860
|
queueName: {
|
|
784
861
|
$cond: [
|
|
785
|
-
{ $eq: [ inputData.moduleType, 'zone' ] }, '$auditConfigs.zoneQueueName',
|
|
862
|
+
{ $eq: [ inputData.moduleType, 'zone' ] }, '$auditConfigs.zoneQueueName', {
|
|
863
|
+
$cond: [
|
|
864
|
+
{ $eq: [ inputData.moduleType, 'track' ] }, '$auditConfigs.trackQueueName', '$auditConfigs.trafficQueueName',
|
|
865
|
+
],
|
|
866
|
+
},
|
|
786
867
|
],
|
|
787
868
|
},
|
|
788
869
|
},
|
|
@@ -1272,77 +1353,195 @@ export async function save( req, res ) {
|
|
|
1272
1353
|
moduleType: inputData.moduleType,
|
|
1273
1354
|
zoneName: inputData.zoneName,
|
|
1274
1355
|
} );
|
|
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
|
-
};
|
|
1356
|
+
if ( inputData.moduleType !=='track' ) {
|
|
1357
|
+
const params = {
|
|
1358
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1359
|
+
};
|
|
1286
1360
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1361
|
+
if ( inputData.auditType === 'ReAudit' ) {
|
|
1362
|
+
params.Bucket = bucket.auditUploadBucket;
|
|
1363
|
+
} else {
|
|
1364
|
+
params.Bucket = bucket.masterJson;
|
|
1365
|
+
}
|
|
1366
|
+
const fileData = await getJsonFileData( params );
|
|
1293
1367
|
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1368
|
+
if ( fileData?.statusCode ) {
|
|
1369
|
+
logger.error( {
|
|
1370
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1371
|
+
type: 'UPLOAD_ERROR',
|
|
1372
|
+
} );
|
|
1373
|
+
return res.sendError( fileData, 500 );
|
|
1374
|
+
}
|
|
1301
1375
|
|
|
1302
|
-
|
|
1376
|
+
const masterJsonData = JSON.parse( fileData.toString( 'utf-8' ) );
|
|
1303
1377
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1378
|
+
const [ G20000, B20000, E0 ] = await Promise.all( [
|
|
1379
|
+
splitG20000( masterJsonData.person_data ),
|
|
1380
|
+
splitB20000( masterJsonData.person_data ),
|
|
1381
|
+
splitE0( masterJsonData.person_data ),
|
|
1382
|
+
] );
|
|
1309
1383
|
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1384
|
+
const [ mappingData ] = await Promise.all( [
|
|
1385
|
+
mapEmployee( B20000, inputData.employee ),
|
|
1386
|
+
mapJunk( B20000, inputData.junk ),
|
|
1387
|
+
mapCustomer( B20000, inputData.customer ),
|
|
1388
|
+
] );
|
|
1315
1389
|
|
|
1316
|
-
|
|
1390
|
+
const tempData = _.sortBy( [ ...mappingData, ...G20000, ...E0 ], 'index' );
|
|
1317
1391
|
|
|
1318
|
-
|
|
1392
|
+
const tempObject = { person_data: tempData };
|
|
1319
1393
|
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1394
|
+
const uploadDataParams = {
|
|
1395
|
+
Bucket: bucket.auditUploadBucket,
|
|
1396
|
+
Key: `${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/`,
|
|
1397
|
+
ContentType: 'application/json',
|
|
1398
|
+
fileName: `${bucket.masterJsonFile}`,
|
|
1399
|
+
body: JSON.stringify( tempObject ),
|
|
1400
|
+
};
|
|
1401
|
+
const mappingUpload = await fileUpload( uploadDataParams );
|
|
1328
1402
|
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1403
|
+
if ( mappingUpload?.statusCode ) {
|
|
1404
|
+
logger.error( {
|
|
1405
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1406
|
+
type: 'UPLOAD_ERROR',
|
|
1407
|
+
} );
|
|
1408
|
+
return res.sendError( mappingUpload, 500 );
|
|
1409
|
+
}
|
|
1410
|
+
} else {
|
|
1411
|
+
// Junk Mapping
|
|
1412
|
+
if ( inputData.junkCount >0 ) {
|
|
1413
|
+
const chunkedJunkMappingData = await filteredMap( inputData.junk );
|
|
1414
|
+
logger.info( { chunkedJunkMappingData: chunkedJunkMappingData } );
|
|
1415
|
+
const getQuery = {
|
|
1416
|
+
size: 10000,
|
|
1417
|
+
_source: false, // do not fetch full source
|
|
1418
|
+
stored_fields: [], // exclude all stored fields
|
|
1419
|
+
query: {
|
|
1420
|
+
bool: {
|
|
1421
|
+
must: [
|
|
1422
|
+
{
|
|
1423
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
1424
|
+
},
|
|
1425
|
+
{
|
|
1426
|
+
terms: { outputCluster: chunkedJunkMappingData },
|
|
1427
|
+
},
|
|
1428
|
+
{
|
|
1429
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
1430
|
+
},
|
|
1431
|
+
{
|
|
1432
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
1433
|
+
},
|
|
1434
|
+
],
|
|
1435
|
+
},
|
|
1436
|
+
},
|
|
1336
1437
|
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1438
|
+
};
|
|
1439
|
+
const getId = await getOpenSearchData( 'tracker_process', getQuery );
|
|
1440
|
+
const ids = getId?.body?.hits?.total?.value || null;
|
|
1441
|
+
if ( ids ) {
|
|
1442
|
+
const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
|
|
1443
|
+
const updatedField = { isJunk: true }; // your field updates
|
|
1444
|
+
const body = temp.flatMap( ( id ) => [
|
|
1445
|
+
{ update: { _index: 'tracker_process', _id: id } },
|
|
1446
|
+
{ doc: updatedField },
|
|
1447
|
+
] );
|
|
1448
|
+
const re= await bulkUpdate( body );
|
|
1449
|
+
logger.info( { getId: getId, re: re } );
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// Employee Mapping
|
|
1454
|
+
if ( inputData.employeeCount >0 ) {
|
|
1455
|
+
const chunkedEmpMappingData = await filteredMap( inputData.employee );
|
|
1456
|
+
logger.info( { chunkedEmpMappingData: chunkedEmpMappingData } );
|
|
1457
|
+
const getQuery = {
|
|
1458
|
+
size: 10000,
|
|
1459
|
+
_source: false, // do not fetch full source
|
|
1460
|
+
stored_fields: [], // exclude all stored fields
|
|
1461
|
+
query: {
|
|
1462
|
+
bool: {
|
|
1463
|
+
must: [
|
|
1464
|
+
{
|
|
1465
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
1466
|
+
},
|
|
1467
|
+
{
|
|
1468
|
+
terms: { outputCluster: chunkedEmpMappingData },
|
|
1469
|
+
},
|
|
1470
|
+
{
|
|
1471
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
1475
|
+
},
|
|
1476
|
+
],
|
|
1477
|
+
},
|
|
1478
|
+
},
|
|
1479
|
+
|
|
1480
|
+
};
|
|
1481
|
+
const getId = await getOpenSearchData( 'tracker_process', getQuery );
|
|
1482
|
+
const ids = getId?.body?.hits?.total?.value || null;
|
|
1483
|
+
if ( ids ) {
|
|
1484
|
+
const temp = getId?.body?.hits?.hits?.map( ( item ) => item._id );
|
|
1485
|
+
const updatedField = { isEmployee: true }; // your field updates
|
|
1486
|
+
const body = temp.flatMap( ( id ) => [
|
|
1487
|
+
{ update: { _index: 'tracker_process', _id: id } },
|
|
1488
|
+
{ doc: updatedField },
|
|
1489
|
+
] );
|
|
1490
|
+
const re= await bulkUpdate( body );
|
|
1491
|
+
logger.info( { getId: getId, re: re } );
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
// Customer Mapping
|
|
1496
|
+
if ( inputData?.customer?.length > 0 ) {
|
|
1497
|
+
logger.info( { lenght: inputData?.customer?.length } );
|
|
1498
|
+
const filterCustomerData = await filteredCustomerMap( inputData.customer );
|
|
1499
|
+
const chunkedMappingData = await chunkArray( filterCustomerData, 10 );
|
|
1500
|
+
|
|
1501
|
+
chunkedMappingData.map( async ( chunk ) => {
|
|
1502
|
+
logger.info( { chunk: chunk } );
|
|
1503
|
+
|
|
1504
|
+
chunk.map( async ( item ) => {
|
|
1505
|
+
const imgName= item.img_name;
|
|
1506
|
+
const mappedId= item.mappedid.map( ( m ) => m.img_name );
|
|
1507
|
+
const searchQuery = {
|
|
1508
|
+
size: 10000,
|
|
1509
|
+
_source: false, // do not fetch full source
|
|
1510
|
+
stored_fields: [], // exclude all stored fields
|
|
1511
|
+
query: {
|
|
1512
|
+
bool: {
|
|
1513
|
+
must: [
|
|
1514
|
+
{
|
|
1515
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
1516
|
+
},
|
|
1517
|
+
{
|
|
1518
|
+
terms: { outputCluster: mappedId },
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
1522
|
+
},
|
|
1523
|
+
{
|
|
1524
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
1525
|
+
},
|
|
1526
|
+
],
|
|
1527
|
+
},
|
|
1528
|
+
},
|
|
1529
|
+
|
|
1530
|
+
};
|
|
1531
|
+
const getData =await getOpenSearchData( 'tracker_process', searchQuery );
|
|
1532
|
+
if ( getData?.body?.hits?.hits?.length > 0 ) {
|
|
1533
|
+
const temp = getData?.body?.hits?.hits?.map( ( item ) => item._id );
|
|
1534
|
+
const body = temp.flatMap( ( id ) => [
|
|
1535
|
+
{ update: { _index: 'tracker_process', _id: id } },
|
|
1536
|
+
{ doc: { outputCluster: imgName, isEmployee: false, isJunk: false } },
|
|
1537
|
+
] );
|
|
1538
|
+
const re= await bulkUpdate( body );
|
|
1539
|
+
logger.info( { re: re } );
|
|
1540
|
+
}
|
|
1541
|
+
} );
|
|
1542
|
+
} );
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1346
1545
|
|
|
1347
1546
|
await updateOneUserAudit(
|
|
1348
1547
|
{ _id: new mongoose.Types.ObjectId( inputData.auditId ) },
|
|
@@ -1466,7 +1665,6 @@ export async function save( req, res ) {
|
|
|
1466
1665
|
fileDate: inputData.fileDate,
|
|
1467
1666
|
moduleType: inputData.moduleType,
|
|
1468
1667
|
zoneName: inputData.zoneName,
|
|
1469
|
-
// auditType: inputData.auditType,
|
|
1470
1668
|
},
|
|
1471
1669
|
{
|
|
1472
1670
|
status: 'completed',
|
|
@@ -1474,22 +1672,34 @@ export async function save( req, res ) {
|
|
|
1474
1672
|
timeSpent: inputData.timeSpent,
|
|
1475
1673
|
},
|
|
1476
1674
|
);
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1675
|
+
if ( inputData.moduleType !== 'track' ) {
|
|
1676
|
+
const sqsProduceQueue = {
|
|
1677
|
+
QueueUrl: ( auditConfig?.isCheckMinAfterCount ==1 && inputData.customerCount > auditConfig?.minAfterCount ) ? `${sqs.url}${sqs.feature_new}`: `${sqs.url}${sqs.feature}`,
|
|
1678
|
+
MessageBody: JSON.stringify( {
|
|
1679
|
+
store_id: inputData.storeId,
|
|
1680
|
+
store_date: inputData.fileDate,
|
|
1681
|
+
bucket_name: `${bucket.auditUploadBucket}`,
|
|
1682
|
+
zone_id: inputData.zoneName,
|
|
1683
|
+
process_type: 'audit',
|
|
1684
|
+
} ),
|
|
1685
|
+
};
|
|
1686
|
+
logger.info( { sqsProduceQueue: sqsProduceQueue } );
|
|
1687
|
+
const sqsQueue = await sendMessageToQueue(
|
|
1688
|
+
sqsProduceQueue.QueueUrl,
|
|
1689
|
+
sqsProduceQueue.MessageBody,
|
|
1690
|
+
);
|
|
1691
|
+
logger.info( { sqsQueue: sqsQueue } );
|
|
1692
|
+
} else {
|
|
1693
|
+
const query =
|
|
1694
|
+
{ 'module': 'REID-TRACKER-V1',
|
|
1695
|
+
'store_date_time': `${inputData.storeId}_${inputData.fileDate}_23:00`,
|
|
1696
|
+
'status': 'POSTPROCESS_AUDIT_SUCCESS',
|
|
1697
|
+
'status_time': Date.now(),
|
|
1698
|
+
'timestamp': new Date() };
|
|
1699
|
+
|
|
1700
|
+
|
|
1701
|
+
await upsertOpenSearchData( 'tracker_process', `${inputData.storeId}_${inputData.fileDate}_23:00`, { doc: query } );
|
|
1702
|
+
}
|
|
1493
1703
|
}
|
|
1494
1704
|
|
|
1495
1705
|
return res.sendSuccess( { result: 'Updated Successfully' } );
|
|
@@ -1500,6 +1710,15 @@ export async function save( req, res ) {
|
|
|
1500
1710
|
}
|
|
1501
1711
|
}
|
|
1502
1712
|
|
|
1713
|
+
const filteredMap = async ( data ) => {
|
|
1714
|
+
const temp = data.map( ( item ) => item.img_name );
|
|
1715
|
+
return temp;
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
const filteredCustomerMap = async ( data ) => {
|
|
1719
|
+
return data.filter( ( map ) => map.count >= 1 );
|
|
1720
|
+
};
|
|
1721
|
+
|
|
1503
1722
|
/* < -- *** Audit Metrics *** --> */
|
|
1504
1723
|
|
|
1505
1724
|
export async function userAuditHistory( req, res ) {
|
|
@@ -1968,7 +2187,6 @@ export async function clientMetrics( req, res ) {
|
|
|
1968
2187
|
);
|
|
1969
2188
|
}
|
|
1970
2189
|
|
|
1971
|
-
logger.info( { query: query } );
|
|
1972
2190
|
const result = await aggregateAuditStoreData( query );
|
|
1973
2191
|
if ( result.length == 0 ) {
|
|
1974
2192
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -1980,7 +2198,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1980
2198
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1981
2199
|
} catch ( error ) {
|
|
1982
2200
|
const err = error.error || 'Internal Server Error';
|
|
1983
|
-
logger.
|
|
2201
|
+
logger.error( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
1984
2202
|
return res.sendError( err, 500 );
|
|
1985
2203
|
}
|
|
1986
2204
|
}
|
|
@@ -2234,8 +2452,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2234
2452
|
'File Date': element.fileDate,
|
|
2235
2453
|
'Store Name': element.storeName,
|
|
2236
2454
|
'Store ID': element.storeId,
|
|
2237
|
-
// 'Client Id': element.clientId,
|
|
2238
|
-
// 'Client Name': element.clientName,
|
|
2239
2455
|
'Product Type': element.moduleType,
|
|
2240
2456
|
'Zone Name': element.zoneName,
|
|
2241
2457
|
'User Name': element.userName,
|
|
@@ -2252,8 +2468,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2252
2468
|
'File Date': element.fileDate,
|
|
2253
2469
|
'Store Name': element.storeName,
|
|
2254
2470
|
'Store ID': element.storeId,
|
|
2255
|
-
// 'Client Id': element.clientId,
|
|
2256
|
-
// 'Client Name': element.clientName,
|
|
2257
2471
|
'Product Type': element.moduleType,
|
|
2258
2472
|
'User Name': element.userName,
|
|
2259
2473
|
'User Email': element.userEmail,
|
|
@@ -2307,7 +2521,6 @@ export async function userMetrics( req, res ) {
|
|
|
2307
2521
|
}
|
|
2308
2522
|
if ( inputData?.filterByUser?.length > 0 ) {
|
|
2309
2523
|
const temp = inputData.filterByUser.map( ( item ) => new mongoose.Types.ObjectId( item ) );
|
|
2310
|
-
logger.info( { temp: temp } );
|
|
2311
2524
|
filter.push(
|
|
2312
2525
|
{ userId: { $in: temp } },
|
|
2313
2526
|
);
|
|
@@ -3514,7 +3727,6 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3514
3727
|
{ createdAt: -1 },
|
|
3515
3728
|
);
|
|
3516
3729
|
const latestTraxDate = geTraxData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
|
|
3517
|
-
logger.info( { geTraxData: geTraxData } );
|
|
3518
3730
|
|
|
3519
3731
|
const query = [
|
|
3520
3732
|
{
|
|
@@ -3720,97 +3932,15 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3720
3932
|
},
|
|
3721
3933
|
},
|
|
3722
3934
|
];
|
|
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
|
-
// ];
|
|
3935
|
+
|
|
3803
3936
|
const getTotalcount = await aggregateAuditStoreData( query );
|
|
3804
3937
|
const getTotalTraxAudit = await aggregateTraxAuditData( traxQuery );
|
|
3805
3938
|
const getInprogressCount = await aggregateStoreAudit( inprogressCount );
|
|
3806
3939
|
const getBinaryInprogressCount = await aggregateBinaryAudit( binaryInprogressCount );
|
|
3807
3940
|
const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3808
|
-
logger.info( { getMappingInprogressCount: getMappingInprogressCount } );
|
|
3809
|
-
// const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
|
|
3810
3941
|
if ( getTotalcount.length == 0 && getTotalTraxAudit.length == 0 ) {
|
|
3811
3942
|
return res.sendError( 'No Data Found', 204 );
|
|
3812
3943
|
}
|
|
3813
|
-
logger.info( { getTotalTraxAudit: getTotalTraxAudit } );
|
|
3814
3944
|
if ( getInprogressCount.length > 0 ) {
|
|
3815
3945
|
notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount > getInprogressCount[0]?.inprogressAuditCount ? getTotalcount[0].totalAuditCount - getInprogressCount[0]?.inprogressAuditCount : 0;
|
|
3816
3946
|
notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount > getInprogressCount[0]?.inprogressZoneCount ? getTotalcount[0].totalZoneCount - getInprogressCount[0]?.inprogressZoneCount : 0;
|
|
@@ -3858,11 +3988,9 @@ export async function auditImages( req, res ) {
|
|
|
3858
3988
|
|
|
3859
3989
|
if ( inputData.export == true ) {
|
|
3860
3990
|
auditImageDownload = await zipDownloadImage( auditImageBC );
|
|
3861
|
-
// Set response headers for the zip file
|
|
3862
3991
|
res.set( 'Content-Type', 'application/zip' );
|
|
3863
3992
|
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
3864
3993
|
|
|
3865
|
-
// Send the zip file as the API response
|
|
3866
3994
|
return res.send( auditImageDownload );
|
|
3867
3995
|
}
|
|
3868
3996
|
res.sendSuccess( { result: auditImageBC } );
|
|
@@ -3879,12 +4007,10 @@ export async function auditImages( req, res ) {
|
|
|
3879
4007
|
}
|
|
3880
4008
|
|
|
3881
4009
|
const reauditImg = await getReauditImg( filterData, auditImageAC );
|
|
3882
|
-
logger.info( { reauditImg: reauditImg } );
|
|
3883
4010
|
if ( reauditImg?.length == 0 ) {
|
|
3884
4011
|
return res.sendError( 'No Data Found', 204 );
|
|
3885
4012
|
}
|
|
3886
4013
|
|
|
3887
|
-
logger.info( { auditImageAC: auditImageAC, filterData: filterData, reauditImg: reauditImg } );
|
|
3888
4014
|
if ( inputData.export == true ) {
|
|
3889
4015
|
auditImageDownload = await zipDownloadImage( reauditImg );
|
|
3890
4016
|
// Set response headers for the zip file
|
|
@@ -3900,12 +4026,9 @@ export async function auditImages( req, res ) {
|
|
|
3900
4026
|
res.sendError( 'No Data Found', 204 );
|
|
3901
4027
|
break;
|
|
3902
4028
|
}
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
// return res.sendSuccess( { result: inputData } );
|
|
3906
4029
|
} catch ( error ) {
|
|
3907
4030
|
const err = error.message || 'Internal Server Error';
|
|
3908
|
-
logger.
|
|
4031
|
+
logger.error( { error: error, message: req.body, function: 'auditImages' } );
|
|
3909
4032
|
return res.sendError( err, 500 );
|
|
3910
4033
|
}
|
|
3911
4034
|
}
|
|
@@ -3924,7 +4047,7 @@ export async function getUserCredit( req, res ) {
|
|
|
3924
4047
|
return res.sendSuccess( { result: getWallet, isAuditUser: true } );
|
|
3925
4048
|
} catch ( error ) {
|
|
3926
4049
|
const err = error.message || 'Internal Server Error';
|
|
3927
|
-
logger.
|
|
4050
|
+
logger.error( { error: error, function: 'getUserCredit' } );
|
|
3928
4051
|
return res.sendError( err, 500 );
|
|
3929
4052
|
}
|
|
3930
4053
|
}
|
|
@@ -3948,7 +4071,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3948
4071
|
|
|
3949
4072
|
// Calculate the difference in days
|
|
3950
4073
|
const differenceInDays = ( yesterday.getDate() - firstDateOfMonth.getDate() );
|
|
3951
|
-
logger.info( { differenceInDays: differenceInDays } );
|
|
3952
4074
|
|
|
3953
4075
|
const auditUserQuery=[
|
|
3954
4076
|
{
|
|
@@ -4110,7 +4232,6 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4110
4232
|
return res.sendError( 'No Data Found', 204 );
|
|
4111
4233
|
}
|
|
4112
4234
|
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
4235
|
const beforeCreditCal = userWallet?.beforeCountCredit/minimumTarget;
|
|
4115
4236
|
const afterCountCredit = userWallet?.afterCountCredit;
|
|
4116
4237
|
const filter = [
|
|
@@ -4415,7 +4536,7 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4415
4536
|
}
|
|
4416
4537
|
} catch ( error ) {
|
|
4417
4538
|
const err = error.message || 'Internal Server Error';
|
|
4418
|
-
logger.
|
|
4539
|
+
logger.error( { error: error, message: req.body, function: 'getUserAuditCount' } );
|
|
4419
4540
|
return res.sendError( err, 500 );
|
|
4420
4541
|
}
|
|
4421
4542
|
}
|
|
@@ -4428,89 +4549,11 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4428
4549
|
yesterday.setDate( today.getDate() - 1 );
|
|
4429
4550
|
let firstDayOfMonth = new Date( yesterday.getFullYear(), today.getMonth(), 1 );
|
|
4430
4551
|
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
4552
|
const dateRange = await getDate( firstDayOfMonth, new Date( dayjs( previousDate ).format( 'YYYY-MM-DD' ) ) );
|
|
4434
|
-
logger.info( { dateRange: dateRange } );
|
|
4435
4553
|
const configTimeSpentSec = userWallet.minTimeSpentSec; // 18000;
|
|
4436
4554
|
const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
|
|
4437
4555
|
const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
|
|
4438
4556
|
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
4557
|
const query = [
|
|
4515
4558
|
{
|
|
4516
4559
|
$match: {
|
|
@@ -4523,9 +4566,6 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4523
4566
|
],
|
|
4524
4567
|
},
|
|
4525
4568
|
},
|
|
4526
|
-
// {
|
|
4527
|
-
// $set: { minimumTarget: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, trafficMinimumTarget, zoneMinimumTarget ] } },
|
|
4528
|
-
// },
|
|
4529
4569
|
{
|
|
4530
4570
|
$project: {
|
|
4531
4571
|
userId: 1,
|
|
@@ -4586,25 +4626,6 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4586
4626
|
totalCredit: { $first: '$totalCredit' },
|
|
4587
4627
|
},
|
|
4588
4628
|
},
|
|
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
4629
|
{
|
|
4609
4630
|
$project: {
|
|
4610
4631
|
totalCount: 1,
|
|
@@ -4716,7 +4737,7 @@ export async function getUserAuditCountMTD( req, res ) {
|
|
|
4716
4737
|
return res.sendSuccess( { message: 'Inserted successfully!' } );
|
|
4717
4738
|
} catch ( error ) {
|
|
4718
4739
|
const err = error.message || 'Internal Server Error';
|
|
4719
|
-
logger.
|
|
4740
|
+
logger.error( { error: error, message: req.body, function: 'getUserAuditCount' } );
|
|
4720
4741
|
return res.sendError( err, 500 );
|
|
4721
4742
|
}
|
|
4722
4743
|
}
|
|
@@ -4961,44 +4982,10 @@ export async function auditViewLogs( req, res ) {
|
|
|
4961
4982
|
break;
|
|
4962
4983
|
|
|
4963
4984
|
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
4985
|
default:
|
|
4998
4986
|
return res.sendError( 'Please give valid modueType', 400 );
|
|
4999
4987
|
}
|
|
5000
4988
|
}
|
|
5001
|
-
logger.info( { query: logsQuery, message: 'unattended' } );
|
|
5002
4989
|
const logs = await getOpenSearchData( parsedOpenSearch.auditLog, logsQuery );
|
|
5003
4990
|
if ( logs.body.hits.hits.length > 0 ) {
|
|
5004
4991
|
const sourcesArray = logs.body.hits.hits.map( ( hit ) => hit._source );
|
|
@@ -5023,7 +5010,7 @@ export async function auditViewLogs( req, res ) {
|
|
|
5023
5010
|
}
|
|
5024
5011
|
} catch ( error ) {
|
|
5025
5012
|
const err = error.message || 'Internal Server Error';
|
|
5026
|
-
logger.
|
|
5013
|
+
logger.error( { error: error, message: req.body, function: 'auditViewLogs' } );
|
|
5027
5014
|
return res.sendError( err, 500 );
|
|
5028
5015
|
}
|
|
5029
5016
|
}
|