tango-app-api-trax 3.3.1-beta-62 → 3.3.1-beta-64

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,11 +1,11 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.3.1-beta-62",
3
+ "version": "3.3.1-beta-64",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node index.js\""
8
+ "start": "nodemon --exec \"eslint --fix . && node app.js\""
9
9
  },
10
10
  "engines": {
11
11
  "node": ">=18.10.0"
@@ -152,7 +152,7 @@ export async function storesList( req, res ) {
152
152
  export const checklistDropdown = async ( req, res ) => {
153
153
  try {
154
154
  let requestData = req.body;
155
- // let fromDate = new Date( requestData.fromDate );
155
+ let fromDate = new Date( requestData.fromDate );
156
156
  let toDate = new Date( requestData.toDate );
157
157
  let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
158
158
  toDate = new Date( toDate.getTime() - userTimezoneOffset );
@@ -163,8 +163,8 @@ export const checklistDropdown = async ( req, res ) => {
163
163
  let findAndQuery = [];
164
164
  findAndQuery.push(
165
165
  { client_id: requestData.clientId },
166
- // { date_iso: { $gte: fromDate } },
167
- // { date_iso: { $lte: toDate } },
166
+ { date_iso: { $gte: fromDate } },
167
+ { date_iso: { $lte: toDate } },
168
168
  // { checkListType: { $eq: 'custom' } },
169
169
  );
170
170
 
@@ -2399,6 +2399,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2399
2399
  checklistStatus: 1,
2400
2400
  questionFlagCount: '$questionFlag',
2401
2401
  timeFlagCount: '$timeFlag',
2402
+ userName: '$userName',
2402
2403
  reinitiateStatus: true,
2403
2404
  // detections: {
2404
2405
  // $sum: {
@@ -2424,7 +2425,7 @@ export const flagChecklistTableV1 = async ( req, res ) => {
2424
2425
  ];
2425
2426
 
2426
2427
  if ( reqestData.search && reqestData.search != '' ) {
2427
- pipeline[0].$match.$and.push( { storeName: { $regex: reqestData.search, $options: 'i' } } );
2428
+ pipeline[0].$match.$and.push( { $or: [ { storeName: { $regex: reqestData.search, $options: 'i' } }, { userName: { $regex: reqestData.search, $options: 'i' } }, { userEmail: { $regex: reqestData.search, $options: 'i' } } ] } );
2428
2429
  }
2429
2430
 
2430
2431
  const total = await processedchecklistService.aggregate( pipeline );
@@ -2653,12 +2654,14 @@ export const checklistDropdownV1 = async ( req, res ) => {
2653
2654
  $project: {
2654
2655
  sourceCheckList_id: 1,
2655
2656
  checkListName: 1,
2657
+ coverage: 1,
2656
2658
  },
2657
2659
  },
2658
2660
  {
2659
2661
  $group: {
2660
2662
  _id: '$sourceCheckList_id',
2661
2663
  checkListName: { $last: '$checkListName' },
2664
+ coverage: { $last: '$coverage' },
2662
2665
  },
2663
2666
  },
2664
2667
  {
@@ -2666,6 +2669,7 @@ export const checklistDropdownV1 = async ( req, res ) => {
2666
2669
  _id: 0,
2667
2670
  sourceCheckList_id: '$_id',
2668
2671
  checkListName: 1,
2672
+ coverage: 1,
2669
2673
  },
2670
2674
  },
2671
2675
  {
@@ -2694,7 +2698,6 @@ export const checklistDropdownV1 = async ( req, res ) => {
2694
2698
  scheduleRepeatedType: 1,
2695
2699
  scheduleStartTime: 1,
2696
2700
  sourceCheckList_id: '$_id',
2697
- storeCount: 1,
2698
2701
  },
2699
2702
  },
2700
2703
  ], as: 'checklistData',
@@ -2713,7 +2716,7 @@ export const checklistDropdownV1 = async ( req, res ) => {
2713
2716
  scheduleRepeatedType: '$checklistData.scheduleRepeatedType',
2714
2717
  scheduleStartTime: '$checklistData.scheduleStartTime',
2715
2718
  sourceCheckList_id: '$checklistData._id',
2716
- storeCount: '$checklistData.storeCount',
2719
+ coverage: 1,
2717
2720
  },
2718
2721
  },
2719
2722
  ];
@@ -2083,12 +2083,12 @@ export const validateUserv1 = async ( req, res ) => {
2083
2083
  assignDetails.forEach( ( item ) => {
2084
2084
  let getStoreDetails = storeDetails.find( ( store ) => store.storeName.toLowerCase() == item.storeName.toLowerCase() );
2085
2085
  if ( getStoreDetails ) {
2086
- let storeUserDetails = userDetails.find( ( ele ) => ele.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
2086
+ // let storeUserDetails = userDetails.find( ( ele ) => ele.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
2087
2087
  item._id = getStoreDetails._id;
2088
2088
  item.storeId = getStoreDetails.storeId;
2089
- item.userName = storeUserDetails ? storeUserDetails?.userName : item.userName;
2089
+ item.userName = getStoreDetails?.spocDetails?.[0]?.name || item.userName;
2090
2090
  item.storeName = getStoreDetails.storeName;
2091
- item.userEmail = storeUserDetails ? storeUserDetails?.email : item.userEmail;
2091
+ item.userEmail = getStoreDetails?.spocDetails?.[0]?.email || item.userEmail;
2092
2092
  }
2093
2093
  } );
2094
2094
  } else {
@@ -738,119 +738,91 @@ export const userPerformance = async ( req, res ) => {
738
738
  userEmail: { $last: '$userEmail' },
739
739
  checkListCount: { $sum: '$_id' },
740
740
  timeFlag: { $sum: '$timeFlag' },
741
- submittedChecklist: {
742
- $sum: {
743
- $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ],
744
- },
745
- },
741
+ submittedChecklist: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
746
742
  checkListType: { $last: '$checkListType' },
747
- // questionFlag: { $sum: '$questionFlag' },
748
743
  questionFlag: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionFlag', 0 ] } },
749
744
  questionCount: { $sum: '$questionCount' },
750
- submittedChecklistQuestionCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] } },
745
+ submittedChecklistQuestionCount: {
746
+ $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ] },
747
+ },
751
748
  },
