tango-app-api-trax 1.0.0-task.126 → 1.0.0-task.127

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-trax",
3
- "version": "1.0.0-task.126",
3
+ "version": "1.0.0-task.127",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -28,14 +28,13 @@ export const checklist = async ( req, res ) => {
28
28
  let offset = parseInt( req.query.offset - 1 ) || 0;
29
29
  let page = offset * limit;
30
30
  let query = [];
31
- console.log( req.user.email, 'email' );
32
31
  query.push(
33
32
  {
34
33
  $match: {
35
34
  type: 'checklist',
36
35
  client_id: req.query.clientId,
37
36
  isdeleted: false,
38
- ...( req.user.userType == 'client' && req.user.role != 'superadmin' ) ? { owner: { $in: [ req.user.email ] } } : {},
37
+ ...( req.user.userType == 'client' && req.user.role != 'superadmin' ) ? { 'owner.value': { $in: [ req.user.email ] } } : {},
39
38
  },
40
39
  },
41
40
  );
@@ -2954,82 +2954,83 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
2954
2954
 
2955
2955
  rangeOneFindQuery.push( { $match: { $and: rangeOneFindAndQuery } } );
2956
2956
 
2957
- rangeOneFindQuery.push( {
2958
- $project: {
2959
- sourceCheckList_id: 1,
2960
- checkListId: 1,
2961
- checklistStatus: 1,
2962
- timeFlag: 1,
2963
- questionFlag: 1,
2964
- checkListType: 1,
2965
- questionCount: 1,
2966
- },
2967
- } );
2968
2957
 
2969
- rangeOneFindQuery.push( {
2970
- $group: {
2971
- _id: '',
2972
- totalChecklist: { $sum: 1 },
2973
- notSubmittedChecklist: {
2974
- $sum: { $cond: [ { $ne: [ '$checklistStatus', 'submit' ] }, 1, 0 ] },
2975
- },
2976
- openChecklist: {
2977
- $sum: { $cond: [ { $eq: [ '$checklistStatus', 'open' ] }, 1, 0 ] },
2978
- },
2979
- inprogressChecklist: {
2980
- $sum: { $cond: [ { $eq: [ '$checklistStatus', 'inprogress' ] }, 1, 0 ] },
2958
+ let queryFormat = [
2959
+ {
2960
+ $project: {
2961
+ sourceCheckList_id: 1,
2962
+ checkListId: 1,
2963
+ checklistStatus: 1,
2964
+ timeFlag: 1,
2965
+ questionFlag: 1,
2966
+ checkListType: 1,
2967
+ questionCount: 1,
2981
2968
  },
2982
- submittedChecklist: {
2983
- $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] },
2969
+ },
2970
+ {
2971
+ $group: {
2972
+ _id: '',
2973
+ totalChecklist: { $sum: 1 },
2974
+ notSubmittedChecklist: {
2975
+ $sum: { $cond: [ { $ne: [ '$checklistStatus', 'submit' ] }, 1, 0 ] },
2976
+ },
2977
+ openChecklist: {
2978
+ $sum: { $cond: [ { $eq: [ '$checklistStatus', 'open' ] }, 1, 0 ] },
2979
+ },
2980
+ inprogressChecklist: {
2981
+ $sum: { $cond: [ { $eq: [ '$checklistStatus', 'inprogress' ] }, 1, 0 ] },
2982
+ },
2983
+ submittedChecklist: {
2984
+ $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] },
2985
+ },
2986
+ timeFlag: { $sum: '$timeFlag' },
2987
+ questionFlagCount: { $sum: '$questionFlag' },
2988
+ questionCount: { $sum: '$questionCount' },
2984
2989
  },
2985
- timeFlag: { $sum: '$timeFlag' },
2986
- questionFlagCount: { $sum: '$questionFlag' },
2987
- questionCount: { $sum: '$questionCount' },
2988
2990
  },
2989
- } );
2990
-
2991
- rangeOneFindQuery.push( {
2992
- $project: {
2993
- totalChecklist: 1,
2994
- notSubmittedChecklist: 1,
2995
- openChecklist: 1,
2996
- inprogressChecklist: 1,
2997
- submittedChecklist: 1,
2998
- flaggedChecklist: { $add: [ '$timeFlag', '$questionFlagCount' ] },
2999
- completionScore: { $round: [ { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] }, 0 ] },
3000
- // completionScore: { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] },
3001
- questionFlagCount: 1,
3002
- questionCount: 1,
3003
- timeFlag: 1,
3004
- correctAnswers: { $subtract: [ '$questionCount', '$questionFlagCount' ] },
2991
+ {
2992
+ $project: {
2993
+ totalChecklist: 1,
2994
+ notSubmittedChecklist: 1,
2995
+ openChecklist: 1,
2996
+ inprogressChecklist: 1,
2997
+ submittedChecklist: 1,
2998
+ flaggedChecklist: { $add: [ '$timeFlag', '$questionFlagCount' ] },
2999
+ completionScore: { $round: [ { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] }, 0 ] },
3000
+ // completionScore: { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] },
3001
+ questionFlagCount: 1,
3002
+ questionCount: 1,
3003
+ timeFlag: 1,
3004
+ correctAnswers: { $subtract: [ '$questionCount', '$questionFlagCount' ] },
3005
+ },
3005
3006
  },
3006
- } );
3007
-
3008
- rangeOneFindQuery.push( {
3009
- $project: {
3010
- totalChecklist: 1,
3011
- notSubmittedChecklist: 1,
3012
- openChecklist: 1,
3013
- inprogressChecklist: 1,
3014
- submittedChecklist: 1,
3015
- flaggedChecklist: 1,
3016
- completionScore: 1,
3017
- questionFlagCount: 1,
3018
- questionCount: 1,
3019
- correctAnswers: 1,
3020
- timeFlag: 1,
3021
- questionCompletionScore: {
3022
- $cond: {
3023
- if: { $eq: [ '$questionCount', 0 ] },
3024
- then: 0,
3025
- else: {
3026
- $round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 0 ],
3027
- // $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ],
3007
+ {
3008
+ $project: {
3009
+ totalChecklist: 1,
3010
+ notSubmittedChecklist: 1,
3011
+ openChecklist: 1,
3012
+ inprogressChecklist: 1,
3013
+ submittedChecklist: 1,
3014
+ flaggedChecklist: 1,
3015
+ completionScore: 1,
3016
+ questionFlagCount: 1,
3017
+ questionCount: 1,
3018
+ correctAnswers: 1,
3019
+ timeFlag: 1,
3020
+ questionCompletionScore: {
3021
+ $cond: {
3022
+ if: { $eq: [ '$questionCount', 0 ] },
3023
+ then: 0,
3024
+ else: {
3025
+ $round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 0 ],
3026
+ // $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ],
3027
+ },
3028
3028
  },
3029
3029
  },
3030
3030
  },
3031
3031
  },
3032
- } );
3032
+ ];
3033
+ rangeOneFindQuery.push( ...queryFormat );
3033
3034
  let rangeOneData = await processedchecklistService.aggregate( rangeOneFindQuery );
3034
3035
  console.log( 'rangeOneData =>', rangeOneData );
3035
3036
 
@@ -3042,7 +3043,7 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
3042
3043
  { date_iso: { $lte: rangeTwoToDate } },
3043
3044
  { checkListType: { $eq: 'custom' } },
3044
3045
  );
