tango-app-api-audit 3.4.3-alpha.17 → 3.4.3-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -356,6 +356,7 @@ export async function getAuditFile( req, res ) {
|
|
|
356
356
|
auditId: userDetails[0]._id,
|
|
357
357
|
moduleType: userDetails[0].moduleType,
|
|
358
358
|
zoneName: userDetails[0].zoneName,
|
|
359
|
+
beforeCount: userDetails[0].beforeCount,
|
|
359
360
|
},
|
|
360
361
|
createdAt: new Date(),
|
|
361
362
|
};
|
|
@@ -458,6 +459,7 @@ export async function getAuditFile( req, res ) {
|
|
|
458
459
|
auditId: reauditInsert._id,
|
|
459
460
|
zoneName: msg.zone_id,
|
|
460
461
|
moduleType: inputData.moduleType,
|
|
462
|
+
beforeCount: msg.total_count,
|
|
461
463
|
},
|
|
462
464
|
createdAt: new Date(),
|
|
463
465
|
};
|
|
@@ -610,6 +612,7 @@ export async function getAuditFile( req, res ) {
|
|
|
610
612
|
auditId: insertData._id,
|
|
611
613
|
zoneName: msg.zone_id,
|
|
612
614
|
moduleType: inputData.moduleType,
|
|
615
|
+
beforeCount: msg.total_count,
|
|
613
616
|
},
|
|
614
617
|
createdAt: new Date(),
|
|
615
618
|
};
|
|
@@ -1239,8 +1242,10 @@ export async function getDraftedData( req, res ) {
|
|
|
1239
1242
|
|
|
1240
1243
|
export async function save( req, res ) {
|
|
1241
1244
|
try {
|
|
1245
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
1242
1246
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
1243
1247
|
const sqs = JSON.parse( process.env.SQS );
|
|
1248
|
+
const auditConfig = JSON.parse( process.env.AUDIT_CONFIG );
|
|
1244
1249
|
const inputData = req.body;
|
|
1245
1250
|
let storeAuditData = await findOneStoreAudit( {
|
|
1246
1251
|
storeId: inputData.storeId,
|
|
@@ -1331,12 +1336,29 @@ export async function save( req, res ) {
|
|
|
1331
1336
|
},
|
|
1332
1337
|
);
|
|
1333
1338
|
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1339
|
+
const logData = {
|
|
1340
|
+
userId: req.user._id,
|
|
1341
|
+
userName: req.user.userName,
|
|
1342
|
+
logType: 'audit',
|
|
1343
|
+
logSubType: 'auditDone',
|
|
1344
|
+
logData: {
|
|
1345
|
+
fileDate: req.userAudit?.fileDate,
|
|
1346
|
+
auditType: req.userAudit?.auditType,
|
|
1347
|
+
storeId: req.userAudit?.storeId,
|
|
1348
|
+
zoneName: req.userAudit?.zoneName,
|
|
1349
|
+
moduleType: req.userAudit?.moduleType,
|
|
1350
|
+
queueName: req.userAudit?.queueName,
|
|
1351
|
+
clientId: req.userAudit?.clientId,
|
|
1352
|
+
beforeCount: req.userAudit?.beforeCount,
|
|
1353
|
+
afterCount: inputData.customerCount,
|
|
1354
|
+
startTime: req.userAudit?.startTime,
|
|
1355
|
+
endTime: Date.now(),
|
|
1356
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1357
|
+
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1358
|
+
},
|
|
1359
|
+
createdAt: Date.now(),
|
|
1360
|
+
};
|
|
1361
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
1340
1362
|
|
|
1341
1363
|
let storeConfig = await findOneStore(
|
|
1342
1364
|
{
|
|
@@ -1401,6 +1423,31 @@ export async function save( req, res ) {
|
|
|
1401
1423
|
timeSpent: timeDifferenceInMinutes,
|
|
1402
1424
|
},
|
|
1403
1425
|
);
|
|
1426
|
+
|
|
1427
|
+
const logData = {
|
|
1428
|
+
userId: req.user._id,
|
|
1429
|
+
userName: req.user.userName,
|
|
1430
|
+
logType: 'audit',
|
|
1431
|
+
logSubType: 'reAuditPush',
|
|
1432
|
+
logData: {
|
|
1433
|
+
fileDate: req.userAudit?.fileDate,
|
|
1434
|
+
auditType: req.userAudit?.auditType,
|
|
1435
|
+
storeId: req.userAudit?.storeId,
|
|
1436
|
+
moduleType: req.userAudit?.moduleType,
|
|
1437
|
+
zoneName: req.userAudit?.zoneName,
|
|
1438
|
+
queueName: req.userAudit?.queueName,
|
|
1439
|
+
clientId: req.userAudit?.clientId,
|
|
1440
|
+
beforeCount: req.userAudit?.beforeCount,
|
|
1441
|
+
afterCount: inputData.customerCount,
|
|
1442
|
+
startTime: req.userAudit?.startTime,
|
|
1443
|
+
endTime: Date.now(),
|
|
1444
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1445
|
+
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1446
|
+
},
|
|
1447
|
+
createdAt: Date.now(),
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
1404
1451
|
} else {
|
|
1405
1452
|
logger.info( 'Hit in Features', {
|
|
1406
1453
|
data: _.omit( inputData, [ 'junk', 'employee', 'customer' ] ),
|
|
@@ -1419,10 +1466,8 @@ export async function save( req, res ) {
|
|
|
1419
1466
|
timeSpent: timeDifferenceInMinutes,
|
|
1420
1467
|
},
|
|
1421
1468
|
);
|
|
1422
|
-
|
|
1423
1469
|
const sqsProduceQueue = {
|
|
1424
|
-
QueueUrl: `${sqs.url}${sqs.feature}`,
|
|
1425
|
-
|
|
1470
|
+
QueueUrl: ( auditConfig?.isCheckMinAfterCount ==1 && auditConfig?.minAfterCount ) >1500? `${sqs.url}${sqs.feature_new}`: `${sqs.url}${sqs.feature}`,
|
|
1426
1471
|
MessageBody: JSON.stringify( {
|
|
1427
1472
|
store_id: inputData.storeId,
|
|
1428
1473
|
store_date: inputData.fileDate,
|
|
@@ -1892,16 +1937,16 @@ export async function clientMetrics( req, res ) {
|
|
|
1892
1937
|
$project: {
|
|
1893
1938
|
'_id': 0,
|
|
1894
1939
|
'File Date': '$fileDate',
|
|
1895
|
-
'
|
|
1896
|
-
'
|
|
1940
|
+
'Brand Name': '$clientName',
|
|
1941
|
+
'Brand Id': '$clientId',
|
|
1897
1942
|
'Product Type': '$moduleType',
|
|
1898
|
-
'Completed Percentage': '$completionPercentage',
|
|
1943
|
+
// 'Completed Percentage': '$completionPercentage',
|
|
1899
1944
|
'Installed Stores': '$installedStore',
|
|
1900
1945
|
'Audit Stores': '$totalFilesCount',
|
|
1901
1946
|
'Inprogress Stores': '$inprogressStoresCount',
|
|
1902
|
-
'Not Assigned': '$notAssignedCount',
|
|
1947
|
+
'Not Assigned stores': '$notAssignedCount',
|
|
1903
1948
|
// 'Not Assigned Stores': '$notAssignedStores',
|
|
1904
|
-
'Completed': '$completedStores',
|
|
1949
|
+
'Completed Stores': '$completedStores',
|
|
1905
1950
|
'Status': '$clientStatus',
|
|
1906
1951
|
},
|
|
1907
1952
|
},
|
|
@@ -2172,34 +2217,36 @@ export async function storeMetrics( req, res ) {
|
|
|
2172
2217
|
if ( element.moduleType == 'zone' ) {
|
|
2173
2218
|
exportData.push( {
|
|
2174
2219
|
'File Date': element.fileDate,
|
|
2175
|
-
'Store ID': element.storeId,
|
|
2176
2220
|
'Store Name': element.storeName,
|
|
2177
|
-
'
|
|
2178
|
-
'Client
|
|
2221
|
+
'Store ID': element.storeId,
|
|
2222
|
+
// 'Client Id': element.clientId,
|
|
2223
|
+
// 'Client Name': element.clientName,
|
|
2224
|
+
'Product Type': element.moduleType,
|
|
2179
2225
|
'Zone Name': element.zoneName,
|
|
2180
2226
|
'User Name': element.userName,
|
|
2181
2227
|
'User Email': element.userEmail,
|
|
2182
2228
|
'Before Count': element.beforeCount,
|
|
2183
2229
|
'After Count': element.afterCount,
|
|
2184
|
-
'Audit Type': element.auditType,
|
|
2185
2230
|
'Accuracy': element.accuracy,
|
|
2186
2231
|
'Time Spent': element.timeSpent,
|
|
2232
|
+
'Audit Type': element.auditType,
|
|
2187
2233
|
'Status': element.status,
|
|
2188
2234
|
} );
|
|
2189
2235
|
} else {
|
|
2190
2236
|
exportData.push( {
|
|
2191
2237
|
'File Date': element.fileDate,
|
|
2192
|
-
'Store ID': element.storeId,
|
|
2193
2238
|
'Store Name': element.storeName,
|
|
2194
|
-
'
|
|
2195
|
-
'Client
|
|
2239
|
+
'Store ID': element.storeId,
|
|
2240
|
+
// 'Client Id': element.clientId,
|
|
2241
|
+
// 'Client Name': element.clientName,
|
|
2242
|
+
'Product Type': element.moduleType,
|
|
2196
2243
|
'User Name': element.userName,
|
|
2197
2244
|
'User Email': element.userEmail,
|
|
2198
2245
|
'Before Count': element.beforeCount,
|
|
2199
2246
|
'After Count': element.afterCount,
|
|
2200
|
-
'Audit Type': element.auditType,
|
|
2201
2247
|
'Accuracy': element.accuracy,
|
|
2202
2248
|
'Time Spent': element.timeSpent,
|
|
2249
|
+
'Audit Type': element.auditType,
|
|
2203
2250
|
'Status': element.status,
|
|
2204
2251
|
} );
|
|
2205
2252
|
}
|
|
@@ -2266,6 +2313,7 @@ export async function userMetrics( req, res ) {
|
|
|
2266
2313
|
totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
|
|
2267
2314
|
beforeCount: 1,
|
|
2268
2315
|
afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
|
|
2316
|
+
createdAt: 1,
|
|
2269
2317
|
},
|
|
2270
2318
|
},
|
|
2271
2319
|
{
|
|
@@ -2278,6 +2326,7 @@ export async function userMetrics( req, res ) {
|
|
|
2278
2326
|
afterCount: { $sum: '$afterCount' },
|
|
2279
2327
|
checkIntime: { $first: '$startTime' },
|
|
2280
2328
|
checkOutTime: { $last: '$endTime' },
|
|
2329
|
+
createdAt: { $first: '$createdAt' },
|
|
2281
2330
|
|
|
2282
2331
|
},
|
|
2283
2332
|
},
|
|
@@ -2303,6 +2352,7 @@ export async function userMetrics( req, res ) {
|
|
|
2303
2352
|
differenceInSeconds: {
|
|
2304
2353
|
$divide: [ { $subtract: [ '$checkOutTime', '$checkIntime' ] }, 1000 ],
|
|
2305
2354
|
},
|
|
2355
|
+
createdAt: 1,
|
|
2306
2356
|
},
|
|
2307
2357
|
},
|
|
2308
2358
|
{
|
|
@@ -2318,6 +2368,7 @@ export async function userMetrics( req, res ) {
|
|
|
2318
2368
|
hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
|
|
2319
2369
|
minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
|
|
2320
2370
|
seconds: { $mod: [ '$differenceInSeconds', 60 ] },
|
|
2371
|
+
createdAt: 1,
|
|
2321
2372
|
},
|
|
2322
2373
|
},
|
|
2323
2374
|
{
|
|
@@ -2352,7 +2403,7 @@ export async function userMetrics( req, res ) {
|
|
|
2352
2403
|
else: { $toString: { $round: [ '$seconds', 0 ] } },
|
|
2353
2404
|
},
|
|
2354
2405
|
},
|
|
2355
|
-
|
|
2406
|
+
createdAt: 1,
|
|
2356
2407
|
},
|
|
2357
2408
|
},
|
|
2358
2409
|
{
|
|
@@ -2370,6 +2421,7 @@ export async function userMetrics( req, res ) {
|
|
|
2370
2421
|
workingHours: {
|
|
2371
2422
|
$concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
|
|
2372
2423
|
},
|
|
2424
|
+
createdAt: 1,
|
|
2373
2425
|
},
|
|
2374
2426
|
},
|
|
2375
2427
|
{
|
|
@@ -2423,6 +2475,7 @@ export async function userMetrics( req, res ) {
|
|
|
2423
2475
|
},
|
|
2424
2476
|
},
|
|
2425
2477
|
workingHours: 1,
|
|
2478
|
+
createdAt: 1,
|
|
2426
2479
|
},
|
|
2427
2480
|
},
|
|
2428
2481
|
];
|
|
@@ -2460,15 +2513,17 @@ export async function userMetrics( req, res ) {
|
|
|
2460
2513
|
{
|
|
2461
2514
|
$project: {
|
|
2462
2515
|
'_id': 0,
|
|
2463
|
-
'File Date': '$fileDate',
|
|
2464
2516
|
'User Name': '$userName',
|
|
2465
|
-
'
|
|
2517
|
+
'File Date': '$fileDate',
|
|
2518
|
+
'Completed Files': '$totalCompletedFiles',
|
|
2519
|
+
'Product Type': '$moduleType',
|
|
2466
2520
|
'Total Before Count': '$beforeCount',
|
|
2467
2521
|
'Total After Count': '$afterCount',
|
|
2468
|
-
'check Intime': '$checkIntime',
|
|
2469
|
-
'check OutTime': '$checkOutTime',
|
|
2470
|
-
'working Hours': '$workingHours',
|
|
2471
2522
|
'Mapping Percentage': '$mappingPerc',
|
|
2523
|
+
'Check Intime': '$checkIntime',
|
|
2524
|
+
'Check OutTime': '$checkOutTime',
|
|
2525
|
+
'Working Hours': '$workingHours',
|
|
2526
|
+
'Audited Date': { $dateToString: { format: '%Y,%b %d', date: '$createdAt' } },
|
|
2472
2527
|
},
|
|
2473
2528
|
},
|
|
2474
2529
|
);
|
|
@@ -3812,11 +3867,11 @@ export async function auditImages( req, res ) {
|
|
|
3812
3867
|
export async function getUserAuditCount( req, res ) {
|
|
3813
3868
|
try {
|
|
3814
3869
|
const userWallet = JSON.parse( process.env.USER_WALLET );
|
|
3815
|
-
const previousDate = dayjs( new Date() ).subtract(
|
|
3870
|
+
const previousDate = dayjs( new Date() ).subtract( 19, 'days' );
|
|
3816
3871
|
const fileDate = dayjs( previousDate ).format( 'DD-MM-YYYY' );
|
|
3817
3872
|
const configTimeSpentSec = userWallet.minTimeSpentSec; // 18000;
|
|
3818
|
-
const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
|
|
3819
|
-
const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
|
|
3873
|
+
// const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
|
|
3874
|
+
// const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
|
|
3820
3875
|
const reduce = userWallet.reductionPerc; // 0.05;
|
|
3821
3876
|
const auditUserQuery=[
|
|
3822
3877
|
{
|
|
@@ -3925,6 +3980,11 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3925
3980
|
}
|
|
3926
3981
|
const zoneMinimumTarget =userCount[0]?.zoneUserCount?.length !== 0 && userCount[0]?.zoneFilesCount !==0 ? Math.floor( userCount[0].zoneFilesCount/userCount[0].zoneUserCount.length ) : 0;
|
|
3927
3982
|
const trafficMinimumTarget =userCount[0]?.trafficUserCount?.length !== 0 && userCount[0]?.trafficFilesCount !==0 ? Math.floor( userCount[0].trafficFilesCount/userCount[0].trafficUserCount.length ) : 0;
|
|
3983
|
+
|
|
3984
|
+
const beforeCountTraffic = 544/trafficMinimumTarget;
|
|
3985
|
+
const beforeCountZone = 544/zoneMinimumTarget; // 0.0035;
|
|
3986
|
+
const afterCountCredit = 136;
|
|
3987
|
+
|
|
3928
3988
|
const query = [
|
|
3929
3989
|
{
|
|
3930
3990
|
$match: {
|
|
@@ -3938,7 +3998,8 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3938
3998
|
},
|
|
3939
3999
|
},
|
|
3940
4000
|
{
|
|
3941
|
-
$set: { minimumTarget: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, trafficMinimumTarget, zoneMinimumTarget ] }
|
|
4001
|
+
$set: { minimumTarget: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, trafficMinimumTarget, zoneMinimumTarget ] },
|
|
4002
|
+
afterCountCredit: afterCountCredit },
|
|
3942
4003
|
},
|
|
3943
4004
|
{
|
|
3944
4005
|
$project: {
|
|
@@ -3950,7 +4011,9 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3950
4011
|
fileDate: 1,
|
|
3951
4012
|
fileDateISO: 1,
|
|
3952
4013
|
minimumTarget: 1,
|
|
4014
|
+
afterCountCredit: 1,
|
|
3953
4015
|
totalEarn: { $ifNull: [ 0, 0 ] },
|
|
4016
|
+
singleImageAmount: { $ifNull: [ 0, 0 ] },
|
|
3954
4017
|
totalReducedAmount: { $ifNull: [ 0, 0 ] },
|
|
3955
4018
|
totalCredit: { $ifNull: [ 0, 0 ] },
|
|
3956
4019
|
deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
|
|
@@ -3969,11 +4032,13 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3969
4032
|
fileDateISO: { $first: '$fileDateISO' },
|
|
3970
4033
|
userId: { $first: '$userId' },
|
|
3971
4034
|
minimumTarget: { $first: '$minimumTarget' },
|
|
4035
|
+
afterCountCredit: { $first: '$afterCountCredit' },
|
|
3972
4036
|
totalEarn: { $first: '$totalEarn' },
|
|
3973
4037
|
totalReducedAmount: { $first: '$totalReducedAmount' },
|
|
3974
4038
|
totalCredit: { $first: '$totalCredit' },
|
|
3975
4039
|
deductionByMinimumTarget: { $first: '$deductionByMinimumTarget' },
|
|
3976
4040
|
deductionBytimeSpent: { $first: '$deductionBytimeSpent' },
|
|
4041
|
+
singleImageAmount: { $first: '$singleImageAmount' },
|
|
3977
4042
|
},
|
|
3978
4043
|
},
|
|
3979
4044
|
{
|
|
@@ -3987,12 +4052,35 @@ export async function getUserAuditCount( req, res ) {
|
|
|
3987
4052
|
fileDate: 1,
|
|
3988
4053
|
fileDateISO: 1,
|
|
3989
4054
|
minimumTarget: 1,
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
4055
|
+
singleImageAmount: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, beforeCountTraffic, beforeCountZone ] },
|
|
4056
|
+
beforeCountCredit: { $multiply: [ '$totalBeforeCount', { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, beforeCountTraffic, beforeCountZone ] } ] },
|
|
4057
|
+
// afterCountCredit: { $cond: [ { $and: [
|
|
4058
|
+
// { $gte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.4 ] }, { $lte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4059
|
+
// ] }, 136,
|
|
4060
|
+
// {
|
|
4061
|
+
// $cond: [ { $gt: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4062
|
+
// { $subtract: [ 136, { $multiply: [ { $subtract: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] }, 136 ] } ] },
|
|
4063
|
+
// { $subtract: [ 136, { $multiply: [ { $subtract: [ 0.4, { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] } ] }, 136 ] } ] },
|
|
4064
|
+
// ],
|
|
4065
|
+
// },
|
|
4066
|
+
// ] },
|
|
4067
|
+
afterCountCredit: afterCountCredit,
|
|
4068
|
+
totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, beforeCountTraffic, beforeCountZone ] } ] }, 136 ] },
|
|
3993
4069
|
deductionBytimeSpent: 1,
|
|
3994
4070
|
deductionByMinimumTarget: 1,
|
|
3995
|
-
|
|
4071
|
+
mappingperc: { $multiply: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 100 ] },
|
|
4072
|
+
deductionByMapping: { $cond: [ { $and: [
|
|
4073
|
+
{ $gte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.4 ] }, { $lte: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4074
|
+
] }, 0,
|
|
4075
|
+
{
|
|
4076
|
+
$cond: [ { $gt: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] },
|
|
4077
|
+
{ $multiply: [ { $subtract: [ { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] }, 0.7 ] }, 136 ] },
|
|
4078
|
+
{ $multiply: [ { $subtract: [ 0.4, { $divide: [ '$totalAfterCount', '$totalBeforeCount' ] } ] }, 136 ] },
|
|
4079
|
+
],
|
|
4080
|
+
},
|
|
4081
|
+
] },
|
|
4082
|
+
totalReducedAmount: 1,
|
|
4083
|
+
totalCredit: 1,
|
|
3996
4084
|
|
|
3997
4085
|
},
|
|
3998
4086
|
},
|
|
@@ -4015,6 +4103,9 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4015
4103
|
fileDate: 1,
|
|
4016
4104
|
fileDateISO: 1,
|
|
4017
4105
|
minimumTarget: 1,
|
|
4106
|
+
singleImageAmount: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, beforeCountTraffic, beforeCountZone ] },
|
|
4107
|
+
beforeCountCredit: 1,
|
|
4108
|
+
afterCountCredit: 1,
|
|
4018
4109
|
totalEarn: 1,
|
|
4019
4110
|
deductionBytimeSpent: { $cond: [
|
|
4020
4111
|
{ $lt: [ '$totalTimeSpent', configTimeSpentSec ] },
|
|
@@ -4026,8 +4117,11 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4026
4117
|
{ $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
|
|
4027
4118
|
{ $multiply: [ reduce, '$totalEarn' ] }, '$deductionByMinimumTarget',
|
|
4028
4119
|
] },
|
|
4120
|
+
mappingperc: 1,
|
|
4121
|
+
deductionByMapping: 1,
|
|
4029
4122
|
totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
|
|
4030
4123
|
|
|
4124
|
+
|
|
4031
4125
|
},
|
|
4032
4126
|
},
|
|
4033
4127
|
|
|
@@ -4060,11 +4154,17 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4060
4154
|
fileDate: 1,
|
|
4061
4155
|
fileDateISO: 1,
|
|
4062
4156
|
minimumTarget: 1,
|
|
4063
|
-
|
|
4157
|
+
beforeCountCredit: 1,
|
|
4158
|
+
afterCountCredit: 1,
|
|
4159
|
+
totalEarn: 1,
|
|
4064
4160
|
deductionByMinimumTarget: 1,
|
|
4161
|
+
singleImageAmount: 1,
|
|
4065
4162
|
deductionBytimeSpent: 1,
|
|
4163
|
+
mappingperc: 1,
|
|
4164
|
+
deductionByMapping: 1,
|
|
4066
4165
|
totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
|
|
4067
|
-
totalReducedAmount: { $round: [ { $add: [ '$deductionBytimeSpent', '$deductionByMinimumTarget' ] }, 2 ] },
|
|
4166
|
+
totalReducedAmount: { $round: [ { $add: [ '$deductionBytimeSpent', '$deductionByMinimumTarget', '$deductionByMapping' ] }, 2 ] },
|
|
4167
|
+
|
|
4068
4168
|
},
|
|
4069
4169
|
},
|
|
4070
4170
|
{
|
|
@@ -4099,14 +4199,20 @@ export async function getUserAuditCount( req, res ) {
|
|
|
4099
4199
|
timeSpent: '$totalTimeSpent',
|
|
4100
4200
|
fileDate: 1,
|
|
4101
4201
|
fileDateISO: 1,
|
|
4202
|
+
beforeCountCredit: 1,
|
|
4203
|
+
afterCountCredit: 1,
|
|
4204
|
+
totalEarn: { $round: [ '$totalEarn', 2 ] },
|
|
4205
|
+
minimumTarget: 1,
|
|
4206
|
+
singleImageAmount: 1,
|
|
4102
4207
|
deductionByMinimumTarget: { $round: [ '$deductionByMinimumTarget', 2 ] },
|
|
4103
4208
|
deductionBytimeSpent: { $round: [ '$deductionBytimeSpent', 2 ] },
|
|
4209
|
+
mappingperc: 1,
|
|
4210
|
+
deductionByMapping: 1,
|
|
4104
4211
|
totalReducedAmount: 1,
|
|
4105
4212
|
totalCredit: { $round: [ { $subtract: [ '$totalEarn', '$totalReducedAmount' ] }, 2 ] },
|
|
4106
|
-
totalEarn: { $round: [ '$totalEarn', 2 ] },
|
|
4107
|
-
minimumTarget: 1,
|
|
4108
4213
|
userEmail: '$users.email', // Access first element from array
|
|
4109
|
-
userName: '$users.userName', // Access first element from array
|
|
4214
|
+
userName: '$users.userName', // Access first element from array,
|
|
4215
|
+
|
|
4110
4216
|
},
|
|
4111
4217
|
},
|
|
4112
4218
|
];
|
|
@@ -4452,8 +4558,12 @@ export async function auditViewLogs( req, res ) {
|
|
|
4452
4558
|
'logData.moduleType.keyword': inputData.moduleType,
|
|
4453
4559
|
},
|
|
4454
4560
|
},
|
|
4561
|
+
{
|
|
4562
|
+
'terms': {
|
|
4563
|
+
'logSubType.keyword': [ 'auditDone', 'reAuditPush', 'reTrigger' ],
|
|
4564
|
+
},
|
|
4565
|
+
},
|
|
4455
4566
|
],
|
|
4456
|
-
|
|
4457
4567
|
},
|
|
4458
4568
|
},
|
|
4459
4569
|
};
|
|
@@ -4462,7 +4572,7 @@ export async function auditViewLogs( req, res ) {
|
|
|
4462
4572
|
logData.push( logs.body.hits.hits[0]._source );
|
|
4463
4573
|
return res.sendSuccess( logData );
|
|
4464
4574
|
} else {
|
|
4465
|
-
return res.sendError( 'No Record Inserted',
|
|
4575
|
+
return res.sendError( 'No Record Inserted', 204 );
|
|
4466
4576
|
}
|
|
4467
4577
|
} catch ( error ) {
|
|
4468
4578
|
const err = error.message || 'Internal Server Error';
|
|
@@ -1403,6 +1403,7 @@ export async function getUpdatedFile( req, res ) {
|
|
|
1403
1403
|
|
|
1404
1404
|
export async function saveBinary( req, res ) {
|
|
1405
1405
|
try {
|
|
1406
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
1406
1407
|
const inputData = req.body;
|
|
1407
1408
|
const isoDate = req.userAudit?.startTime;
|
|
1408
1409
|
const currentTime = dayjs();
|
|
@@ -1476,6 +1477,31 @@ export async function saveBinary( req, res ) {
|
|
|
1476
1477
|
};
|
|
1477
1478
|
let updatDatacamera= await updateOneBinaryAuditModel( cameraquery, cameraupdate );
|
|
1478
1479
|
if ( updatDatacamera.modifiedCount==0 ) {
|
|
1480
|
+
const logData = {
|
|
1481
|
+
userId: req.user._id,
|
|
1482
|
+
userName: req.user.userName,
|
|
1483
|
+
logType: 'traxAudit',
|
|
1484
|
+
logSubType: 'auditDone',
|
|
1485
|
+
logData: {
|
|
1486
|
+
fileDate: req.userAudit?.fileDate,
|
|
1487
|
+
auditType: req.userAudit?.auditType,
|
|
1488
|
+
storeId: req.userAudit?.storeId,
|
|
1489
|
+
moduleType: req.userAudit?.moduleType,
|
|
1490
|
+
queueName: req.userAudit?.queueName,
|
|
1491
|
+
clientId: req.userAudit?.clientId,
|
|
1492
|
+
beforeCount: req.userAudit?.beforeCount,
|
|
1493
|
+
afterCount: inputData.employeeCount,
|
|
1494
|
+
startTime: req.userAudit?.startTime,
|
|
1495
|
+
streamName: req.userAudit?.streamName,
|
|
1496
|
+
tempId: req.userAudit?.tempId,
|
|
1497
|
+
question: req.userAudit?.question,
|
|
1498
|
+
endTime: Date.now(),
|
|
1499
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1500
|
+
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1501
|
+
},
|
|
1502
|
+
createdAt: Date.now(),
|
|
1503
|
+
};
|
|
1504
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
1479
1505
|
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1480
1506
|
}
|
|
1481
1507
|
logger.info( 'update in binary data', { query: cameraquery, update: cameraupdate } );
|
|
@@ -1731,15 +1757,18 @@ export async function userAuditHistory( req, res ) {
|
|
|
1731
1757
|
switch ( inputData.moduleType ) {
|
|
1732
1758
|
case 'camera-angle-change':
|
|
1733
1759
|
temp['stream Name'] = element.streamName;
|
|
1760
|
+
temp['Result'] = element.answer;
|
|
1734
1761
|
temp['User Comments'] = element.userComments;
|
|
1735
1762
|
break;
|
|
1736
1763
|
case 'unattended-customer':
|
|
1737
1764
|
temp['Customer ID'] = element.tempId;
|
|
1738
1765
|
temp['Question'] = element.question;
|
|
1766
|
+
temp['Result'] = element.answer;
|
|
1739
1767
|
temp['User Comments'] = element.userComments;
|
|
1740
1768
|
break;
|
|
1741
1769
|
case 'left-in-middle':
|
|
1742
1770
|
temp['Question'] = element.question;
|
|
1771
|
+
temp['Result'] = element.answer;
|
|
1743
1772
|
temp['User Comments'] = element.userComments;
|
|
1744
1773
|
break;
|
|
1745
1774
|
case 'uniform-detection':
|
|
@@ -2088,16 +2117,16 @@ export async function clientMetrics( req, res ) {
|
|
|
2088
2117
|
$project: {
|
|
2089
2118
|
'_id': 0,
|
|
2090
2119
|
'File Date': '$fileDate',
|
|
2091
|
-
'
|
|
2092
|
-
'
|
|
2120
|
+
'Brand Name': '$clientName',
|
|
2121
|
+
'Brand Id': '$clientId',
|
|
2093
2122
|
'Product Type': '$value',
|
|
2094
|
-
'Completed Percentage': '$completionPercentage',
|
|
2123
|
+
// 'Completed Percentage': '$completionPercentage',
|
|
2095
2124
|
'Installed Stores': '$installedStore',
|
|
2096
2125
|
'Audit Stores': '$totalFilesCount',
|
|
2097
2126
|
'Inprogress Stores': '$inprogressStoresCount',
|
|
2098
|
-
'Not Assigned': '$notAssignedCount',
|
|
2127
|
+
'Not Assigned Stores': '$notAssignedCount',
|
|
2099
2128
|
// 'Not Assigned Stores': '$notAssignedStores',
|
|
2100
|
-
'Completed': '$completedStores',
|
|
2129
|
+
'Completed Stores': '$completedStores',
|
|
2101
2130
|
'Status': '$clientStatus',
|
|
2102
2131
|
},
|
|
2103
2132
|
},
|
|
@@ -2201,10 +2230,10 @@ export async function storeMetrics( req, res ) {
|
|
|
2201
2230
|
question: 1,
|
|
2202
2231
|
questionType: 1,
|
|
2203
2232
|
answer: 1,
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
userId: 1,
|
|
2233
|
+
userId: {
|
|
2234
|
+
$arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], // need to check if no data
|
|
2235
|
+
},
|
|
2236
|
+
// userId: 1,
|
|
2208
2237
|
auditType: 1,
|
|
2209
2238
|
beforeCount: 1,
|
|
2210
2239
|
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
@@ -2579,7 +2608,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2579
2608
|
'User Email': element.userEmail,
|
|
2580
2609
|
'Audit Type': element.auditType,
|
|
2581
2610
|
'Time Spent': element.timeSpent,
|
|
2582
|
-
'Result': element.answer,
|
|
2583
2611
|
};
|
|
2584
2612
|
switch ( inputData.moduleType ) {
|
|
2585
2613
|
case 'camera-angle-change':
|
|
@@ -2676,7 +2704,7 @@ export async function userMetrics( req, res ) {
|
|
|
2676
2704
|
totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
|
|
2677
2705
|
beforeCount: 1,
|
|
2678
2706
|
afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
|
|
2679
|
-
|
|
2707
|
+
createdAt: 1,
|
|
2680
2708
|
value: {
|
|
2681
2709
|
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' },
|
|
2682
2710
|
} },
|
|
@@ -2693,6 +2721,7 @@ export async function userMetrics( req, res ) {
|
|
|
2693
2721
|
checkOutTime: { $last: '$endTime' },
|
|
2694
2722
|
moduleType: { $last: '$moduleType' },
|
|
2695
2723
|
value: { $last: '$value' },
|
|
2724
|
+
createdAt: { $first: '$createdAt' },
|
|
2696
2725
|
},
|
|
2697
2726
|
},
|
|
2698
2727
|
{
|
|
@@ -2705,6 +2734,7 @@ export async function userMetrics( req, res ) {
|
|
|
2705
2734
|
value: 1,
|
|
2706
2735
|
beforeCount: 1,
|
|
2707
2736
|
afterCount: 1,
|
|
2737
|
+
createdAt: 1,
|
|
2708
2738
|
// mappingPerc: { $round: [
|
|
2709
2739
|
// { $multiply: [
|
|
2710
2740
|
// { $divide: [ '$afterCount', '$beforeCount' ] }, 100,
|
|
@@ -2732,6 +2762,7 @@ export async function userMetrics( req, res ) {
|
|
|
2732
2762
|
hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
|
|
2733
2763
|
minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
|
|
2734
2764
|
seconds: { $mod: [ '$differenceInSeconds', 60 ] },
|
|
2765
|
+
createdAt: 1,
|
|
2735
2766
|
},
|
|
2736
2767
|
},
|
|
2737
2768
|
{
|
|
@@ -2746,6 +2777,7 @@ export async function userMetrics( req, res ) {
|
|
|
2746
2777
|
checkOutTime: 1,
|
|
2747
2778
|
moduleType: 1,
|
|
2748
2779
|
value: 1,
|
|
2780
|
+
createdAt: 1,
|
|
2749
2781
|
// mappingPerc: 1,
|
|
2750
2782
|
hours: {
|
|
2751
2783
|
$cond: {
|
|
@@ -2781,6 +2813,7 @@ export async function userMetrics( req, res ) {
|
|
|
2781
2813
|
checkIntime: 1,
|
|
2782
2814
|
checkOutTime: 1,
|
|
2783
2815
|
moduleType: 1,
|
|
2816
|
+
createdAt: 1,
|
|
2784
2817
|
value: {
|
|
2785
2818
|
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' },
|
|
2786
2819
|
},
|
|
@@ -2844,6 +2877,7 @@ export async function userMetrics( req, res ) {
|
|
|
2844
2877
|
timezone: 'Asia/Kolkata',
|
|
2845
2878
|
},
|
|
2846
2879
|
},
|
|
2880
|
+
createdAt: 1,
|
|
2847
2881
|
workingHours: 1,
|
|
2848
2882
|
},
|
|
2849
2883
|
},
|
|
@@ -2880,26 +2914,28 @@ export async function userMetrics( req, res ) {
|
|
|
2880
2914
|
if ( inputData.isExport ) {
|
|
2881
2915
|
const detection = {
|
|
2882
2916
|
'_id': 0,
|
|
2883
|
-
'File Date': '$fileDate',
|
|
2884
2917
|
'User Name': '$userName',
|
|
2885
|
-
'
|
|
2918
|
+
'File Date': '$fileDate',
|
|
2919
|
+
'Completed Files': '$totalCompletedFiles',
|
|
2920
|
+
'Product Type': '$value',
|
|
2886
2921
|
'Total Before Count': '$beforeCount',
|
|
2887
2922
|
'Total After Count': '$afterCount',
|
|
2888
|
-
'
|
|
2889
|
-
'
|
|
2890
|
-
'
|
|
2891
|
-
'
|
|
2923
|
+
'Check Intime': '$checkIntime',
|
|
2924
|
+
'Check OutTime': '$checkOutTime',
|
|
2925
|
+
'Working Hours': '$workingHours',
|
|
2926
|
+
'Audited Date': { $dateToString: { format: '%Y,%b %d', date: '$createdAt' } },
|
|
2892
2927
|
// 'Mapping Percentage': '$mappingPerc',
|
|
2893
2928
|
};
|
|
2894
2929
|
const YesNo = {
|
|
2895
2930
|
'_id': 0,
|
|
2896
|
-
'File Date': '$fileDate',
|
|
2897
2931
|
'User Name': '$userName',
|
|
2898
|
-
'
|
|
2899
|
-
'
|
|
2900
|
-
'check OutTime': '$checkOutTime',
|
|
2901
|
-
'working Hours': '$workingHours',
|
|
2932
|
+
'File Date': '$fileDate',
|
|
2933
|
+
'Completed Files': '$totalCompletedFiles',
|
|
2902
2934
|
'Product Type': '$value',
|
|
2935
|
+
'Check Intime': '$checkIntime',
|
|
2936
|
+
'Check OutTime': '$checkOutTime',
|
|
2937
|
+
'Working Hours': '$workingHours',
|
|
2938
|
+
'Audited Date': { $dateToString: { format: '%Y,%b %d', date: '$createdAt' } },
|
|
2903
2939
|
// 'Mapping Percentage': '$mappingPerc',
|
|
2904
2940
|
};
|
|
2905
2941
|
[ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?
|
|
@@ -4232,6 +4268,7 @@ export async function getDraftedData( req, res ) {
|
|
|
4232
4268
|
|
|
4233
4269
|
export async function save( req, res ) {
|
|
4234
4270
|
try {
|
|
4271
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
4235
4272
|
const inputData = req.body;
|
|
4236
4273
|
const isoDate = req.userAudit?.startTime;
|
|
4237
4274
|
const currentTime = dayjs();
|
|
@@ -4256,6 +4293,28 @@ export async function save( req, res ) {
|
|
|
4256
4293
|
};
|
|
4257
4294
|
await updateOneUserEmpDetection( { _id: inputData.auditId }, userUpdated );
|
|
4258
4295
|
await updateOneStoreEmpDetection( query, storeUpdated );
|
|
4296
|
+
const logData = {
|
|
4297
|
+
userId: req.user._id,
|
|
4298
|
+
userName: req.user.userName,
|
|
4299
|
+
logType: 'traxAudit',
|
|
4300
|
+
logSubType: 'auditDone',
|
|
4301
|
+
logData: {
|
|
4302
|
+
fileDate: getUserAuditData?.fileDate,
|
|
4303
|
+
auditType: getUserAuditData?.auditType,
|
|
4304
|
+
storeId: getUserAuditData?.storeId,
|
|
4305
|
+
moduleType: getUserAuditData?.moduleType,
|
|
4306
|
+
queueName: req.userAudit?.queueName,
|
|
4307
|
+
clientId: req.userAudit?.clientId,
|
|
4308
|
+
beforeCount: req.userAudit?.beforeCount,
|
|
4309
|
+
afterCount: inputData.employeeCount,
|
|
4310
|
+
startTime: req.userAudit?.startTime,
|
|
4311
|
+
endTime: Date.now(),
|
|
4312
|
+
timeSpent: timeDifferenceInMinutes,
|
|
4313
|
+
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
4314
|
+
},
|
|
4315
|
+
createdAt: Date.now(),
|
|
4316
|
+
};
|
|
4317
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
4259
4318
|
return res.sendSuccess( { result: 'Updated Successfully' } );
|
|
4260
4319
|
} else {
|
|
4261
4320
|
return res.sendError( 'something went wrong', 403 );
|
|
@@ -3,14 +3,14 @@ import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
|
3
3
|
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
|
|
4
4
|
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
5
5
|
import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save, reTrigger } from '../controllers/traxAudit.controllers.js';
|
|
6
|
-
import { isMappingAuditInputFolderExist, isTraxAuditDocumentExist, isuserEmpDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
|
|
6
|
+
import { isMappingAuditInputFolderExist, isTraxAuditDocumentExist, isuserEmpDocumentExist, validateBinaryAudit, validateUserEmpDetection } from '../validation/traxAuditValidation.js';
|
|
7
7
|
|
|
8
8
|
export const traxAuditRouter = Router();
|
|
9
9
|
|
|
10
10
|
// Audit Mapping
|
|
11
11
|
|
|
12
12
|
traxAuditRouter.get( '/get-file-detection', isAllowedSessionHandler, validate( getDetectionFileValid ), isExistsQueue, getDetectionAuditFile );
|
|
13
|
-
traxAuditRouter.post( '/save', validate( saveValid ), isAllowedSessionHandler, save );
|
|
13
|
+
traxAuditRouter.post( '/save', validate( saveValid ), isAllowedSessionHandler, validateUserEmpDetection, save );
|
|
14
14
|
traxAuditRouter.post( '/save-draft', validate( saveDraftValid ), isAllowedSessionHandler, saveDraft );
|
|
15
15
|
traxAuditRouter.get( '/get-drafted-data', validate( getDraftedDataValid ), isAllowedSessionHandler, getDraftedData );
|
|
16
16
|
|