752
749
  } );
753
750
 
751
+
754
752
  findQuery.push( {
755
- $project: {
753
+ $addFields: {
756
754
  userName: '$_id',
757
- userEmail: 1,
758
- checkListCount: { $sum: '$totalChecklist' },
759
755
  flaggedCount: { $add: [ '$timeFlag', '$questionFlag' ] },
760
- submittedChecklist: 1,
761
- timeFlag: 1,
762
- checkListType: 1,
763
- questionCount: 1,
764
- questionFlag: 1,
756
+ correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount', '$questionFlag' ] },
765
757
  completion: {
766
- $round: [ { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] }, 0 ],
767
- // $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ],
758
+ $round: [
759
+ { $multiply: [ { $divide: [ '$submittedChecklist', '$totalChecklist' ] }, 100 ] },
760
+ 0,
761
+ ],
768
762
  },
769
- correctAnswers: { $subtract: [ '$submittedChecklistQuestionCount', '$questionFlag' ] },
770
763
  },
771
764
  } );
772
765
 
766
+
773
767
  findQuery.push( {
774
- $project: {
775
- userName: 1,
776
- userEmail: 1,
777
- checkListCount: 1,
778
- flaggedCount: 1,
779
- submittedChecklist: 1,
780
- checkListType: 1,
781
- questionCount: 1,
782
- questionFlag: 1,
783
- timeFlag: 1,
784
- completion: 1,
785
- compliance: 1,
768
+ $addFields: {
786
769
  compliance: {
787
770
  $cond: {
788
771
  if: { $eq: [ '$questionCount', 0 ] },
789
772
  then: 0,
790
773
  else: {
791
774
  $round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 0 ],
792
- // $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ],
793
775
  },
794
776
  },
795
777
  },
778
+ lowercaseUserName: { $toLower: '$userName' },
796
779
  },
797
780
  } );
798
781
 
