tango-app-api-audit 3.4.11-alpha.2 → 3.4.11-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/controllers/audit.controllers.js +404 -342
- package/src/controllers/traxAudit.controllers.js +229 -108
- package/src/docs/audit.docs.js +14 -0
- package/src/dtos/audit.dtos.js +2 -0
- package/src/routes/audit.routes.js +3 -2
- package/src/service/auditUserWallet.service.js +4 -0
- package/src/service/auditUsers.service.js +4 -0
- package/src/validation/audit.validation.js +15 -0
- package/src/validation/traxAuditValidation.js +1 -0
|
@@ -746,7 +746,6 @@ export async function workSpace( req, res ) {
|
|
|
746
746
|
},
|
|
747
747
|
];
|
|
748
748
|
|
|
749
|
-
logger.info( { moduleType: inputData.moduleType, key: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ), dateStart: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ), end: dateRange.end, user: req.user._id, client: clientList } );
|
|
750
749
|
|
|
751
750
|
const userAsignAudit = [
|
|
752
751
|
{
|
|
@@ -800,11 +799,11 @@ export async function workSpace( req, res ) {
|
|
|
800
799
|
},
|
|
801
800
|
];
|
|
802
801
|
|
|
803
|
-
const auditUserCount = [ '
|
|
804
|
-
const userIncompleteFilesCount = [ '
|
|
802
|
+
const auditUserCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
|
|
803
|
+
const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
|
|
805
804
|
logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
|
|
806
805
|
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
807
|
-
const completedStoresCount = [ '
|
|
806
|
+
const completedStoresCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
|
|
808
807
|
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
809
808
|
const auditStoreData = await aggregateTraxAuditData(
|
|
810
809
|
auditStoreDataQuery,
|
|
@@ -981,13 +980,7 @@ export async function getAuditFile( req, res ) {
|
|
|
981
980
|
query ={
|
|
982
981
|
storeId: userDetails[0].storeId,
|
|
983
982
|
fileDate: userDetails[0].fileDate,
|
|
984
|
-
|
|
985
|
-
};
|
|
986
|
-
break;
|
|
987
|
-
case 'mobile-detection':
|
|
988
|
-
query ={
|
|
989
|
-
storeId: userDetails[0].storeId,
|
|
990
|
-
fileDate: userDetails[0].fileDate,
|
|
983
|
+
// tempId: userDetails[0].tempId,
|
|
991
984
|
moduleType: userDetails[0].moduleType,
|
|
992
985
|
};
|
|
993
986
|
break;
|
|
@@ -1005,7 +998,7 @@ export async function getAuditFile( req, res ) {
|
|
|
1005
998
|
logger.info( { query: query } );
|
|
1006
999
|
const traxInfo = await findOneTraxAuditData( query );
|
|
1007
1000
|
if ( !traxInfo ) {
|
|
1008
|
-
return res.sendError( 'The
|
|
1001
|
+
return res.sendError( 'The source record not found', 400 );
|
|
1009
1002
|
}
|
|
1010
1003
|
msg =traxInfo?.sqs?.Body;
|
|
1011
1004
|
break;
|
|
@@ -1049,46 +1042,42 @@ export async function getAuditFile( req, res ) {
|
|
|
1049
1042
|
},
|
|
1050
1043
|
];
|
|
1051
1044
|
break;
|
|
1052
|
-
case '
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1045
|
+
case 'uniform-detection':
|
|
1046
|
+
const files = [];
|
|
1047
|
+
|
|
1048
|
+
const params ={
|
|
1049
|
+
Bucket: msg.inputBucketName,
|
|
1050
|
+
Key: msg?.filePath,
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
const isExists = await checkFileExist( params );
|
|
1054
|
+
|
|
1055
|
+
if ( isExists ) {
|
|
1056
|
+
const signedParams ={
|
|
1056
1057
|
Bucket: msg.inputBucketName,
|
|
1057
|
-
file_path: msg?.
|
|
1058
|
-
MaxKeys: 1000,
|
|
1058
|
+
file_path: msg?.filePath,
|
|
1059
1059
|
};
|
|
1060
|
-
const
|
|
1061
|
-
const folderPath = list.data;
|
|
1062
|
-
logger.info( { folderPath: list, params: params, list: list } );
|
|
1063
|
-
if ( folderPath?.length ) {
|
|
1064
|
-
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
1065
|
-
// const img = folderPath[i].Key.split( '/' );
|
|
1066
|
-
// const image = img[3].split( '.' );
|
|
1067
|
-
// const indexes = image[0].split( '_' );
|
|
1068
|
-
const signedParams ={
|
|
1069
|
-
Bucket: msg.inputBucketName,
|
|
1070
|
-
file_path: folderPath[i].Key,
|
|
1071
|
-
};
|
|
1072
|
-
const data = await signedUrl( signedParams );
|
|
1060
|
+
const data = await signedUrl( signedParams );
|
|
1073
1061
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
}
|
|
1078
|
-
} else {
|
|
1079
|
-
logger.error( {
|
|
1080
|
-
error: { folderPath: folderPath },
|
|
1081
|
-
function: `getAuditFile - ${inputData.moduleType}`,
|
|
1082
|
-
message: 'Bucket image data not availale',
|
|
1083
|
-
} );
|
|
1084
|
-
return res.sendError( 'Bucket is Empty', 204 );
|
|
1085
|
-
}
|
|
1086
|
-
result.push( {
|
|
1087
|
-
type: msg.fileDetails[i].type,
|
|
1088
|
-
file: files,
|
|
1089
|
-
} );
|
|
1062
|
+
files.push(
|
|
1063
|
+
data,
|
|
1064
|
+
);
|
|
1090
1065
|
}
|
|
1066
|
+
// else {
|
|
1067
|
+
// logger.error( {
|
|
1068
|
+
// error: { folderPath: folderPath },
|
|
1069
|
+
// function: `getAuditFile - ${inputData.moduleType}`,
|
|
1070
|
+
// message: 'Bucket image data not availale',
|
|
1071
|
+
// } );
|
|
1072
|
+
// return res.sendError( 'Bucket is Empty', 204 );
|
|
1073
|
+
// }
|
|
1074
|
+
result.push( {
|
|
1075
|
+
type: 'image',
|
|
1076
|
+
file: files,
|
|
1077
|
+
} );
|
|
1078
|
+
|
|
1091
1079
|
break;
|
|
1080
|
+
case 'unattended-customer':
|
|
1092
1081
|
case 'left-in-middle':
|
|
1093
1082
|
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
1094
1083
|
const files = [];
|
|
@@ -1262,46 +1251,35 @@ export async function getUpdatedFile( req, res ) {
|
|
|
1262
1251
|
},
|
|
1263
1252
|
];
|
|
1264
1253
|
break;
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1254
|
+
|
|
1255
|
+
case 'uniform-detection':
|
|
1256
|
+
const files = [];
|
|
1257
|
+
|
|
1258
|
+
const params ={
|
|
1259
|
+
Bucket: msg.inputBucketName,
|
|
1260
|
+
Key: msg?.filePath,
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
const isExists = await checkFileExist( params );
|
|
1264
|
+
|
|
1265
|
+
if ( isExists ) {
|
|
1266
|
+
const signedParams ={
|
|
1269
1267
|
Bucket: msg.inputBucketName,
|
|
1270
|
-
file_path: msg?.
|
|
1271
|
-
MaxKeys: 1000,
|
|
1268
|
+
file_path: msg?.filePath,
|
|
1272
1269
|
};
|
|
1273
|
-
const
|
|
1274
|
-
const folderPath = list.data;
|
|
1275
|
-
logger.info( { folderPath: list, params: params, list: list } );
|
|
1276
|
-
if ( folderPath?.length ) {
|
|
1277
|
-
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
1278
|
-
// const img = folderPath[i].Key.split( '/' );
|
|
1279
|
-
// const image = img[3].split( '.' );
|
|
1280
|
-
// const indexes = image[0].split( '_' );
|
|
1281
|
-
const signedParams ={
|
|
1282
|
-
Bucket: msg.inputBucketName,
|
|
1283
|
-
file_path: folderPath[i].Key,
|
|
1284
|
-
};
|
|
1285
|
-
const data = await signedUrl( signedParams );
|
|
1270
|
+
const data = await signedUrl( signedParams );
|
|
1286
1271
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
}
|
|
1291
|
-
} else {
|
|
1292
|
-
logger.error( {
|
|
1293
|
-
error: { folderPath: folderPath },
|
|
1294
|
-
function: `getAuditFile - ${inputData.moduleType}`,
|
|
1295
|
-
message: 'Bucket image data not availale',
|
|
1296
|
-
} );
|
|
1297
|
-
return res.sendError( 'Bucket is Empty', 204 );
|
|
1298
|
-
}
|
|
1299
|
-
result.push( {
|
|
1300
|
-
type: msg.fileDetails[i].type,
|
|
1301
|
-
file: files,
|
|
1302
|
-
} );
|
|
1272
|
+
files.push(
|
|
1273
|
+
data,
|
|
1274
|
+
);
|
|
1303
1275
|
}
|
|
1276
|
+
result.push( {
|
|
1277
|
+
type: 'image',
|
|
1278
|
+
file: files,
|
|
1279
|
+
} );
|
|
1280
|
+
|
|
1304
1281
|
break;
|
|
1282
|
+
case 'unattended-customer':
|
|
1305
1283
|
case 'left-in-middle':
|
|
1306
1284
|
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
1307
1285
|
const files = [];
|
|
@@ -1404,6 +1382,7 @@ export async function getUpdatedFile( req, res ) {
|
|
|
1404
1382
|
export async function saveBinary( req, res ) {
|
|
1405
1383
|
try {
|
|
1406
1384
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
1385
|
+
const sqs = JSON.parse( process.env.SQS );
|
|
1407
1386
|
const inputData = req.body;
|
|
1408
1387
|
const isoDate = req.userAudit?.startTime;
|
|
1409
1388
|
const currentTime = dayjs();
|
|
@@ -1457,11 +1436,94 @@ export async function saveBinary( req, res ) {
|
|
|
1457
1436
|
createdAt: Date.now(),
|
|
1458
1437
|
};
|
|
1459
1438
|
await insertOpenSearchData( openSearch.auditLog, logData2 );
|
|
1460
|
-
logger.info( 'update in binary data', { query: unattendedquery, update: update } );
|
|
1461
1439
|
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1462
1440
|
|
|
1463
1441
|
break;
|
|
1464
1442
|
|
|
1443
|
+
case 'uniform-detection':
|
|
1444
|
+
let uniformDetectionQuery ={
|
|
1445
|
+
_id: inputData.auditId,
|
|
1446
|
+
storeId: inputData.storeId,
|
|
1447
|
+
fileDate: inputData.fileDate,
|
|
1448
|
+
// tempId: inputData.tempId,
|
|
1449
|
+
moduleType: inputData.moduleType,
|
|
1450
|
+
};
|
|
1451
|
+
|
|
1452
|
+
let updateUniform={
|
|
1453
|
+
auditStatus: 'completed',
|
|
1454
|
+
answer: inputData.answer,
|
|
1455
|
+
userComments: inputData.userComments || '',
|
|
1456
|
+
endTime: new Date(),
|
|
1457
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1458
|
+
};
|
|
1459
|
+
let updatDataUniform= await updateOneBinaryAuditModel( uniformDetectionQuery, updateUniform );
|
|
1460
|
+
if ( updatDataUniform.modifiedCount==0 ) {
|
|
1461
|
+
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1462
|
+
}
|
|
1463
|
+
const getFilePath = await findOneTraxAuditData(
|
|
1464
|
+
{
|
|
1465
|
+
fileDate: inputData.fileDate,
|
|
1466
|
+
storeId: inputData.storeId,
|
|
1467
|
+
moduleType: inputData.moduleType,
|
|
1468
|
+
tempId: inputData.tempId,
|
|
1469
|
+
},
|
|
1470
|
+
);
|
|
1471
|
+
if ( !getFilePath ) {
|
|
1472
|
+
return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
|
|
1473
|
+
}
|
|
1474
|
+
const sqsProduceQueue = {
|
|
1475
|
+
QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
|
|
1476
|
+
MessageBody: JSON.stringify( {
|
|
1477
|
+
storeId: inputData.storeId,
|
|
1478
|
+
fileDate: inputData.fileDate,
|
|
1479
|
+
tempId: inputData.tempId,
|
|
1480
|
+
moduleType: inputData.moduleType,
|
|
1481
|
+
answer: inputData.answer,
|
|
1482
|
+
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
1483
|
+
filePath: getFilePath?.sqs?.Body?.filePath,
|
|
1484
|
+
} ),
|
|
1485
|
+
};
|
|
1486
|
+
const sqsQueue = await sendMessageToQueue(
|
|
1487
|
+
sqsProduceQueue.QueueUrl,
|
|
1488
|
+
sqsProduceQueue.MessageBody,
|
|
1489
|
+
);
|
|
1490
|
+
|
|
1491
|
+
if ( sqsQueue.statusCode ) {
|
|
1492
|
+
logger.error( {
|
|
1493
|
+
error: `${sqsQueue}`,
|
|
1494
|
+
type: 'UPLOAD_ERROR',
|
|
1495
|
+
} );
|
|
1496
|
+
return res.sendError( 'SQS not sent', 500 );
|
|
1497
|
+
}
|
|
1498
|
+
const logData3 = {
|
|
1499
|
+
userId: req.user._id,
|
|
1500
|
+
userName: req.user.userName,
|
|
1501
|
+
logType: 'traxAudit',
|
|
1502
|
+
logSubType: 'auditDone',
|
|
1503
|
+
logData: {
|
|
1504
|
+
fileDate: req.userAudit?.fileDate,
|
|
1505
|
+
auditType: req.userAudit?.auditType,
|
|
1506
|
+
storeId: req.userAudit?.storeId,
|
|
1507
|
+
moduleType: req.userAudit?.moduleType,
|
|
1508
|
+
queueName: req.userAudit?.queueName,
|
|
1509
|
+
clientId: req.userAudit?.clientId,
|
|
1510
|
+
// beforeCount: req.userAudit?.beforeCount,
|
|
1511
|
+
// afterCount: inputData.employeeCount,
|
|
1512
|
+
startTime: req.userAudit?.startTime,
|
|
1513
|
+
streamName: req.userAudit?.streamName,
|
|
1514
|
+
tempId: req.userAudit?.tempId,
|
|
1515
|
+
question: req.userAudit?.question,
|
|
1516
|
+
result: req.userAudit?.answer,
|
|
1517
|
+
endTime: Date.now(),
|
|
1518
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1519
|
+
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1520
|
+
},
|
|
1521
|
+
createdAt: Date.now(),
|
|
1522
|
+
};
|
|
1523
|
+
await insertOpenSearchData( openSearch.auditLog, logData3 );
|
|
1524
|
+
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1525
|
+
break;
|
|
1526
|
+
|
|
1465
1527
|
case 'left-in-middle':
|
|
1466
1528
|
let leftquery ={
|
|
1467
1529
|
_id: inputData.auditId,
|
|
@@ -1507,7 +1569,6 @@ export async function saveBinary( req, res ) {
|
|
|
1507
1569
|
createdAt: Date.now(),
|
|
1508
1570
|
};
|
|
1509
1571
|
await insertOpenSearchData( openSearch.auditLog, logData1 );
|
|
1510
|
-
logger.info( 'update in binary data', { query: leftquery, update: leftupdate } );
|
|
1511
1572
|
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1512
1573
|
|
|
1513
1574
|
break;
|
|
@@ -1552,13 +1613,12 @@ export async function saveBinary( req, res ) {
|
|
|
1552
1613
|
question: req.userAudit?.question,
|
|
1553
1614
|
result: req.userAudit?.answer,
|
|
1554
1615
|
endTime: Date.now(),
|
|
1555
|
-
timeSpent:
|
|
1616
|
+
timeSpent:timeDifferenceInMinutes,
|
|
1556
1617
|
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1557
1618
|
},
|
|
1558
1619
|
createdAt: Date.now(),
|
|
1559
1620
|
};
|
|
1560
1621
|
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
1561
|
-
logger.info( 'update in binary data', { query: cameraquery, update: cameraupdate } );
|
|
1562
1622
|
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1563
1623
|
|
|
1564
1624
|
break;
|
|
@@ -1781,7 +1841,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1781
1841
|
},
|
|
1782
1842
|
);
|
|
1783
1843
|
}
|
|
1784
|
-
const count = [ '
|
|
1844
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1785
1845
|
if ( count.length == 0 ) {
|
|
1786
1846
|
return res.sendError( 'No Data Found', 204 );
|
|
1787
1847
|
}
|
|
@@ -1826,6 +1886,10 @@ export async function userAuditHistory( req, res ) {
|
|
|
1826
1886
|
temp['User Comments'] = element.userComments;
|
|
1827
1887
|
break;
|
|
1828
1888
|
case 'uniform-detection':
|
|
1889
|
+
// temp['Customer ID'] = element.tempId;
|
|
1890
|
+
// temp['Question'] = element.question;
|
|
1891
|
+
// temp['Result'] = element.answer;
|
|
1892
|
+
// temp['User Comments'] = element.userComments;
|
|
1829
1893
|
temp['Before Count'] = element.beforeCount;
|
|
1830
1894
|
temp['After Count'] = element.afterCount;
|
|
1831
1895
|
temp['Accuracy'] = element.accuracy || '';
|
|
@@ -1853,7 +1917,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1853
1917
|
{
|
|
1854
1918
|
$limit: limit,
|
|
1855
1919
|
} );
|
|
1856
|
-
const result = [ '
|
|
1920
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1857
1921
|
|
|
1858
1922
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1859
1923
|
} catch ( error ) {
|
|
@@ -2178,7 +2242,7 @@ export async function clientMetrics( req, res ) {
|
|
|
2178
2242
|
);
|
|
2179
2243
|
}
|
|
2180
2244
|
|
|
2181
|
-
const count = [ '
|
|
2245
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
2182
2246
|
logger.info( { count: count } );
|
|
2183
2247
|
if ( count.length == 0 ) {
|
|
2184
2248
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -2245,7 +2309,7 @@ export async function clientMetrics( req, res ) {
|
|
|
2245
2309
|
);
|
|
2246
2310
|
}
|
|
2247
2311
|
|
|
2248
|
-
const result = [ '
|
|
2312
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
2249
2313
|
if ( result.length == 0 ) {
|
|
2250
2314
|
return res.sendError( 'No Data Found', 204 );
|
|
2251
2315
|
}
|
|
@@ -2280,7 +2344,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2280
2344
|
}
|
|
2281
2345
|
|
|
2282
2346
|
if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
|
|
2283
|
-
[ '
|
|
2347
|
+
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
2284
2348
|
}
|
|
2285
2349
|
|
|
2286
2350
|
if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
|
|
@@ -2713,8 +2777,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2713
2777
|
},
|
|
2714
2778
|
);
|
|
2715
2779
|
}
|
|
2716
|
-
|
|
2717
|
-
const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2780
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2718
2781
|
|
|
2719
2782
|
|
|
2720
2783
|
if ( count.length == 0 ) {
|
|
@@ -2738,7 +2801,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2738
2801
|
$limit: limit,
|
|
2739
2802
|
} );
|
|
2740
2803
|
}
|
|
2741
|
-
const result = [ '
|
|
2804
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2742
2805
|
if ( inputData.isExport ) {
|
|
2743
2806
|
const exportdata = [];
|
|
2744
2807
|
result.forEach( ( element ) => {
|
|
@@ -2779,6 +2842,11 @@ export async function storeMetrics( req, res ) {
|
|
|
2779
2842
|
temp['Accuracy'] = element.accuracy;
|
|
2780
2843
|
break;
|
|
2781
2844
|
case 'uniform-detection':
|
|
2845
|
+
// temp['Customer ID'] = element.tempId;
|
|
2846
|
+
// temp['Question'] = element.question;
|
|
2847
|
+
// temp['User Comments'] = element.userComments;
|
|
2848
|
+
// temp['Status'] = toCamelCase( element.auditStatus );
|
|
2849
|
+
// temp['Result'] = element.answer;
|
|
2782
2850
|
temp['Before Count'] = element.beforeCount;
|
|
2783
2851
|
temp['After Count'] = element.afterCount;
|
|
2784
2852
|
temp['Status'] = toCamelCase( element.status );
|
|
@@ -3056,7 +3124,7 @@ export async function userMetrics( req, res ) {
|
|
|
3056
3124
|
);
|
|
3057
3125
|
}
|
|
3058
3126
|
|
|
3059
|
-
const count = [ '
|
|
3127
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3060
3128
|
if ( count.length == 0 ) {
|
|
3061
3129
|
return res.sendError( 'No Data Found', 204 );
|
|
3062
3130
|
}
|
|
@@ -3092,7 +3160,7 @@ export async function userMetrics( req, res ) {
|
|
|
3092
3160
|
'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
|
|
3093
3161
|
// 'Mapping Percentage': '$mappingPerc',
|
|
3094
3162
|
};
|
|
3095
|
-
[ '
|
|
3163
|
+
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?
|
|
3096
3164
|
query.push(
|
|
3097
3165
|
{
|
|
3098
3166
|
$project: detection,
|
|
@@ -3106,7 +3174,7 @@ export async function userMetrics( req, res ) {
|
|
|
3106
3174
|
}
|
|
3107
3175
|
|
|
3108
3176
|
|
|
3109
|
-
const result = [ '
|
|
3177
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3110
3178
|
if ( inputData.isExport ) {
|
|
3111
3179
|
await download( result, res );
|
|
3112
3180
|
return;
|
|
@@ -3250,7 +3318,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3250
3318
|
},
|
|
3251
3319
|
);
|
|
3252
3320
|
}
|
|
3253
|
-
const count = [ '
|
|
3321
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3254
3322
|
if ( count.length == 0 ) {
|
|
3255
3323
|
return res.sendError( 'No Data Found', 204 );
|
|
3256
3324
|
}
|
|
@@ -3266,7 +3334,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3266
3334
|
} );
|
|
3267
3335
|
}
|
|
3268
3336
|
|
|
3269
|
-
const result = [ '
|
|
3337
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3270
3338
|
if ( inputData.isExport ) {
|
|
3271
3339
|
const exportdata = [];
|
|
3272
3340
|
result.forEach( ( element ) => {
|
|
@@ -3295,6 +3363,8 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3295
3363
|
temp['Before Count'] = element.beforeCount;
|
|
3296
3364
|
break;
|
|
3297
3365
|
case 'uniform-detection':
|
|
3366
|
+
// temp['Customer ID'] = element.tempId;
|
|
3367
|
+
// temp['Question'] = element.question;
|
|
3298
3368
|
temp['Before Count'] = element.beforeCount;
|
|
3299
3369
|
break;
|
|
3300
3370
|
}
|
|
@@ -3460,7 +3530,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
3460
3530
|
},
|
|
3461
3531
|
];
|
|
3462
3532
|
|
|
3463
|
-
const storeAudit = [ '
|
|
3533
|
+
const storeAudit = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3464
3534
|
if ( storeAudit.length > 0 ) {
|
|
3465
3535
|
temp.inprogressStores= storeAudit[0].inprogressStores;
|
|
3466
3536
|
temp.completedStores = storeAudit[0].completedStores;
|
|
@@ -3648,7 +3718,7 @@ export async function summarySplit( req, res ) {
|
|
|
3648
3718
|
},
|
|
3649
3719
|
},
|
|
3650
3720
|
];
|
|
3651
|
-
const result = [ '
|
|
3721
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3652
3722
|
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3653
3723
|
result[0].totalCount = totalCount[0]?.total;
|
|
3654
3724
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
@@ -3678,7 +3748,7 @@ export async function overviewTable( req, res ) {
|
|
|
3678
3748
|
}
|
|
3679
3749
|
|
|
3680
3750
|
if ( inputData.filterByStatus.length > 0 ) {
|
|
3681
|
-
[ '
|
|
3751
|
+
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3682
3752
|
}
|
|
3683
3753
|
|
|
3684
3754
|
const query =[
|
|
@@ -3795,7 +3865,7 @@ export async function overviewTable( req, res ) {
|
|
|
3795
3865
|
},
|
|
3796
3866
|
);
|
|
3797
3867
|
}
|
|
3798
|
-
const count = [ '
|
|
3868
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3799
3869
|
if ( count.length == 0 ) {
|
|
3800
3870
|
return res.sendError( 'No Data Found', 204 );
|
|
3801
3871
|
}
|
|
@@ -3810,7 +3880,7 @@ export async function overviewTable( req, res ) {
|
|
|
3810
3880
|
$limit: limit,
|
|
3811
3881
|
} );
|
|
3812
3882
|
}
|
|
3813
|
-
const result = [ '
|
|
3883
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3814
3884
|
if ( inputData.isExport ) {
|
|
3815
3885
|
const exportdata = [];
|
|
3816
3886
|
result.forEach( ( element ) => {
|
|
@@ -3847,6 +3917,11 @@ export async function overviewTable( req, res ) {
|
|
|
3847
3917
|
temp['Status'] = toCamelCase( element.status );
|
|
3848
3918
|
break;
|
|
3849
3919
|
case 'uniform-detection':
|
|
3920
|
+
// temp['Customer ID'] = element.tempId;
|
|
3921
|
+
// temp['Question'] = element.question;
|
|
3922
|
+
// temp['User Comments'] = element.userComments;
|
|
3923
|
+
// temp['Audit Type'] = element.auditType;
|
|
3924
|
+
// temp['Status'] = toCamelCase( element.auditStatus );
|
|
3850
3925
|
temp['Before Count'] = element.beforeCount;
|
|
3851
3926
|
temp['After Count'] = element.afterCount;
|
|
3852
3927
|
temp['Audit Type'] = element.auditType;
|
|
@@ -4423,6 +4498,7 @@ export async function getDraftedData( req, res ) {
|
|
|
4423
4498
|
export async function save( req, res ) {
|
|
4424
4499
|
try {
|
|
4425
4500
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
4501
|
+
const sqs = JSON.parse( process.env.SQS );
|
|
4426
4502
|
const inputData = req.body;
|
|
4427
4503
|
const isoDate = req.userAudit?.startTime;
|
|
4428
4504
|
const currentTime = dayjs();
|
|
@@ -4443,10 +4519,55 @@ export async function save( req, res ) {
|
|
|
4443
4519
|
const storeUpdated ={
|
|
4444
4520
|
status: 'completed',
|
|
4445
4521
|
afterCount: inputData.employeeCount,
|
|
4446
|
-
timeSpent:
|
|
4522
|
+
timeSpent:timeDifferenceInMinutes,
|
|
4447
4523
|
};
|
|
4448
|
-
|
|
4449
|
-
await updateOneStoreEmpDetection( query, storeUpdated );
|
|
4524
|
+
logger.info( { query: query, function: 'saveQuery' } );
|
|
4525
|
+
const [ userUpdate, storeUpdate ] = await Promise.all( [ updateOneUserEmpDetection( { _id: inputData.auditId }, userUpdated ), updateOneStoreEmpDetection( query, storeUpdated ) ] );
|
|
4526
|
+
|
|
4527
|
+
logger.info( { userUpdate: userUpdate, storeUpdate: storeUpdate, function: 'saveUpdate' } );
|
|
4528
|
+
const getFilePath = await findOneTraxAuditData(
|
|
4529
|
+
{
|
|
4530
|
+
fileDate: inputData.fileDate,
|
|
4531
|
+
storeId: inputData.storeId,
|
|
4532
|
+
moduleType: inputData.moduleType,
|
|
4533
|
+
},
|
|
4534
|
+
);
|
|
4535
|
+
if ( !getFilePath ) {
|
|
4536
|
+
return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
|
|
4537
|
+
}
|
|
4538
|
+
const tempId=[];
|
|
4539
|
+
if ( inputData.employeeCount > 0 ) {
|
|
4540
|
+
for ( let i =0; i<inputData?.employee.length; i++ ) {
|
|
4541
|
+
tempId.push( inputData?.employee[i].img_id );
|
|
4542
|
+
}
|
|
4543
|
+
}
|
|
4544
|
+
const getStore = await findOneStore( { storeId: inputData.storeId }, { storeName: 1 } );
|
|
4545
|
+
const sqsProduceQueue = {
|
|
4546
|
+
QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
|
|
4547
|
+
MessageBody: JSON.stringify( {
|
|
4548
|
+
storeId: inputData.storeId,
|
|
4549
|
+
storeName: getStore?.storeName,
|
|
4550
|
+
fileDate: inputData.fileDate,
|
|
4551
|
+
moduleType: inputData.moduleType,
|
|
4552
|
+
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
4553
|
+
tempId: tempId,
|
|
4554
|
+
count: inputData.employeeCount,
|
|
4555
|
+
folderPath: getFilePath?.sqs?.Body?.folderPath,
|
|
4556
|
+
} ),
|
|
4557
|
+
};
|
|
4558
|
+
const sqsQueue = await sendMessageToQueue(
|
|
4559
|
+
sqsProduceQueue.QueueUrl,
|
|
4560
|
+
sqsProduceQueue.MessageBody,
|
|
4561
|
+
);
|
|
4562
|
+
|
|
4563
|
+
if ( sqsQueue.statusCode ) {
|
|
4564
|
+
logger.error( {
|
|
4565
|
+
error: `${sqsQueue}`,
|
|
4566
|
+
type: 'UPLOAD_ERROR',
|
|
4567
|
+
} );
|
|
4568
|
+
return res.sendError( 'SQS not sent', 500 );
|
|
4569
|
+
}
|
|
4570
|
+
|
|
4450
4571
|
const logData = {
|
|
4451
4572
|
userId: req.user._id,
|
|
4452
4573
|
userName: req.user.userName,
|
|
@@ -4463,7 +4584,7 @@ export async function save( req, res ) {
|
|
|
4463
4584
|
afterCount: inputData.employeeCount,
|
|
4464
4585
|
startTime: req.userAudit?.startTime,
|
|
4465
4586
|
endTime: Date.now(),
|
|
4466
|
-
timeSpent:
|
|
4587
|
+
timeSpent:timeDifferenceInMinutes,
|
|
4467
4588
|
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
4468
4589
|
},
|
|
4469
4590
|
createdAt: Date.now(),
|
package/src/docs/audit.docs.js
CHANGED
|
@@ -544,6 +544,20 @@ export const auditDocs = {
|
|
|
544
544
|
},
|
|
545
545
|
},
|
|
546
546
|
},
|
|
547
|
+
'/v3/audit/get-user-credit': {
|
|
548
|
+
get: {
|
|
549
|
+
tags: [ 'Audit User Wallet' ],
|
|
550
|
+
description: 'Get single past date credit',
|
|
551
|
+
operationId: 'get-user-credit',
|
|
552
|
+
responses: {
|
|
553
|
+
200: { description: 'Successful' },
|
|
554
|
+
401: { description: 'Unauthorized User' },
|
|
555
|
+
422: { description: 'Field Error' },
|
|
556
|
+
500: { description: 'Server Error' },
|
|
557
|
+
204: { description: 'Not Found' },
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
},
|
|
547
561
|
'/v3/audit/get-user-audit-count': {
|
|
548
562
|
get: {
|
|
549
563
|
tags: [ 'Audit User Wallet' ],
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -51,6 +51,7 @@ export const saveDraftSchema = joi.object( {
|
|
|
51
51
|
storeId: joi.string().required(),
|
|
52
52
|
auditId: joi.string().required(),
|
|
53
53
|
moduleType: joi.string().required(),
|
|
54
|
+
timeSpent: joi.number().required(),
|
|
54
55
|
zoneName: joi.string().required(),
|
|
55
56
|
auditType: joi.string().required(),
|
|
56
57
|
fileDate: joi.string().required(),
|
|
@@ -89,6 +90,7 @@ export const saveSchema = joi.object( {
|
|
|
89
90
|
fileDate: joi.string().required(),
|
|
90
91
|
auditType: joi.string().required(),
|
|
91
92
|
moduleType: joi.string().required(),
|
|
93
|
+
timeSpent: joi.number().required(),
|
|
92
94
|
zoneName: joi.string().required(),
|
|
93
95
|
beforeCount: joi.number().required(),
|
|
94
96
|
junkCount: joi.number().required(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
2
|
+
import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
3
3
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs } from '../controllers/audit.controllers.js';
|
|
4
|
+
import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs, getUserCredit } from '../controllers/audit.controllers.js';
|
|
5
5
|
import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid } from '../dtos/audit.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditRouter = express.Router();
|
|
@@ -37,6 +37,7 @@ auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate(
|
|
|
37
37
|
auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotAssignedCount );
|
|
38
38
|
|
|
39
39
|
// audit user wallet
|
|
40
|
+
auditRouter.get( '/get-user-credit', isAllowedSessionHandler, isAuditUser, getUserCredit );
|
|
40
41
|
auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditCount );
|
|
41
42
|
auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
|
|
42
43
|
|
|
@@ -5,6 +5,10 @@ export function createAuditUserWallet( record ) {
|
|
|
5
5
|
return auditUserWalletModel.create( record );
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
export function findOneAuditUserWallet( record, fields, sort = { createdAt: -1 } ) {
|
|
9
|
+
return auditUserWalletModel.findOne( record, fields ).sort( sort );
|
|
10
|
+
};
|
|
11
|
+
|
|
8
12
|
export function updateManyAuditUserWallet( query, record ) {
|
|
9
13
|
return auditUserWalletModel.updateMany( query, record, { upsert: true } );
|
|
10
14
|
};
|
|
@@ -3,3 +3,7 @@ import auditUsersModel from 'tango-api-schema/schema/auditUsers.model.js';
|
|
|
3
3
|
export function aggregateAuditUsers( query ) {
|
|
4
4
|
return auditUsersModel.aggregate( query );
|
|
5
5
|
};
|
|
6
|
+
|
|
7
|
+
export function findOneAuditUsers( query, fields ) {
|
|
8
|
+
return auditUsersModel.findOne( query, fields );
|
|
9
|
+
};
|