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

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.11",
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
 
@@ -3805,12 +3806,39 @@ export async function getUserAuditCount( req, res ) {
3805
3806
  const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
3806
3807
  const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
3807
3808
  const reduce = userWallet.reductionPerc; // 0.05;
3809
+ const auditUserQuery=[
3810
+ {
3811
+ $match: {
3812
+ $and: [
3813
+ { type: { $eq: 'consultant' } },
3814
+ { isActive: { $eq: true } },
3815
+ ],
3816
+ },
3817
+ },
3818
+ {
3819
+ $group: {
3820
+ _id: null,
3821
+ userList: { $push: '$userId' },
3822
+ },
3823
+ },
3824
+ {
3825
+ $project: {
3826
+ _id: 0,
3827
+ userList: 1,
3828
+ },
3829
+ },
3830
+ ];
3831
+ const auditUserList = await aggregateAuditUsers( auditUserQuery );
3832
+ if ( auditUserList.length==0 ) {
3833
+ return res.sendError( 'No users available', 204 );
3834
+ }
3808
3835
  const userCountQuery= [
3809
3836
  {
3810
3837
  $match: {
3811
3838
  $and: [
3812
3839
  { fileDate: { $eq: fileDate } },
3813
3840
  { auditStatus: { $eq: 'completed' } },
3841
+ { userId: { $in: auditUserList[0].userList } },
3814
3842
  ],
3815
3843
  },
3816
3844
  },
@@ -3893,6 +3921,7 @@ export async function getUserAuditCount( req, res ) {
3893
3921
  {
3894
3922
  auditStatus: { $eq: 'completed' },
3895
3923
  },
3924
+ { userId: { $in: auditUserList[0].userList } },
3896
3925
  ],
3897
3926
  },
3898
3927
  },
@@ -3912,6 +3941,8 @@ export async function getUserAuditCount( req, res ) {
3912
3941
  totalEarn: { $ifNull: [ 0, 0 ] },
3913
3942
  totalReducedAmount: { $ifNull: [ 0, 0 ] },
3914
3943
  totalCredit: { $ifNull: [ 0, 0 ] },
3944
+ deductionBytimeSpent: { $ifNull: [ 0, 0 ] },
3945
+ deductionByMinimumTarget: { $ifNull: [ 0, 0 ] },
3915
3946
  },
3916
3947
  },
3917
3948
  {
@@ -3929,6 +3960,8 @@ export async function getUserAuditCount( req, res ) {
3929
3960
  totalEarn: { $first: '$totalEarn' },
3930
3961
  totalReducedAmount: { $first: '$totalReducedAmount' },
3931
3962
  totalCredit: { $first: '$totalCredit' },
3963
+ deductionByMinimumTarget: { $first: '$deductionByMinimumTarget' },
3964
+ deductionBytimeSpent: { $first: '$deductionBytimeSpent' },
3932
3965
  },
3933
3966
  },
3934
3967
  {
@@ -3945,6 +3978,9 @@ export async function getUserAuditCount( req, res ) {
3945
3978
  totalEarn: { $add: [ { $multiply: [ '$totalBeforeCount', beforeCountX ] }, { $multiply: [ '$totalAfterCount', afterCountY ] } ] },
3946
3979
  totalReducedAmount: 1,
3947
3980
  totalCredit: 1,
3981
+ deductionBytimeSpent: 1,
3982
+ deductionByMinimumTarget: 1,
3983
+
3948
3984
 
3949
3985
  },
3950
3986
  },