799
782
  findQuery.push( {
800
- $project: {
801
- userName: 1,
802
- lowercaseUserName: { $toLower: '$userName' },
803
- userEmail: 1,
804
- checkListCount: 1,
805
- flaggedCount: 1,
806
- submittedChecklist: 1,
807
- checkListType: 1,
808
- questionCount: 1,
809
- questionFlag: 1,
810
- timeFlag: 1,
811
- correctAnswers: 1,
812
- completion: 1,
813
- compliance: 1,
783
+ $addFields: {
814
784
  performance: { $round: [ { $divide: [ { $add: [ '$completion', '$compliance' ] }, 2 ] }, 0 ] },
815
- // performance: { $divide: [ { $add: [ '$completion', '$compliance' ] }, 2 ] },
816
785
  },
817
786
  } );
818
787
 
819
- // let getTotalCount = await processedchecklistService.aggregate( findQuery );
820
- // if ( !getTotalCount.length ) {
821
- // return res.sendError( { error: 'No Data Found' }, 204 );
822
- // }
823
-
824
- if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
825
- if ( requestData.sortColumnName == 'userName' ) {
826
- findQuery.push( { $sort: { ['lowercaseUserName']: requestData.sortBy } } );
827
- } else {
828
- findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
829
- }
788
+ if ( requestData.sortColumnName && requestData.sortBy ) {
789
+ const sortField =
790
+ requestData.sortColumnName === 'userName' ? 'lowercaseUserName' : requestData.sortColumnName;
791
+ findQuery.push( { $sort: { [sortField]: requestData.sortBy } } );
830
792
  } else {
831
- findQuery.push( { $sort: { ['userName']: -1 } } );
793
+ findQuery.push( { $sort: { userName: -1 } } );
832
794
  }
833
795
 
834
796
  let limit = parseInt( requestData?.limit ) || 10;
835
- let skip = limit * ( requestData?.offset ) || 0;
797
+ let skip = limit * ( requestData?.offset || 0 );
836
798
  findQuery.push( {
837
799
  $facet: {
838
- data: [
839
- { $skip: skip }, { $limit: limit },
840
- ],
841
- count: [
842
- { $count: 'total' },
843
- ],
800
+ data: [ { $skip: skip }, { $limit: limit } ],
801
+ count: [ { $count: 'total' } ],
844
802
  },
845
- },
846
- );
803
+ } );
804
+
847
805
 
848
806
  let getUserPerformanceData = await processedchecklistService.aggregate( findQuery );
849
807
 
850
808
  if ( !getUserPerformanceData[0].data.length ) {
851
809
  return res.sendError( { error: 'No Data Found' }, 204 );
852
810
  }
853
-
811
+ if ( requestData.export ) {
812
+ const exportdata = [];
813
+ getUserPerformanceData[0].data.forEach( ( element ) => {
814
+ exportdata.push( {
815
+ 'User Name': element.userName || '--',
816
+ 'Email': element.userEmail || '--',
817
+ 'Checklist Assigned': element.checkListCount || '--',
818
+ 'Flags': element.flaggedCount || '--',
819
+ 'Completion %': element.completion || '--',
820
+ 'Compliance %': element.compliance || '--',
821
+ 'Performance %': element.performance || '--',
822
+ } );
823
+ } );
824
+ return await download( exportdata, res );
825
+ }
854
826
  result.totalCount = getUserPerformanceData[0].count[0].total;
855
827
  result.userPerformance = getUserPerformanceData[0].data;
856
828
  return res.sendSuccess( result );
@@ -1250,7 +1222,11 @@ export const checklistInfo = async ( req, res ) => {
1250
1222
  findQuery.push( { $addFields: { store: { $toLower: '$storeName' } } } );
1251
1223
  query = { store: { $in: storeList } };
1252
1224
  } else {
1253
- query = { storeName: { $regex: requestData.searchValue.trim(), $options: 'i' } };
1225
+ query = { $or: [
1226
+ { storeName: { $regex: requestData.searchValue.trim(), $options: 'i' } },
1227
+ { userEmail: { $regex: requestData.searchValue.trim(), $options: 'i' } },
1228
+ { userName: { $regex: requestData.searchValue.trim(), $options: 'i' } },
1229
+ ] };
1254
1230
  }
1255
1231
  findQuery.push( { $match: { $or: [ query ] } } );
1256
1232
  } else {
@@ -1266,6 +1242,38 @@ export const checklistInfo = async ( req, res ) => {
1266
1242
  findQuery.push( { $match: { $or: [ query ] } } );
1267
1243
  }
1268
1244
  }
