tango-app-api-audit 3.4.3-alpha.9 → 3.4.4

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.
@@ -2,7 +2,7 @@ import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime
2
2
  import { aggregateBinaryAudit, createBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
3
3
  import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
5
- import { aggregateUserEmpDetection, createUserEmpDetection, updateOneUserEmpDetection } from '../service/userEmpDetection.service.js';
5
+ import { aggregateUserEmpDetection, countDocumentsUserEmpDetection, createUserEmpDetection, updateOneUserEmpDetection } from '../service/userEmpDetection.service.js';
6
6
  import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
7
7
  import { aggregateClient, findOneClient } from '../service/client.service.js';
8
8
  import dayjs from 'dayjs';
@@ -346,6 +346,7 @@ import { updateOneEmpDetectionOutput } from '../service/empDetectionOutput.servi
346
346
  // img_id: img[3],
347
347
  // selected: false,
348
348
  // dropped: false,
349
+ // singleDetection: false,
349
350
  // count: 1,
350
351
  // mappedid: [ mapimg ],
351
352
  // } );
@@ -1402,6 +1403,7 @@ export async function getUpdatedFile( req, res ) {
1402
1403
 
1403
1404
  export async function saveBinary( req, res ) {
1404
1405
  try {
1406
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
1405
1407
  const inputData = req.body;
1406
1408
  const isoDate = req.userAudit?.startTime;
1407
1409
  const currentTime = dayjs();
@@ -1475,6 +1477,31 @@ export async function saveBinary( req, res ) {
1475
1477
  };
1476
1478
  let updatDatacamera= await updateOneBinaryAuditModel( cameraquery, cameraupdate );
1477
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 );
1478
1505
  return res.sendError( 'Update failed, it may be invalid request', 400 );
1479
1506
  }
1480
1507
  logger.info( 'update in binary data', { query: cameraquery, update: cameraupdate } );
@@ -1713,33 +1740,35 @@ export async function userAuditHistory( req, res ) {
1713
1740
  const temp ={
1714
1741
 
1715
1742
  'File Date': element.fileDate,
1716
- 'Brand ID': element.clientId,
1717
1743
  'Brand Name': element.clientName,
1718
- 'Store ID': element.storeId,
1744
+ 'Brand ID': element.clientId,
1719
1745
  'Store Name': element.storeName,
1746
+ 'Store ID': element.storeId,
1720
1747
  'Audit Type': element.auditType,
1721
1748
  'Product Type': element.value,
1749
+ 'Audited Date': dayjs( element.createdAt ).format( 'YYYY,MMM D' ),
1722
1750
  'Start Time': element.startTime,
1723
1751
  'End Time': element.endTime || '',
1724
1752
  'Time Spent': element.timeSpent,
1725
- 'Status': element.auditStatus,
1726
- 'Audited Date': dayjs( element.createdAt ).format( 'YYYY,MMM D' ),
1727
- 'Result': element.answer,
1753
+ 'Status': toCamelCase( element.auditStatus ),
1728
1754
 
1729
1755
 
1730
1756
  };
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
  },
@@ -2201,10 +2230,10 @@ export async function storeMetrics( req, res ) {
2201
2230
  question: 1,
2202
2231
  questionType: 1,
2203
2232
  answer: 1,
2204
- // userId: {
2205
- // $arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], //need to check if no data
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':
@@ -2594,18 +2622,18 @@ export async function storeMetrics( req, res ) {
2594
2622
  case 'left-in-middle':
2595
2623
  temp['Question'] = element.question;
2596
2624
  temp['User Comments'] = element.userComments;
2597
- temp['Status'] = element.auditStatus;
2625
+ temp['Status'] = toCamelCase( element.auditStatus );
2598
2626
  break;
2599
2627
  case 'mobile-detection':
2600
2628
  temp['Before Count'] = element.beforeCount;
2601
2629
  temp['After Count'] = element.afterCount;
2602
- temp['Status'] = element.status;
2630
+ temp['Status'] = toCamelCase( element.status );
2603
2631
  temp['Accuracy'] = element.accuracy;
2604
2632
  break;
2605
2633
  case 'uniform-detection':
2606
2634
  temp['Before Count'] = element.beforeCount;
2607
2635
  temp['After Count'] = element.afterCount;
2608
- temp['Status'] = element.status;
2636
+ temp['Status'] = toCamelCase( element.status );
2609
2637
  temp['Accuracy'] = element.accuracy;
2610
2638
  break;
2611
2639
  }
@@ -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 )?
@@ -3088,7 +3124,7 @@ export async function pendingSummaryTable( req, res ) {
3088
3124
  'Start Time': element.startTime,
3089
3125
  'User Name': element.userName,
3090
3126
  'User Email': element.userEmail,
3091
- 'Status': element.auditStatus,
3127
+ 'Status': toCamelCase( element.auditStatus ),
3092
3128
  };
3093
3129
  switch ( inputData.moduleType ) {
3094
3130
  case 'camera-angle-change':
@@ -3312,6 +3348,63 @@ export async function summarySplit( req, res ) {
3312
3348
  { clientId: { $in: inputData.clientId } },
3313
3349
  ];
3314
3350
 
3351
+
3352
+ const binaryAuditQuery =[
3353
+ {
3354
+ $match: {
3355
+ $and: filters,
3356
+ },
3357
+
3358
+ },
3359
+ {
3360
+ $project: {
3361
+ auditInprogress: {
3362
+ $cond: [
3363
+ { $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$auditStatus', 'inprogress' ] } ] }, 1, 0,
3364
+ ],
3365
+ },
3366
+ reAuditInprogress: {
3367
+ $cond: [
3368
+ { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$auditStatus', 'inprogress' ] } ] }, 1, 0,
3369
+ ],
3370
+ },
3371
+
3372
+ reAuditCompleted: {
3373
+ $cond: [
3374
+ { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$auditStatus', 'completed' ] } ] }, 1, 0,
3375
+ ],
3376
+ },
3377
+ auditCompleted: {
3378
+ $cond: [
3379
+ { $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$auditStatus', 'completed' ] } ] }, 1, 0,
3380
+ ],
3381
+ },
3382
+ },
3383
+ },
3384
+ {
3385
+ $group: {
3386
+ _id: null,
3387
+ auditInprogress: { $sum: '$auditInprogress' },
3388
+ reAuditInprogress: { $sum: '$reAuditInprogress' },
3389
+ reAuditCompleted: { $sum: '$reAuditCompleted' },
3390
+ auditCompleted: { $sum: '$auditCompleted' },
3391
+
3392
+ },
3393
+ },
3394
+ {
3395
+ $project: {
3396
+ _id: 0,
3397
+ totalInprogress: 1,
3398
+ auditInprogress: 1,
3399
+ reAuditInprogress: 1,
3400
+ reAuditCompleted: 1,
3401
+ auditCompleted: 1,
3402
+ totalCount: { $ifNull: [ 0, 0 ] },
3403
+
3404
+ },
3405
+ },
3406
+ ];
3407
+
3315
3408
  const query =[
3316
3409
  {
3317
3410
  $match: {
@@ -3401,7 +3494,7 @@ export async function summarySplit( req, res ) {
3401
3494
  },
3402
3495
  },
3403
3496
  ];
3404
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3497
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
3405
3498
  const totalCount = await aggregateTraxAuditData( totalQuery );
3406
3499
  result[0].totalCount = totalCount[0]?.total;
3407
3500
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
@@ -3431,7 +3524,7 @@ export async function overviewTable( req, res ) {
3431
3524
  }
3432
3525
 
3433
3526
  if ( inputData.filterByStatus.length > 0 ) {
3434
- filters.push( { status: { $in: inputData.filterByStatus } } );
3527
+ [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
3435
3528
  }
3436
3529
 
3437
3530
  const query =[
@@ -3568,39 +3661,42 @@ export async function overviewTable( req, res ) {
3568
3661
  const exportdata = [];
3569
3662
  result.forEach( ( element ) => {
3570
3663
  const temp ={
3571
- 'Store ID': element.storeId,
3572
- 'Brand ID': element.clientId,
3573
3664
  'File Date': element.fileDate,
3574
- 'Result': element.answer,
3575
- 'Product Type': element.value,
3576
- 'Audit Type': element.auditType,
3577
- // 'User Name': element.userName,
3578
- // 'User Email': element.userEmail,
3579
- 'Status': element.status,
3580
- 'Audit Status': element.status,
3665
+ 'Brand ID': element.clientId,
3666
+ 'Store ID': element.storeId,
3581
3667
  };
3582
3668
 
3583
3669
  switch ( inputData.moduleType ) {
3584
3670
  case 'camera-angle-change':
3585
3671
  temp['stream Name'] = element.streamName;
3586
3672
  temp['User Comments'] = element.userComments;
3673
+ temp['Audit Type'] = element.auditType;
3674
+ temp['Status'] = toCamelCase( element.auditStatus );
3587
3675
  break;
3588
3676
  case 'unattended-customer':
3589
3677
  temp['Customer ID'] = element.tempId;
3590
3678
  temp['Question'] = element.question;
3591
3679
  temp['User Comments'] = element.userComments;
3680
+ temp['Audit Type'] = element.auditType;
3681
+ temp['Status'] = toCamelCase( element.auditStatus );
3592
3682
  break;
3593
3683
  case 'left-in-middle':
3594
3684
  temp['Question'] = element.question;
3595
3685
  temp['User Comments'] = element.userComments;
3686
+ temp['Audit Type'] = element.auditType;
3687
+ temp['Status'] = toCamelCase( element.auditStatus );
3596
3688
  break;
3597
3689
  case 'mobile-detection':
3598
3690
  temp['Before Count'] = element.beforeCount;
3599
3691
  temp['After Count'] = element.afterCount;
3692
+ temp['Audit Type'] = element.auditType;
3693
+ temp['Status'] = toCamelCase( element.status );
3600
3694
  break;
3601
3695
  case 'uniform-detection':
3602
3696
  temp['Before Count'] = element.beforeCount;
3603
3697
  temp['After Count'] = element.afterCount;
3698
+ temp['Audit Type'] = element.auditType;
3699
+ temp['Status'] = toCamelCase( element.status );
3604
3700
  break;
3605
3701
  }
3606
3702
  exportdata.push( temp );
@@ -3945,6 +4041,7 @@ export async function getDetectionAuditFile( req, res ) {
3945
4041
  img_id: img[3],
3946
4042
  selected: false,
3947
4043
  dropped: false,
4044
+ singleDetection: false,
3948
4045
  count: 1,
3949
4046
  mappedid: [ mapimg ],
3950
4047
  } );
@@ -4150,6 +4247,7 @@ export async function getDraftedData( req, res ) {
4150
4247
  storeId: inputData.storeId,
4151
4248
  userId: userId,
4152
4249
  moduleType: inputData.moduleType,
4250
+ auditId: inputData.auditId,
4153
4251
  };
4154
4252
  const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
4155
4253
 
@@ -4170,14 +4268,53 @@ export async function getDraftedData( req, res ) {
4170
4268
 
4171
4269
  export async function save( req, res ) {
4172
4270
  try {
4271
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
4173
4272
  const inputData = req.body;
4273
+ const isoDate = req.userAudit?.startTime;
4274
+ const currentTime = dayjs();
4275
+ const isoDateTime = dayjs( isoDate );
4276
+ const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
4174
4277
  const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
4175
4278
  inputData.clientId = getUserAuditData.clientId;
4176
4279
  const query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
4177
4280
  const data = await updateOneEmpDetectionOutput( query, { $set: inputData }, { upsert: true } );
4178
4281
  if ( data ) {
4179
- await updateOneUserEmpDetection( { _id: inputData.auditId }, { auditStatus: 'completed', afterCount: inputData.employeeCount } );
4180
- await updateOneStoreEmpDetection( query, { status: 'completed', afterCount: inputData.employeeCount } );
4282
+ const userUpdated ={
4283
+ auditStatus: 'completed',
4284
+ afterCount: inputData.employeeCount,
4285
+ endTime: Date.now(),
4286
+ isDraft: false,
4287
+ timeSpent: timeDifferenceInMinutes,
4288
+ };
4289
+ const storeUpdated ={
4290
+ status: 'completed',
4291
+ afterCount: inputData.employeeCount,
4292
+ timeSpent: timeDifferenceInMinutes,
4293
+ };
4294
+ await updateOneUserEmpDetection( { _id: inputData.auditId }, userUpdated );
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 );
4181
4318
  return res.sendSuccess( { result: 'Updated Successfully' } );
4182
4319
  } else {
4183
4320
  return res.sendError( 'something went wrong', 403 );
@@ -4204,6 +4341,9 @@ export async function reTrigger( req, res ) {
4204
4341
  if ( !getQueueName || queueName == '' ) {
4205
4342
  return res.sendError( 'queueName does not create', 400 );
4206
4343
  }
4344
+ const getRecord = await countDocumentsUserEmpDetection( { storeId: message.storeId,
4345
+ fileDate: message.fileDate,
4346
+ moduleType: message.moduleType, auditStatus: 'completed' } );
4207
4347
  const msg = {
4208
4348
  storeId: message.storeId,
4209
4349
  fileDate: message.fileDate,
@@ -4213,6 +4353,7 @@ export async function reTrigger( req, res ) {
4213
4353
  question: message.question,
4214
4354
  folderPath: message.folderPath,
4215
4355
  fileCount: message.fileCount,
4356
+ auditType: getRecord > 0? 'ReAudit':'Audit',
4216
4357
  };
4217
4358
  const sqsProduceQueue = {
4218
4359
  QueueUrl: `${sqs.url}${queueName}`,
@@ -4278,3 +4419,15 @@ export async function reTrigger( req, res ) {
4278
4419
  return res.sendError( err, 500 );
4279
4420
  }
4280
4421
  }
4422
+
4423
+ export function toCamelCase( str ) {
4424
+ logger.info( { str: str } );
4425
+ return str
4426
+ .split( '-' ) // Split the string by spaces
4427
+ .map( ( word, index ) =>
4428
+ // index === 0 ?
4429
+ // word.toLowerCase() : // Lowercase the first word
4430
+ word.charAt( 0 ).toUpperCase() + word.slice( 1 ).toLowerCase(), // Capitalize the first letter of subsequent words
4431
+ )
4432
+ .join( '' ); // Join the words without spaces
4433
+ }
@@ -184,6 +184,12 @@ export const auditDocs = {
184
184
  scema: j2s( getDraftedDataSchema ).swagger,
185
185
  require: true,
186
186
  },
187
+ {
188
+ in: 'query',
189
+ name: 'auditId',
190
+ scema: j2s( getDraftedDataSchema ).swagger,
191
+ require: true,
192
+ },
187
193
  {
188
194
  in: 'query',
189
195
  name: 'userId',
@@ -387,6 +387,12 @@ export const traxAuditDocs = {
387
387
  scema: j2s( getDraftedDataSchema ).swagger,
388
388
  require: true,
389
389
  },
390
+ {
391
+ in: 'query',
392
+ name: 'auditId',
393
+ scema: j2s( getDraftedDataSchema ).swagger,
394
+ require: true,
395
+ },
390
396
  {
391
397
  in: 'query',
392
398
  name: 'userId',
@@ -76,6 +76,7 @@ export const getDraftedDataSchema = joi.object( {
76
76
  userId: joi.string().optional(),
77
77
  moduleType: joi.string().required(),
78
78
  zoneName: joi.string().required(),
79
+ auditId: joi.string().required(),
79
80
  } );
80
81
 
81
82
  export const getDraftedDataValid = {
@@ -266,7 +267,7 @@ export const reTriggerValid = {
266
267
  export const overViewCardSchema = joi.object( {
267
268
  fromDate: joi.string().required(),
268
269
  toDate: joi.string().required(),
269
- clientId: joi.array().items( joi.string().required() ).required(),
270
+ clientId: joi.array().items( joi.string().required().allow( '' ) ).required(),
270
271
  } );
271
272
 
272
273
  export const overViewCardValid = {
@@ -68,6 +68,7 @@ export const getDraftedDataSchema = joi.object(
68
68
  fileDate: joi.string().required(),
69
69
  userId: joi.string().optional(),
70
70
  moduleType: joi.string().required(),
71
+ auditId: joi.string().required(),
71
72
  },
72
73
  );
73
74
 
@@ -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
 
@@ -0,0 +1,5 @@
1
+ import auditUsersModel from 'tango-api-schema/schema/auditUsers.model.js';
2
+
3
+ export function aggregateAuditUsers( query ) {
4
+ return auditUsersModel.aggregate( query );
5
+ };
@@ -1,9 +1,7 @@
1
1
  import userEmpDetectionModel from 'tango-api-schema/schema/userEmpDetection.model.js';
2
- import { logger } from 'tango-app-api-middleware';
3
2
 
4
3
 
5
4
  export function aggregateUserEmpDetection( query ) {
6
- logger.info( { seelevt: 'yryruteretwyyyyyyyyyyyyyyyyyyyyyyyyyyyyewe' } );
7
5
  return userEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
8
6
  }
9
7
 
@@ -15,6 +13,10 @@ export function findOneUserEmpDetection( query, fields ) {
15
13
  return userEmpDetectionModel.findOne( query, fields );
16
14
  }
17
15
 
16
+ export function countDocumentsUserEmpDetection( query, fields ) {
17
+ return userEmpDetectionModel.countDocuments( query, fields );
18
+ }
19
+
18
20
  export function updateOneUserEmpDetection( query, record ) {
19
21
  return userEmpDetectionModel.updateOne( query, { $set: record } );
20
22
  }