@@ -3956,13 +3992,27 @@ export async function getUserAuditCount( req, res ) {
3956
3992
  totalBeforeCount: 1,
3957
3993
  totalAfterCount: 1,
3958
3994
  totalTimeSpent: 1,
3995
+ hours: { $floor: { $divide: [ '$totalTimeSpent', 3600 ] } },
3996
+ minutes: {
3997
+ $floor: {
3998
+ $divide: [
3999
+ { $mod: [ '$totalTimeSpent', 3600 ] }, // Get remaining minutes after hours
4000
+ 60,
4001
+ ] },
4002
+ },
3959
4003
  fileDate: 1,
3960
4004
  fileDateISO: 1,
3961
4005
  minimumTarget: 1,
3962
4006
  totalEarn: 1,
3963
- totalReducedAmount: { $cond: [
4007
+ deductionBytimeSpent: { $cond: [
3964
4008
  { $lt: [ '$totalTimeSpent', configTimeSpentSec ] },
3965
- { $add: [ '$totalReducedAmount', { $multiply: [ reduce, '$totalEarn' ] } ] }, '$totalReducedAmount',
4009
+ { $multiply: [ reduce, '$totalEarn' ] }, '$deductionBytimeSpent',
4010
+ ] },
4011
+
4012
+ deductionByMinimumTarget:
4013
+ { $cond: [
4014
+ { $lt: [ '$totalBeforeCount', '$minimumTarget' ] },
4015
+ { $multiply: [ reduce, '$totalEarn' ] }, '$deductionByMinimumTarget',
3966
4016
  ] },
3967
4017
  totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
3968
4018
 
@@ -3976,18 +4026,33 @@ export async function getUserAuditCount( req, res ) {
3976
4026
  moduleType: 1,
3977
4027
  totalBeforeCount: 1,
3978
4028
  totalAfterCount: 1,
3979
- totalTimeSpent: 1,
4029
+ totalTimeSpent: {
4030
+ $cond: [ { $eq: [ '$hours', 0 ] },
4031
+ { $concat: [
4032
+ { $toString: '$minutes' }, ' minutes',
4033
+ ] },
4034
+ { $cond: [ { $eq: [ '$minutes', 0 ] },
4035
+ { $concat: [
4036
+ { $toString: '$hours' }, ' hours',
4037
+ ] },
4038
+ {
4039
+ $concat: [
4040
+ { $toString: '$hours' }, ' hours and ',
4041
+ { $toString: '$minutes' }, ' minutes',
4042
+ ],
4043
+ },
4044
+ ] },
4045
+ ],
4046
+
4047
+ },
3980
4048
  fileDate: 1,
3981
4049
  fileDateISO: 1,
3982
4050
  minimumTarget: 1,
3983
4051
  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
-
4052
+ deductionByMinimumTarget: 1,
4053
+ deductionBytimeSpent: 1,
3990
4054
  totalCredit: { $subtract: [ '$totalEarn', '$totalReducedAmount' ] },
4055
+ totalReducedAmount: { $round: [ { $add: [ '$deductionBytimeSpent', '$deductionByMinimumTarget' ] }, 2 ] },
3991
4056
  },
3992
4057
  },
3993
4058
  {
@@ -4019,10 +4084,12 @@ export async function getUserAuditCount( req, res ) {
4019
4084
  moduleType: 1,
4020
4085
  totalAfterCount: { $round: [ '$totalAfterCount', 2 ] },
4021
4086
  totalBeforeCount: { $round: [ '$totalBeforeCount', 2 ] },
4022
- timeSpent: { $round: [ '$totalTimeSpent', 2 ] },
4087
+ timeSpent: '$totalTimeSpent',
4023
4088
  fileDate: 1,
4024
4089
  fileDateISO: 1,
4025
- totalReducedAmount: { $round: [ '$totalReducedAmount', 2 ] },
4090
+ deductionByMinimumTarget: { $round: [ '$deductionByMinimumTarget', 2 ] },
4091
+ deductionBytimeSpent: { $round: [ '$deductionBytimeSpent', 2 ] },
4092
+ totalReducedAmount: 1,
4026
4093
  totalCredit: { $round: [ { $subtract: [ '$totalEarn', '$totalReducedAmount' ] }, 2 ] },
4027
4094
  totalEarn: { $round: [ '$totalEarn', 2 ] },
4028
4095
  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 } );
@@ -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
+ };