1245
+ findQuery.push( { $sort: { _id: -1 } } );
1246
+
1247
+ findQuery.push( {
1248
+ $group: {
1249
+ _id: { store: '$store_id', email: '$userEmail' },
1250
+ checkListName: { $first: '$checkListName' },
1251
+ coverage: { $first: '$coverage' },
1252
+ createdByName: { $first: '$createdByName' },
1253
+ userName: { $first: '$userName' },
1254
+ userEmail: { $first: '$userEmail' },
1255
+ checklistStatus: { $last: '$checklistStatus' },
1256
+ submitTime_string: { $push: '$submitTime_string' },
1257
+ storeName: { $first: '$storeName' },
1258
+ checkListType: { $first: '$checkListType' },
1259
+ scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
1260
+ timeFlag: { $sum: '$timeFlag' },
1261
+ questionFlag: { $sum: '$questionFlag' },
1262
+ date_iso: { $first: '$date_iso' },
1263
+ store_id: { $first: '$store_id' },
1264
+ date_string: { $first: '$date_string' },
1265
+ sourceCheckList_id: { $first: '$sourceCheckList_id' },
1266
+ reinitiateStatus: { $first: '$reinitiateStatus' },
1267
+ redoStatus: { $first: '$redoStatus' },
1268
+ submitCount: { $sum: {
1269
+ $cond: {
1270
+ if: { $eq: [ '$checklistStatus', 'submit' ] },
1271
+ then: 1,
1272
+ else: 0,
1273
+ },
1274
+ } },
1275
+ },
1276
+ } );
1269
1277
 
1270
1278
  findQuery.push( {
1271
1279
  $project: {
@@ -1273,21 +1281,22 @@ export const checklistInfo = async ( req, res ) => {
1273
1281
  coverage: 1,
1274
1282
  createdByName: 1,
1275
1283
  userName: 1,
1276
- userEmail: 1,
1284
+ userEmail: '$_id.email',
1277
1285
  checklistStatus: 1,
1278
- submitTime_string: 1,
1286
+ submitTime_string: { $arrayElemAt: [ '$submitTime_string', -1 ] },
1279
1287
  storeName: 1,
1280
1288
  checkListType: 1,
1281
1289
  scheduleRepeatedType: 1,
1282
1290
  timeFlag: 1,
1283
1291
  questionFlag: 1,
1284
1292
  date_iso: 1,
1285
- store_id: 1,
1293
+ store_id: '$_id.store',
1286
1294
  timeFlag: 1,
1287
1295
  date_string: 1,
1288
1296
  sourceCheckList_id: 1,
1289
1297
  reinitiateStatus: 1,
1290
1298
  redoStatus: 1,
1299
+ submitCount: 1,
1291
1300
  },
1292
1301
  } );
1293
1302
 
@@ -1334,30 +1343,76 @@ export const checklistInfo = async ( req, res ) => {
1334
1343
  sourceCheckList_id: 1,
1335
1344
  reinitiateStatus: 1,
1336
1345
  redoStatus: 1,
1346
+ submitCount: 1,
1337
1347
  },
1338
1348
  } );
1339
1349
 
1340
- let getTotalCount = await processedchecklistService.aggregate( findQuery );
1341
- if ( !getTotalCount.length ) {
1342
- return res.sendError( { error: 'No Data Found' }, 204 );
1343
- }
1350
+ // let getTotalCount = await processedchecklistService.aggregate( findQuery );
1351
+ // if ( !getTotalCount.length ) {
1352
+ // return res.sendError( { error: 'No Data Found' }, 204 );
1353
+ // }
1344
1354
 
1345
1355
  if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
1346
1356
  findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
1347
- } else {
1348
- findQuery.push( { $sort: { ['date_iso']: -1 } } );
1349
1357
  }
1350
-
1351
1358
  let limit = parseInt( requestData?.limit ) || 10;
1352
1359
  let skip = limit * ( requestData?.offset ) || 0;
1353
- findQuery.push( { $skip: skip }, { $limit: limit } );
1354
- let getChecklistPerformanceData = await processedchecklistService.aggregate( findQuery );
1355
1360
 