3045
- if ( requestData.groupByType == 'checklist' ) {
3046
+ if ( requestData.groupByType == 'Checklist' ) {
3046
3047
  rangeTwoFindAndQuery.push( { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.groupByValue ) } );
3047
3048
  }
3048
3049
 
@@ -3056,82 +3057,7 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
3056
3057
 
3057
3058
  rangeTwoFindQuery.push( { $match: { $and: rangeTwoFindAndQuery } } );
3058
3059
 
3059
- rangeTwoFindQuery.push( {
3060
- $project: {
3061
- sourceCheckList_id: 1,
3062
- checkListId: 1,
3063
- checklistStatus: 1,
3064
- timeFlag: 1,
3065
- questionFlag: 1,
3066
- checkListType: 1,
3067
- questionCount: 1,
3068
- },
3069
- } );
3070
-
3071
- rangeTwoFindQuery.push( {
3072
- $group: {
3073
- _id: '',
3074
- totalChecklist: { $sum: 1 },
3075
- notSubmittedChecklist: {
3076
- $sum: { $cond: [ { $ne: [ '$checklistStatus', 'submit' ] }, 1, 0 ] },
3077
- },
3078
- openChecklist: {
3079
- $sum: { $cond: [ { $eq: [ '$checklistStatus', 'open' ] }, 1, 0 ] },
3080
- },
3081
- inprogressChecklist: {
3082
- $sum: { $cond: [ { $eq: [ '$checklistStatus', 'inprogress' ] }, 1, 0 ] },
3083
- },
3084
- submittedChecklist: {
3085
- $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] },
3086
- },
3087
- timeFlag: { $sum: '$timeFlag' },
3088
- questionFlagCount: { $sum: '$questionFlag' },
3089
- questionCount: { $sum: '$questionCount' },
3090
- },
3091
- } );
3092
-
3093
- rangeTwoFindQuery.push( {
3094
- $project: {
3095
- totalChecklist: 1,
3096
- notSubmittedChecklist: 1,
3097
- openChecklist: 1,
3098
- inprogressChecklist: 1,
3099
- submittedChecklist: 1,
3100
- flaggedChecklist: { $add: [ '$timeFlag', '$questionFlagCount' ] },
3101
- completionScore: { $round: [ { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] }, 0 ] },
3102
- // completionScore: { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] },
3103
- questionFlagCount: 1,
3104
- questionCount: 1,
3105
- timeFlag: 1,
3106
- correctAnswers: { $subtract: [ '$questionCount', '$questionFlagCount' ] },
3107
- },
3108
- } );
3109
-
3110
- rangeTwoFindQuery.push( {
3111
- $project: {
3112
- totalChecklist: 1,
3113
- notSubmittedChecklist: 1,
3114
- openChecklist: 1,
3115
- inprogressChecklist: 1,
3116
- submittedChecklist: 1,
3117
- flaggedChecklist: 1,
3118
- completionScore: 1,
3119
- questionFlagCount: 1,
3120
- questionCount: 1,
3121
- correctAnswers: 1,
3122
- timeFlag: 1,
3123
- questionCompletionScore: {
3124
- $cond: {
3125
- if: { $eq: [ '$questionCount', 0 ] },
3126
- then: 0,
3127
- else: {
3128
- $round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 0 ],
3129
- // $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ],
3130
- },
3131
- },
3132
- },
3133
- },
3134
- } );
3060
+ rangeTwoFindQuery.push( ...queryFormat );
3135
3061
  let rangeTwoData = await processedchecklistService.aggregate( rangeTwoFindQuery );
