tango-app-api-audit 3.4.3-alpha.10 → 3.4.3-alpha.12

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.10",
3
+ "version": "3.4.3-alpha.12",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -64,6 +64,7 @@ import { aggregateStoreEmpDetection } from '../service/storeEmpDetection.service
64
64
  import { aggregateBinaryAudit } from '../service/binaryAudit.service.js';
65
65
  import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
66
66
  import { createAuditUserWallet } from '../service/auditUserWallet.service.js';
67
+ import { aggregateAuditUsers } from '../service/auditUsers.service.js';
67
68
 
68
69
  /* < -- *** Configuration *** --> */
69
70
 
@@ -1102,9 +1103,9 @@ export async function workSpace( req, res ) {
1102
1103
  }
1103
1104
 
1104
1105
  if ( inputData.isExport ) {
1105
- const exportdata = [];
1106
+ const exportData = [];
1106
1107
  temp.forEach( ( element ) => {
1107
- exportdata.push( {
1108
+ exportData.push( {
1108
1109
  'Client Name': element.clientName,
1109
1110
  'Client Id': element.clientId,
1110
1111
  'Completed stores Count': element.completedStoresCount,
@@ -1115,7 +1116,7 @@ export async function workSpace( req, res ) {
1115
1116
  'Assigned': element.Assignedcount,
1116
1117
  } );
1117
1118
  } );
1118
- await download( exportdata, res );
1119
+ await download( exportData, res );
1119
1120
  return;
1120
1121
  } else {
1121
1122
  return res.sendSuccess( {
@@ -2164,10 +2165,10 @@ export async function storeMetrics( req, res ) {
2164
2165
  }
2165
2166
  const result = await aggregateStoreAudit( query );
2166
2167
  if ( inputData.isExport ) {
2167
- const exportdata = [];
2168
+ const exportData = [];
2168
2169
  result.forEach( ( element ) => {
2169
2170
  if ( element.moduleType == 'zone' ) {
2170
- exportdata.push( {
2171
+ exportData.push( {
2171
2172
  'File Date': element.fileDate,
2172
2173
  'Store ID': element.storeId,
2173
2174
  'Store Name': element.storeName,
@@ -2184,7 +2185,7 @@ export async function storeMetrics( req, res ) {
2184
2185
  'Status': element.status,
2185
2186
  } );
2186
2187
  } else {
2187
- exportdata.push( {
2188
+ exportData.push( {
2188
2189
  'File Date': element.fileDate,
2189
2190
  'Store ID': element.storeId,
2190
2191
  'Store Name': element.storeName,
@@ -2201,7 +2202,7 @@ export async function storeMetrics( req, res ) {
2201
2202
  } );
2202
2203
  }
2203
2204
  } );
2204
- await download( exportdata, res );
2205
+ await download( exportData, res );
2205
2206
  return;
2206
2207
  }
2207
2208
  return res.sendSuccess( { result: result, count: count.length } );
@@ -2620,10 +2621,10 @@ export async function pendingSummaryTable( req, res ) {
2620
2621
 
2621
2622
  const result = await aggregateUserAudit( query );
2622
2623
  if ( inputData.isExport ) {
2623
- const exportdata = [];
2624
+ const exportData = [];
2624
2625
  result.forEach( ( element ) => {
2625
2626
  if ( element.moduleType == 'zone' ) {
2626
- exportdata.push( {
2627
+ exportData.push( {
2627
2628
  'Store ID': element.storeId,
2628
2629
  'zoneName': element.zoneName,
2629
2630
  'File Date': element.fileDate,
@@ -2636,7 +2637,7 @@ export async function pendingSummaryTable( req, res ) {
2636
2637
  'Status': element.auditStatus,
2637
2638
  } );
2638
2639
  } else {
2639
- exportdata.push( {
2640
+ exportData.push( {
2640
2641
  'Store ID': element.storeId,
2641
2642
  'File Date': element.fileDate,
2642
2643
  'Product Type': element.moduleType,
@@ -2649,7 +2650,7 @@ export async function pendingSummaryTable( req, res ) {
2649
2650
  } );
2650
2651
  }
2651
2652
  } );
2652
- await download( exportdata, res );
2653
+ await download( exportData, res );
2653
2654
  return;
2654
2655
  }
2655
2656
  return res.sendSuccess( { result: result, count: count.length } );
@@ -2938,6 +2939,7 @@ export async function overViewCard( req, res ) {
2938
2939
  inprogressCount: 0,
2939
2940
  completedCount: 0,
2940
2941
  pendingCount: 0,
2942
+ notAssigned: 0,
2941
2943
  };
2942
2944
 
2943
2945
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
@@ -2968,7 +2970,7 @@ export async function overViewCard( req, res ) {
2968
2970
  },
2969
2971
  inprogressCount: {
2970
2972
  $cond: [
2971
- { $ne: [ '$status', 'completed' ] }, 1, 0,
2973
+ { $in: [ '$status', [ 'inprogress', 'assigned', 'drafted' ] ] }, 1, 0,
2972
2974
  ],
2973
2975
  },
2974
2976
  completedCount: {
@@ -3195,7 +3197,10 @@ export async function summarySplit( req, res ) {
3195
3197
  ];
3196
3198
  const result = await aggregateStoreAudit( query );
3197
3199
  const totalCount = await aggregateAuditStoreData( totalQuery );
3198
- result[0].totalCount = totalCount[0]?.total;
3200
+ if ( totalCount.length> 0 ) {
3201
+ result[0].totalCount = totalCount[0]?.total;
3202
+ }
3203
+
3199
3204
  return res.sendSuccess( { result: result.length > 0 ? result[0] : temp } );
3200
3205
  } catch ( error ) {
3201
3206
  const err = error.message || 'Internal Server Error';
@@ -3336,38 +3341,32 @@ export async function overviewTable( req, res ) {
3336
3341
 
3337
3342
  const result = await aggregateStoreAudit( query );
3338
3343
  if ( inputData.isExport ) {
3339
- const exportdata = [];
3344
+ const exportData = [];
3340
3345
  result.forEach( ( element ) => {
3341
3346
  if ( element.moduleType == 'zone' ) {
3342
- exportdata.push( {
3343
- 'Store ID': element.storeId,
3347
+ exportData.push( {
3348
+ 'File Date': element.fileDate,
3344
3349
  'Brand ID': element.clientId,
3350
+ 'Store ID': element.storeId,
3345
3351
  'Zone Name': element.zoneName,
3346
- 'File Date': element.fileDate,
3347
- 'Product Type': element.moduleType,
3348
- 'Audit Type': element.auditType,
3349
3352
  'Before Count': element.beforeCount,
3350
3353
  'After Count': element.afterCount,
3351
- // 'User Name': element.userName,
3352
- // 'User Email': element.userEmail,
3353
- 'Status': element.status,
3354
+ 'Audit Type': element.auditType,
3355
+ 'Status': toCamelCase( element.status ),
3354
3356
  } );
3355
3357
  } else {
3356
- exportdata.push( {
3357
- 'Store ID': element.storeId,
3358
- 'Brand ID': element.clientId,
3358
+ exportData.push( {
3359
3359
  'File Date': element.fileDate,
3360
- 'Product Type': element.moduleType,
3361
- 'Audit Type': element.auditType,
3360
+ 'Brand ID': element.clientId,
3361
+ 'Store ID': element.storeId,
3362
3362
  'Before Count': element.beforeCount,
3363
3363
  'After Count': element.afterCount,
3364
- // 'User Name': element.userName,
3365
- // 'User Email': element.userEmail,
3366
- 'Status': element.status,
3364
+ 'Audit Type': element.auditType,
3365
+ 'Status': toCamelCase( element.status ),
3367
3366
  } );
3368
3367
  }
3369
3368
  } );
3370
- await download( exportdata, res );
3369
+ await download( exportData, res );
3371
3370
  return;
3372
3371
  }
3373
3372
  return res.sendSuccess( { result: result, count: count.length } );
@@ -3378,6 +3377,18 @@ export async function overviewTable( req, res ) {
3378
3377
  }
3379
3378
  }
3380
3379
 
3380
+ export function toCamelCase( str ) {
3381
+ logger.info( { str: str } );
3382
+ return str
3383
+ .split( '-' ) // Split the string by spaces
3384
+ .map( ( word, index ) =>
3385
+ // index === 0 ?
3386
+ // word.toLowerCase() : // Lowercase the first word
3387
+ word.charAt( 0 ).toUpperCase() + word.slice( 1 ).toLowerCase(), // Capitalize the first letter of subsequent words
3388
+ )
3389
+ .join( '' ); // Join the words without spaces
3390
+ }
3391
+
3381
3392
  export async function totalNotAssignedCount( req, res ) {
3382
3393
  try {
3383
3394
  let notAssignedCount = {
@@ -3805,12 +3816,39 @@ export async function getUserAuditCount( req, res ) {
3805
3816
  const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
3806
3817
  const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
3807
3818
  const reduce = userWallet.reductionPerc; // 0.05;
3819
+ const auditUserQuery=[
3820
+ {
3821
+ $match: {
3822
+ $and: [
3823
+ { type: { $eq: 'consultant' } },
3824
+ { isActive: { $eq: true } },
3825
+ ],
3826
+ },
3827
+ },
3828
+ {
3829
+ $group: {
3830
+ _id: null,
3831
+ userList: { $push: '$userId' },
3832
+ },
3833
+ },
3834
+ {
3835
+ $project: {
3836
+ _id: 0,
3837
+ userList: 1,
3838
+ },
3839
+ },
3840
+ ];
3841
+ const auditUserList = await aggregateAuditUsers( auditUserQuery );
3842
+ if ( auditUserList.length==0 ) {
3843
+ return res.sendError( 'No users available', 204 );
3844
+ }
3808
3845
  const userCountQuery= [
3809
3846
  {
3810
3847
  $match: {
3811
3848
  $and: [
3812
3849
  { fileDate: { $eq: fileDate } },
3813
3850
  { auditStatus: { $eq: 'completed' } },
3851
+ { userId: { $in: auditUserList[0].userList } },
3814
3852
  ],
3815
3853
  },
3816
3854
  },
@@ -3893,6 +3931,7 @@ export async function getUserAuditCount( req, res ) {
3893
3931
  {
3894
3932
  auditStatus: { $eq: 'completed' },
3895
3933
  },
3934
+ { userId: { $in: auditUserList[0].userList } },
3896
3935
  ],
3897
3936
  },
3898
3937
  },
@@ -3912,6 +3951,8 @@ export async function getUserAuditCount( req, res ) {
3912
3951
  totalEarn: { $ifNull: [ 0, 0 ] },
3913
3952
  totalReducedAmount: { $ifNull: [ 0, 0 ] },
3914
3953
  totalCredit: { $ifNull: [ 0, 0 ] },
3954
+ deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
3955
+ deductionByMinimumTarget: { $ifNull: [ 0, 0 ] },
3915
3956
  },
3916
3957
  },
3917
3958
  {
@@ -3929,6 +3970,8 @@ export async function getUserAuditCount( req, res ) {
3929
3970
  totalEarn: { $first: '$totalEarn' },
3930
3971
  totalReducedAmount: { $first: '$totalReducedAmount' },
3931
3972
  totalCredit: { $first: '$totalCredit' },
3973
+ deductionByMinimumTarget: { $first: '$deductionByMinimumTarget' },
3974
+ deductionBytimeSpent: { $first: '$deductionBytimeSpent' },
3932
3975
  },
3933
3976
  },
3934
3977
  {
@@ -3945,6 +3988,9 @@ export async function getUserAuditCount( req, res ) {
3945
3988
  totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', beforeCountX ] }, { $multiply: [ '$totalAfterCount', afterCountY ] } ] },
3946
3989
  totalReducedAmount: 1,
3947
3990
  totalCredit: 1,
3991
+ deductionBytimeSpent: 1,
3992
+ deductionByMinimumTarget: 1,
3993
+
3948
3994
 
3949
3995
  },
3950
3996
  },
@@ -3956,13 +4002,27 @@ export async function getUserAuditCount( req, res ) {
3956
4002
  totalBeforeCount: 1,
3957
4003
  totalAfterCount: 1,
3958
4004
  totalTimeSpent: 1,
4005
+ hours: { $floor: { $divide: [ '$totalTimeSpent', 3600 ] } },
4006
+ minutes: {
4007
+ $floor: {
4008
+ $divide: [
4009
+ { $mod: [ '$totalTimeSpent', 3600 ] }, // Get remaining minutes after hours
4010
+ 60,
4011
+ ] },
4012
+ },
3959
4013
  fileDate: 1,
3960
4014
  fileDateISO: 1,
3961
4015
  minimumTarget: 1,
3962
4016
  totalEarn: 1,
3963
- totalReducedAmount: { $cond: [
4017
+ deductionBytimeSpent: { $cond: [
3964
4018
  { $lt: [ '$totalTimeSpent', configTimeSpentSec ] },
3965
- { $add: [ '$totalReducedAmount', { $multiply: [ reduce, '$totalEarn' ] } ] }, '$totalReducedAmount',
4019
+ { $multiply: [ reduce, '$totalEarn' ] }, '$deductionBytimeSpent',
4020
+ ] },
4021
+
4022
+ deductionByMinimumTarget:
4023
+ { $cond: [
4024
+ { $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
4025
+ { $multiply: [ reduce, '$totalEarn' ] }, '$deductionByMinimumTarget',
3966
4026
  ] },
3967
4027
  totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
3968
4028
 
@@ -3976,18 +4036,33 @@ export async function getUserAuditCount( req, res ) {
3976
4036
  moduleType: 1,
3977
4037
  totalBeforeCount: 1,
3978
4038
  totalAfterCount: 1,
3979
- totalTimeSpent: 1,
4039
+ totalTimeSpent: {
4040
+ $cond: [ { $eq: [ '$hours', 0 ] },
4041
+ { $concat: [
4042
+ { $toString: '$minutes' }, ' minutes',
4043
+ ] },
4044
+ { $cond: [ { $eq: [ '$minutes', 0 ] },
4045
+ { $concat: [
4046
+ { $toString: '$hours' }, ' hours',
4047
+ ] },
4048
+ {
4049
+ $concat: [
4050
+ { $toString: '$hours' }, ' hours and ',
4051
+ { $toString: '$minutes' }, ' minutes',
4052
+ ],
4053
+ },
4054
+ ] },
4055
+ ],
4056
+
4057
+ },
3980
4058
  fileDate: 1,
3981
4059
  fileDateISO: 1,
3982
4060
  minimumTarget: 1,
3983
4061
  totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', beforeCountX ] }, { $multiply: [ '$totalAfterCount', afterCountY ] } ] },
3984
- totalReducedAmount:
3985
- { $cond: [
3986
- { $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
3987
- { $add: [ '$totalReducedAmount', { $multiply: [ reduce, '$totalEarn' ] } ] }, '$totalReducedAmount',
3988
- ] },
3989
-
4062
+ deductionByMinimumTarget: 1,
4063
+ deductionBytimeSpent: 1,
3990
4064
  totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
4065
+ totalReducedAmount: { $round: [ { $add: [ '$deductionBytimeSpent', '$deductionByMinimumTarget' ] }, 2 ] },
3991
4066
  },
3992
4067
  },
3993
4068
  {
@@ -4019,10 +4094,12 @@ export async function getUserAuditCount( req, res ) {
4019
4094
  moduleType: 1,
4020
4095
  totalAfterCount: { $round: [ '$totalAfterCount', 2 ] },
4021
4096
  totalBeforeCount: { $round: [ '$totalBeforeCount', 2 ] },
4022
- timeSpent: { $round: [ '$totalTimeSpent', 2 ] },
4097
+ timeSpent: '$totalTimeSpent',
4023
4098
  fileDate: 1,
4024
4099
  fileDateISO: 1,
4025
- totalReducedAmount: { $round: [ '$totalReducedAmount', 2 ] },
4100
+ deductionByMinimumTarget: { $round: [ '$deductionByMinimumTarget', 2 ] },
4101
+ deductionBytimeSpent: { $round: [ '$deductionBytimeSpent', 2 ] },
4102
+ totalReducedAmount: 1,
4026
4103
  totalCredit: { $round: [ { $subtract: [ '$totalEarn', '$totalReducedAmount' ] }, 2 ] },
4027
4104
  totalEarn: { $round: [ '$totalEarn', 2 ] },
4028
4105
  minimumTarget: 1,
@@ -3312,6 +3312,63 @@ export async function summarySplit( req, res ) {
3312
3312
  { clientId: { $in: inputData.clientId } },
3313
3313
  ];
3314
3314
 
3315
+
3316
+ const binaryAuditQuery =[
3317
+ {
3318
+ $match: {
3319
+ $and: filters,
3320
+ },
3321
+
3322
+ },
3323
+ {
3324
+ $project: {
3325
+ auditInprogress: {
3326
+ $cond: [
3327
+ { $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$auditStatus', 'inprogress' ] } ] }, 1, 0,
3328
+ ],
3329
+ },
3330
+ reAuditInprogress: {
3331
+ $cond: [
3332
+ { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$auditStatus', 'inprogress' ] } ] }, 1, 0,
3333
+ ],
3334
+ },
3335
+
3336
+ reAuditCompleted: {
3337
+ $cond: [
3338
+ { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$auditStatus', 'completed' ] } ] }, 1, 0,
3339
+ ],
3340
+ },
3341
+ auditCompleted: {
3342
+ $cond: [
3343
+ { $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$auditStatus', 'completed' ] } ] }, 1, 0,
3344
+ ],
3345
+ },
3346
+ },
3347
+ },
3348
+ {
3349
+ $group: {
3350
+ _id: null,
3351
+ auditInprogress: { $sum: '$auditInprogress' },
3352
+ reAuditInprogress: { $sum: '$reAuditInprogress' },
3353
+ reAuditCompleted: { $sum: '$reAuditCompleted' },
3354
+ auditCompleted: { $sum: '$auditCompleted' },
3355
+
3356
+ },
3357
+ },
3358
+ {
3359
+ $project: {
3360
+ _id: 0,
3361
+ totalInprogress: 1,
3362
+ auditInprogress: 1,
3363
+ reAuditInprogress: 1,
3364
+ reAuditCompleted: 1,
3365
+ auditCompleted: 1,
3366
+ totalCount: { $ifNull: [ 0, 0 ] },
3367
+
3368
+ },
3369
+ },
3370
+ ];
3371
+
3315
3372
  const query =[
3316
3373
  {
3317
3374
  $match: {
@@ -3401,7 +3458,7 @@ export async function summarySplit( req, res ) {
3401
3458
  },
3402
3459
  },
3403
3460
  ];
3404
- const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3461
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
3405
3462
  const totalCount = await aggregateTraxAuditData( totalQuery );
3406
3463
  result[0].totalCount = totalCount[0]?.total;
3407
3464
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
@@ -3568,39 +3625,42 @@ export async function overviewTable( req, res ) {
3568
3625
  const exportdata = [];
3569
3626
  result.forEach( ( element ) => {
3570
3627
  const temp ={
3571
- 'Store ID': element.storeId,
3572
- 'Brand ID': element.clientId,
3573
3628
  '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,
3629
+ 'Brand ID': element.clientId,
3630
+ 'Store ID': element.storeId,
3581
3631
  };
3582
3632
 
3583
3633
  switch ( inputData.moduleType ) {
3584
3634
  case 'camera-angle-change':
3585
3635
  temp['stream Name'] = element.streamName;
3586
3636
  temp['User Comments'] = element.userComments;
3637
+ temp['Audit Type'] = element.auditType;
3638
+ temp['Status'] = element.auditStatus;
3587
3639
  break;
3588
3640
  case 'unattended-customer':
3589
3641
  temp['Customer ID'] = element.tempId;
3590
3642
  temp['Question'] = element.question;
3591
3643
  temp['User Comments'] = element.userComments;
3644
+ temp['Audit Type'] = element.auditType;
3645
+ temp['Status'] = element.auditStatus;
3592
3646
  break;
3593
3647
  case 'left-in-middle':
3594
3648
  temp['Question'] = element.question;
3595
3649
  temp['User Comments'] = element.userComments;
3650
+ temp['Audit Type'] = element.auditType;
3651
+ temp['Status'] = element.auditStatus;
3596
3652
  break;
3597
3653
  case 'mobile-detection':
3598
3654
  temp['Before Count'] = element.beforeCount;
3599
3655
  temp['After Count'] = element.afterCount;
3656
+ temp['Audit Type'] = element.auditType;
3657
+ temp['Status'] = element.status;
3600
3658
  break;
3601
3659
  case 'uniform-detection':
3602
3660
  temp['Before Count'] = element.beforeCount;
3603
3661
  temp['After Count'] = element.afterCount;
3662
+ temp['Audit Type'] = element.auditType;
3663
+ temp['Status'] = element.status;
3604
3664
  break;
3605
3665
  }
3606
3666
  exportdata.push( temp );
@@ -266,7 +266,7 @@ export const reTriggerValid = {
266
266
  export const overViewCardSchema = joi.object( {
267
267
  fromDate: joi.string().required(),
268
268
  toDate: joi.string().required(),
269
- clientId: joi.array().items( joi.string().required() ).required(),
269
+ clientId: joi.array().items( joi.string().required().allow( '' ) ).required(),
270
270
  } );
271
271
 
272
272
  export const overViewCardValid = {
@@ -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
+ };