1356
- result.totalCount = getTotalCount.length;
1357
- for ( let i = 0; i < getChecklistPerformanceData.length; i++ ) {
1358
- getChecklistPerformanceData[i].date_string = dayjs( getChecklistPerformanceData[i].date_string ).format( 'DD MMM YYYY' );
1361
+ findQuery.push(
1362
+ {
1363
+ $facet: {
1364
+ data: [
1365
+ { $skip: skip }, { $limit: limit },
1366
+ ],
1367
+ count: [
1368
+ { $count: 'total' },
1369
+ ],
1370
+ },
1371
+ },
1372
+ );
1373
+
1374
+
1375
+ let getChecklistPerformanceData = await processedchecklistService.aggregate( findQuery );
1376
+ if ( !getChecklistPerformanceData[0].data.length ) {
1377
+ return res.sendError( 'No data found', 204 );
1359
1378
  }
1360
1379
  result.checklistInfo = getChecklistPerformanceData;
1380
+ if ( requestData.export ) {
1381
+ const exportdata = [];
1382
+ result.checklistInfo.forEach( ( element ) => {
1383
+ if ( requestData.groupByType==='Checklist' ) {
1384
+ exportdata.push( {
1385
+ 'Date': element.date_string || '--',
1386
+ 'Store Name': element.storeName || '--',
1387
+ 'Checklist Owner': element.userName || '--',
1388
+ 'Submitted By': element.userName || '--',
1389
+ 'Status': element.checklistStatus || '--',
1390
+ 'Submitted On': element.submitTime_string || '--',
1391
+ 'Flags': element.flaggedChecklist || '--',
1392
+ } );
1393
+ } else if ( requestData.groupByType==='Store' ) {
1394
+ exportdata.push( {
1395
+ 'CheckList Name': element.checkListName || '--',
1396
+ 'Checklist Owner': element.userName || '--',
1397
+ 'Submitted By': element.userName || '--',
1398
+ 'Status': element.checklistStatus || '--',
1399
+ 'Submitted On': element.submitTime_string || '--',
1400
+ 'Flags': element.flaggedChecklist || '--',
1401
+ } );
1402
+ } else {
1403
+ exportdata.push( {
1404
+ 'Date': element.date_string || '--',
1405
+ 'CheckList Name': element.checkListName || '--',
1406
+ 'Store Name': element.storeName || '--',
1407
+ 'Checklist Owner': element.userName || '--',
1408
+ 'Status': element.checklistStatus || '--',
1409
+ 'Submitted On': element.submitTime_string || '--',
1410
+ 'Flags': element.flaggedChecklist || '--',
1411
+ } );
1412
+ }
1413
+ } );
1414
+ return await download( exportdata, res );
1415
+ }
1361
1416
  return res.sendSuccess( result );
1362
1417
  } catch ( error ) {
1363
1418
  console.log( 'error =>', error );
@@ -3566,12 +3621,15 @@ export const checklistDropdown = async ( req, res ) => {
3566
3621
  $project: {
3567
3622
  sourceCheckList_id: 1,
3568
3623
  checkListName: 1,
3624
+ coverage: 1,
3569
3625
  },
3570
3626
  },
3571
3627
  {
3572
3628
  $group: {
3573
3629
  _id: '$sourceCheckList_id',
3574
3630
  checkListName: { $last: '$checkListName' },
3631
+ storeCount: { $sum: 1 },
3632
+ coverage: { $last: '$coverage' },
3575
3633
  },
3576
3634
  },
3577
3635
  {
@@ -3579,6 +3637,8 @@ export const checklistDropdown = async ( req, res ) => {
3579
3637
  _id: 0,
3580
3638
  sourceCheckList_id: '$_id',
3581
3639
  checkListName: 1,
3640
+ storeCount: 1,
3641
+ coverage: 1,
3582
3642
  },
3583
3643
  },
3584
3644
  {
@@ -3607,7 +3667,7 @@ export const checklistDropdown = async ( req, res ) => {
3607
3667
  scheduleRepeatedType: 1,
3608
3668
  scheduleStartTime: 1,
3609
3669
  sourceCheckList_id: '$_id',
3610
- storeCount: 1,
3670
+ allowedMultiSubmit: 1,
3611
3671
  },
3612
3672
  },
3613
3673
  ], as: 'checklistData',
@@ -3626,7 +3686,10 @@ export const checklistDropdown = async ( req, res ) => {
3626
3686
  scheduleRepeatedType: '$checklistData.scheduleRepeatedType',
3627
3687
  scheduleStartTime: '$checklistData.scheduleStartTime',
3628
3688
  sourceCheckList_id: '$checklistData._id',
3629
- storeCount: '$checklistData.storeCount',
3689
+ storeCount: 1,
3690
+ coverage: 1,
3691
+ allowedMultiSubmit: '$checklistData.allowedMultiSubmit',
3692
+
3630
3693
  },
3631
3694
  },
3632
3695
  ];
@@ -13,6 +13,7 @@ const tableSchema = {
13
13
  limit: joi.number().required(),
14
14
  offset: joi.number().required(),
15
15
  sortColumnName: joi.string().optional().allow( '' ),
16
+ export: joi.boolean().optional().allow( '' ),
16
17
  };
17
18
 
18
19