3136
3062
  console.log( 'rangeTwoData =>', rangeTwoData );
3137
3063
 
@@ -3171,11 +3097,11 @@ export const infoComparisonCardsV1 = async ( req, res ) => {
3171
3097
  infoComparisonCards.complianceRate.ComparisonFlag = false;
3172
3098
  }
3173
3099
 
3174
- infoComparisonCards.totalInstances.comparisonData = Math.abs( infoComparisonCards.totalInstances.comparisonData );
3175
- infoComparisonCards.completedInstances.comparisonData = Math.abs( infoComparisonCards.completedInstances.comparisonData );
3176
- infoComparisonCards.flags.comparisonData = Math.abs( infoComparisonCards.flags.comparisonData );
3177
- infoComparisonCards.completionScore.comparisonData = Math.abs( infoComparisonCards.completionScore.comparisonData );
3178
- infoComparisonCards.complianceRate.comparisonData = Math.abs( infoComparisonCards.complianceRate.comparisonData );
3100
+ infoComparisonCards.totalInstances.comparisonData = Math.abs( infoComparisonCards.totalInstances.comparisonData ) || 0;
3101
+ infoComparisonCards.completedInstances.comparisonData = Math.abs( infoComparisonCards.completedInstances.comparisonData ) || 0;
3102
+ infoComparisonCards.flags.comparisonData = Math.abs( infoComparisonCards.flags.comparisonData ) || 0;
3103
+ infoComparisonCards.completionScore.comparisonData = Math.abs( infoComparisonCards.completionScore.comparisonData ) || 0;
3104
+ infoComparisonCards.complianceRate.comparisonData = Math.abs( infoComparisonCards.complianceRate.comparisonData ) || 0;
3179
3105
  }
3180
3106
  console.log( 'infoComparisonCards =>', infoComparisonCards );
3181
3107
  let result = {