tango-app-api-audit 3.4.3-alpha.18 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.4.3-alpha.18",
3
+ "version": "3.4.3-alpha.19",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1242,8 +1242,10 @@ export async function getDraftedData( req, res ) {
1242
1242
 
1243
1243
  export async function save( req, res ) {
1244
1244
  try {
1245
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
1245
1246
  const bucket = JSON.parse( process.env.BUCKET );
1246
1247
  const sqs = JSON.parse( process.env.SQS );
1248
+ const auditConfig = JSON.parse( process.env.AUDIT_CONFIG );
1247
1249
  const inputData = req.body;
1248
1250
  let storeAuditData = await findOneStoreAudit( {
1249
1251
  storeId: inputData.storeId,
@@ -1334,12 +1336,29 @@ export async function save( req, res ) {
1334
1336
  },
1335
1337
  );
1336
1338
 
1337
- /** *
1338
- *
1339
- * logs need to be added
1340
- *
1341
- *
1342
- */
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 );
1343
1362
 
1344
1363
  let storeConfig = await findOneStore(
1345
1364
  {
@@ -1404,6 +1423,31 @@ export async function save( req, res ) {
1404
1423
  timeSpent: timeDifferenceInMinutes,
1405
1424
  },
1406
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 );
1407
1451
  } else {
1408
1452
  logger.info( 'Hit in Features', {
1409
1453
  data: _.omit( inputData, [ 'junk', 'employee', 'customer' ] ),
@@ -1422,10 +1466,8 @@ export async function save( req, res ) {
1422
1466
  timeSpent: timeDifferenceInMinutes,
1423
1467
  },
1424
1468
  );
1425
-
1426
1469
  const sqsProduceQueue = {
1427
- QueueUrl: `${sqs.url}${sqs.feature}`,
1428
-
1470
+ QueueUrl: ( auditConfig?.isCheckMinAfterCount ==1 && auditConfig?.minAfterCount ) >1500? `${sqs.url}${sqs.feature_new}`: `${sqs.url}${sqs.feature}`,
1429
1471
  MessageBody: JSON.stringify( {
1430
1472
  store_id: inputData.storeId,
1431
1473
  store_date: inputData.fileDate,
@@ -1895,16 +1937,16 @@ export async function clientMetrics( req, res ) {
1895
1937
  $project: {
1896
1938
  '_id': 0,
1897
1939
  'File Date': '$fileDate',
1898
- 'Client Name': '$clientName',
1899
- 'Client Id': '$clientId',
1940
+ 'Brand Name': '$clientName',
1941
+ 'Brand Id': '$clientId',
1900
1942
  'Product Type': '$moduleType',
1901
- 'Completed Percentage': '$completionPercentage',
1943
+ // 'Completed Percentage': '$completionPercentage',
1902
1944
  'Installed Stores': '$installedStore',
1903
1945
  'Audit Stores': '$totalFilesCount',
1904
1946
  'Inprogress Stores': '$inprogressStoresCount',
1905
- 'Not Assigned': '$notAssignedCount',
1947
+ 'Not Assigned stores': '$notAssignedCount',
1906
1948
  // 'Not Assigned Stores': '$notAssignedStores',
1907
- 'Completed': '$completedStores',
1949
+ 'Completed Stores': '$completedStores',
1908
1950
  'Status': '$clientStatus',
1909
1951
  },
1910
1952
  },
@@ -2175,34 +2217,36 @@ export async function storeMetrics( req, res ) {
2175
2217
  if ( element.moduleType == 'zone' ) {
2176
2218
  exportData.push( {
2177
2219
  'File Date': element.fileDate,
2178
- 'Store ID': element.storeId,
2179
2220
  'Store Name': element.storeName,
2180
- 'Client Id': element.clientId,
2181
- 'Client Name': element.clientName,
2221
+ 'Store ID': element.storeId,
2222
+ // 'Client Id': element.clientId,
2223
+ // 'Client Name': element.clientName,
2224
+ 'Product Type': element.moduleType,
2182
2225
  'Zone Name': element.zoneName,
2183
2226
  'User Name': element.userName,
2184
2227
  'User Email': element.userEmail,
2185
2228
  'Before Count': element.beforeCount,
2186
2229
  'After Count': element.afterCount,
2187
- 'Audit Type': element.auditType,
2188
2230
  'Accuracy': element.accuracy,
2189
2231
  'Time Spent': element.timeSpent,
2232
+ 'Audit Type': element.auditType,
2190
2233
  'Status': element.status,
2191
2234
  } );
2192
2235
  } else {
2193
2236
  exportData.push( {
2194
2237
  'File Date': element.fileDate,
2195
- 'Store ID': element.storeId,
2196
2238
  'Store Name': element.storeName,
2197
- 'Client Id': element.clientId,
2198
- 'Client Name': element.clientName,
2239
+ 'Store ID': element.storeId,
2240
+ // 'Client Id': element.clientId,
2241
+ // 'Client Name': element.clientName,
2242
+ 'Product Type': element.moduleType,
2199
2243
  'User Name': element.userName,
2200
2244
  'User Email': element.userEmail,
2201
2245
  'Before Count': element.beforeCount,
2202
2246
  'After Count': element.afterCount,
2203
- 'Audit Type': element.auditType,
2204
2247
  'Accuracy': element.accuracy,
2205
2248
  'Time Spent': element.timeSpent,
2249
+ 'Audit Type': element.auditType,
2206
2250
  'Status': element.status,
2207
2251
  } );
2208
2252
  }
@@ -2269,6 +2313,7 @@ export async function userMetrics( req, res ) {
2269
2313
  totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
2270
2314
  beforeCount: 1,
2271
2315
  afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
2316
+ createdAt: 1,
2272
2317
  },
2273
2318
  },
2274
2319
  {
@@ -2281,6 +2326,7 @@ export async function userMetrics( req, res ) {
2281
2326
  afterCount: { $sum: '$afterCount' },
2282
2327
  checkIntime: { $first: '$startTime' },
2283
2328
  checkOutTime: { $last: '$endTime' },
2329
+ createdAt: { $first: '$createdAt' },
2284
2330
 
2285
2331
  },
2286
2332
  },
@@ -2306,6 +2352,7 @@ export async function userMetrics( req, res ) {
2306
2352
  differenceInSeconds: {
2307
2353
  $divide: [ { $subtract: [ '$checkOutTime', '$checkIntime' ] }, 1000 ],
2308
2354
  },
2355
+ createdAt: 1,
2309
2356
  },
2310
2357
  },
2311
2358
  {
@@ -2321,6 +2368,7 @@ export async function userMetrics( req, res ) {
2321
2368
  hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
2322
2369
  minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
2323
2370
  seconds: { $mod: [ '$differenceInSeconds', 60 ] },
2371
+ createdAt: 1,
2324
2372
  },
2325
2373
  },
2326
2374
  {
@@ -2355,7 +2403,7 @@ export async function userMetrics( req, res ) {
2355
2403
  else: { $toString: { $round: [ '$seconds', 0 ] } },
2356
2404
  },
2357
2405
  },
2358
-
2406
+ createdAt: 1,
2359
2407
  },
2360
2408
  },
2361
2409
  {
@@ -2373,6 +2421,7 @@ export async function userMetrics( req, res ) {
2373
2421
  workingHours: {
2374
2422
  $concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
2375
2423
  },
2424
+ createdAt: 1,
2376
2425
  },
2377
2426
  },
2378
2427
  {
@@ -2426,6 +2475,7 @@ export async function userMetrics( req, res ) {
2426
2475
  },
2427
2476
  },
2428
2477
  workingHours: 1,
2478
+ createdAt: 1,
2429
2479
  },
2430
2480
  },
2431
2481
  ];
@@ -2463,15 +2513,17 @@ export async function userMetrics( req, res ) {
2463
2513
  {
2464
2514
  $project: {
2465
2515
  '_id': 0,
2466
- 'File Date': '$fileDate',
2467
2516
  'User Name': '$userName',
2468
- 'Total Completed Files Count': '$totalCompletedFiles',
2517
+ 'File Date': '$fileDate',
2518
+ 'Completed Files': '$totalCompletedFiles',
2519
+ 'Product Type': '$moduleType',
2469
2520
  'Total Before Count': '$beforeCount',
2470
2521
  'Total After Count': '$afterCount',
2471
- 'check Intime': '$checkIntime',
2472
- 'check OutTime': '$checkOutTime',
2473
- 'working Hours': '$workingHours',
2474
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' } },
2475
2527
  },
2476
2528
  },
2477
2529
  );
@@ -3815,11 +3867,11 @@ export async function auditImages( req, res ) {
3815
3867
  export async function getUserAuditCount( req, res ) {
3816
3868
  try {
3817
3869
  const userWallet = JSON.parse( process.env.USER_WALLET );
3818
- const previousDate = dayjs( new Date() ).subtract( 16, 'days' );
3870
+ const previousDate = dayjs( new Date() ).subtract( 19, 'days' );
3819
3871
  const fileDate = dayjs( previousDate ).format( 'DD-MM-YYYY' );
3820
3872
  const configTimeSpentSec = userWallet.minTimeSpentSec; // 18000;
3821
- const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
3822
- const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
3873
+ // const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
3874
+ // const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
3823
3875
  const reduce = userWallet.reductionPerc; // 0.05;
3824
3876
  const auditUserQuery=[
3825
3877
  {
@@ -3928,6 +3980,11 @@ export async function getUserAuditCount( req, res ) {
3928
3980
  }
3929
3981
  const zoneMinimumTarget =userCount[0]?.zoneUserCount?.length !== 0 && userCount[0]?.zoneFilesCount !==0 ? Math.floor( userCount[0].zoneFilesCount/userCount[0].zoneUserCount.length ) : 0;
3930
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
+
3931
3988
  const query = [
3932
3989
  {
3933
3990
  $match: {
@@ -3941,7 +3998,8 @@ export async function getUserAuditCount( req, res ) {
3941
3998
  },
3942
3999
  },
3943
4000
  {
3944
- $set: { minimumTarget: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, trafficMinimumTarget, zoneMinimumTarget ] } },
4001
+ $set: { minimumTarget: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, trafficMinimumTarget, zoneMinimumTarget ] },
4002
+ afterCountCredit: afterCountCredit },
3945
4003
  },
3946
4004
  {
3947
4005
  $project: {
@@ -3953,7 +4011,9 @@ export async function getUserAuditCount( req, res ) {
3953
4011
  fileDate: 1,
3954
4012
  fileDateISO: 1,
3955
4013
  minimumTarget: 1,
4014
+ afterCountCredit: 1,
3956
4015
  totalEarn: { $ifNull: [ 0, 0 ] },
4016
+ singleImageAmount: { $ifNull: [ 0, 0 ] },
3957
4017
  totalReducedAmount: { $ifNull: [ 0, 0 ] },
3958
4018
  totalCredit: { $ifNull: [ 0, 0 ] },
3959
4019
  deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
@@ -3972,11 +4032,13 @@ export async function getUserAuditCount( req, res ) {
3972
4032
  fileDateISO: { $first: '$fileDateISO' },
3973
4033
  userId: { $first: '$userId' },
3974
4034
  minimumTarget: { $first: '$minimumTarget' },
4035
+ afterCountCredit: { $first: '$afterCountCredit' },
3975
4036
  totalEarn: { $first: '$totalEarn' },
3976
4037
  totalReducedAmount: { $first: '$totalReducedAmount' },
3977
4038
  totalCredit: { $first: '$totalCredit' },
3978
4039
  deductionByMinimumTarget: { $first: '$deductionByMinimumTarget' },
3979
4040
  deductionBytimeSpent: { $first: '$deductionBytimeSpent' },
4041
+ singleImageAmount: { $first: '$singleImageAmount' },
3980
4042
  },
3981
4043
  },
3982
4044
  {
@@ -3990,12 +4052,35 @@ export async function getUserAuditCount( req, res ) {
3990
4052
  fileDate: 1,
3991
4053
  fileDateISO: 1,
3992
4054
  minimumTarget: 1,
3993
- totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', beforeCountX ] }, { $multiply: [ '$totalAfterCount', afterCountY ] } ] },
3994
- totalReducedAmount: 1,
3995
- totalCredit: 1,
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 ] },
3996
4069
  deductionBytimeSpent: 1,
3997
4070
  deductionByMinimumTarget: 1,
3998
-
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,
3999
4084
 
4000
4085
  },
4001
4086
  },
@@ -4018,6 +4103,9 @@ export async function getUserAuditCount( req, res ) {
4018
4103
  fileDate: 1,
4019
4104
  fileDateISO: 1,
4020
4105
  minimumTarget: 1,
4106
+ singleImageAmount: { $cond: [ { $eq: [ '$moduleType', 'traffic' ] }, beforeCountTraffic, beforeCountZone ] },
4107
+ beforeCountCredit: 1,
4108
+ afterCountCredit: 1,
4021
4109
  totalEarn: 1,
4022
4110
  deductionBytimeSpent: { $cond: [
4023
4111
  { $lt: [ '$totalTimeSpent', configTimeSpentSec ] },
@@ -4029,8 +4117,11 @@ export async function getUserAuditCount( req, res ) {
4029
4117
  { $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
4030
4118
  { $multiply: [ reduce, '$totalEarn' ] }, '$deductionByMinimumTarget',
4031
4119
  ] },
4120
+ mappingperc: 1,
4121
+ deductionByMapping: 1,
4032
4122
  totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
4033
4123
 
4124
+
4034
4125
  },
4035
4126
  },
4036
4127
 
@@ -4063,11 +4154,17 @@ export async function getUserAuditCount( req, res ) {
4063
4154
  fileDate: 1,
4064
4155
  fileDateISO: 1,
4065
4156
  minimumTarget: 1,
4066
- totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', beforeCountX ] }, { $multiply: [ '$totalAfterCount', afterCountY ] } ] },
4157
+ beforeCountCredit: 1,
4158
+ afterCountCredit: 1,
4159
+ totalEarn: 1,
4067
4160
  deductionByMinimumTarget: 1,
4161
+ singleImageAmount: 1,
4068
4162
  deductionBytimeSpent: 1,
4163
+ mappingperc: 1,
4164
+ deductionByMapping: 1,
4069
4165
  totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
4070
- totalReducedAmount: { $round: [ { $add: [ '$deductionBytimeSpent', '$deductionByMinimumTarget' ] }, 2 ] },
4166
+ totalReducedAmount: { $round: [ { $add: [ '$deductionBytimeSpent', '$deductionByMinimumTarget', '$deductionByMapping' ] }, 2 ] },
4167
+
4071
4168
  },
4072
4169
  },
4073
4170
  {
@@ -4102,14 +4199,20 @@ export async function getUserAuditCount( req, res ) {
4102
4199
  timeSpent: '$totalTimeSpent',
4103
4200
  fileDate: 1,
4104
4201
  fileDateISO: 1,
4202
+ beforeCountCredit: 1,
4203
+ afterCountCredit: 1,
4204
+ totalEarn: { $round: [ '$totalEarn', 2 ] },
4205
+ minimumTarget: 1,
4206
+ singleImageAmount: 1,
4105
4207
  deductionByMinimumTarget: { $round: [ '$deductionByMinimumTarget', 2 ] },
4106
4208
  deductionBytimeSpent: { $round: [ '$deductionBytimeSpent', 2 ] },
4209
+ mappingperc: 1,
4210
+ deductionByMapping: 1,
4107
4211
  totalReducedAmount: 1,
4108
4212
  totalCredit: { $round: [ { $subtract: [ '$totalEarn', '$totalReducedAmount' ] }, 2 ] },
4109
- totalEarn: { $round: [ '$totalEarn', 2 ] },
4110
- minimumTarget: 1,
4111
4213
  userEmail: '$users.email', // Access first element from array
4112
- userName: '$users.userName', // Access first element from array
4214
+ userName: '$users.userName', // Access first element from array,
4215
+
4113
4216
  },
4114
4217
  },
4115
4218
  ];
@@ -4456,8 +4559,8 @@ export async function auditViewLogs( req, res ) {
4456
4559
  },
4457
4560
  },
4458
4561
  {
4459
- 'term': {
4460
- 'logSubType.keyword': { $in: [ 'auditDone', 'reAuditPush', 'reTrigger' ] },
4562
+ 'terms': {
4563
+ 'logSubType.keyword': [ 'auditDone', 'reAuditPush', 'reTrigger' ],
4461
4564
  },
4462
4565
  },
4463
4566
  ],
@@ -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
- 'Client Name': '$clientName',
2092
- 'Client Id': '$clientId',
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
  },
@@ -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
- 'Total Completed Files Count': '$totalCompletedFiles',
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
- 'check Intime': '$checkIntime',
2889
- 'check OutTime': '$checkOutTime',
2890
- 'working Hours': '$workingHours',
2891
- 'Product Type': '$value',
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
- 'Total Completed Files Count': '$totalCompletedFiles',
2899
- 'check Intime': '$checkIntime',
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