tango-app-api-trax 3.3.1-beta-8 → 3.3.1-beta-9

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": "3.3.1-beta-8",
3
+ "version": "3.3.1-beta-9",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.2.35",
29
+ "tango-api-schema": "^2.2.41",
30
30
  "tango-app-api-middleware": "^3.1.50",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
@@ -354,14 +354,14 @@ export async function redoChecklist( req, res ) {
354
354
  return res.sendError( 'section is not found', 400 );
355
355
  }
356
356
 
357
- let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
357
+ let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele?.parentQuestion ? ele.qno == req.body.payload.qno && ele.parentQuestion == req.body.payload.parentQuestion : ele.qno == req.body.payload.qno );
358
358
 
359
359
  let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
360
360
  // if ( checklistDetails.client_id == '458' ) {
361
361
  data.answers.forEach( ( item ) => {
362
362
  if ( item.showLinked ) {
363
363
  item.nestedQuestion.forEach( ( ele ) => {
364
- let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
364
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn?.parentQuestion ? qn.qno == parseInt( ele ) && qn?.parentQuestion == req.body.payload?.parentQuestion : qn.qno == parseInt( ele ) );
365
365
  let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
366
366
  question[sectionIndex].questions[eleIndex] = element;
367
367
  question[sectionIndex].questions[eleIndex].userAnswer = [];
@@ -149,7 +149,7 @@ export async function startChecklist( req, res ) {
149
149
  }
150
150
 
151
151
  let updateData = {};
152
- let storeTimeZone = await storeService.findOne( { storeName: getBeforeChecklist[0].storeName }, { 'storeProfile.timeZone': 1 } );
152
+ let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeChecklist[0].storeName, $options: 'i' }, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
153
153
  let currentDateTime;
154
154
  if ( storeTimeZone?.storeProfile?.timeZone ) {
155
155
  currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
@@ -244,6 +244,7 @@ export async function startChecklist( req, res ) {
244
244
  questions = [];
245
245
  for ( let question of section.questions ) {
246
246
  if ( !question.linkType ) {
247
+ question.parentQuestion = question.qno;
247
248
  questions.push( question );
248
249
  let linkedAnswer = new Set( question.answers.filter( ( ele ) => ele.showLinked ).flatMap( ( ele ) => ele.nestedQuestion ) );
249
250
  let linkedQuestion = section.questions.filter( ( qn ) => linkedAnswer.has( qn.qno ) );
@@ -1725,12 +1726,12 @@ export async function submitChecklist( req, res ) {
1725
1726
  updateQuery._id = new ObjectId( requestData.processedcheckListId );
1726
1727
  updateQuery.userId = req.user._id;
1727
1728
  updateQuery.date_string = requestData.date;
1728
- let storeTimeZone = await storeService.findOne( { storeName: getchecklist[0].storeName }, { 'storeProfile.timeZone': 1 } );
1729
+ let storeTimeZone = await storeService.findOne( { storeName: { $regex: getchecklist[0].storeName, $options: 'i' }, clientId: getchecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
1729
1730
  let currentDateTime;
1730
1731
  if ( storeTimeZone?.storeProfile?.timeZone ) {
1731
1732
  currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
1732
1733
  } else {
1733
- currentDateTime = dayjs();
1734
+ currentDateTime = requestData?.currentTime ? dayjs( requestData.currentTime, 'HH:mm:ss' ) : dayjs();
1734
1735
  }
1735
1736
  let updateData = {};
1736
1737
  let flagCount = QuestionFlag( req, res );
@@ -2605,6 +2606,7 @@ export async function questionList( req, res ) {
2605
2606
  questions = [];
2606
2607
  for ( let question of section.questions ) {
2607
2608
  if ( !question.linkType ) {
2609
+ question.parentQuestion = question.qno;
2608
2610
  questions.push( question );
2609
2611
  let linkedAnswer = new Set( question.answers.filter( ( ele ) => ele.showLinked ).flatMap( ( ele ) => ele.nestedQuestion ) );
2610
2612
  let linkedQuestion = section.questions.filter( ( qn ) => qn?.parentQuestion ? qn?.parentQuestion == question.qno && linkedAnswer.has( qn.qno ) : linkedAnswer.has( qn.qno ) );
@@ -564,7 +564,10 @@ export const flagCardsV1 = async ( req, res ) => {
564
564
  {
565
565
  $match: {
566
566
  client_id: clientId,
567
- store_id: { $in: storeId },
567
+ $or: [
568
+ { store_id: { $in: storeId } },
569
+ { aiStoreList: { $in: storeId } },
570
+ ],
568
571
  date_iso: { $gte: adjustedFromDate, $lte: adjustedToDate },
569
572
  },
570
573
  },
@@ -634,7 +637,7 @@ export const flagCardsV1 = async ( req, res ) => {
634
637
  flagCards.detectionFlag.count += resultData[item];
635
638
  }
636
639
  } );
637
- flagCards.totalFlag = flagCards.detectionFlag.count;
640
+ flagCards.totalFlag += flagCards.detectionFlag.count;
638
641
  }
639
642
 
640
643
  return res.sendSuccess( { flagCards } );
@@ -697,7 +700,12 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
697
700
  }
698
701
 
699
702
  const createFindQuery = ( fromDate, toDate ) => [
700
- { $match: { client_id: requestData.clientId, store_id: { $in: requestData.storeId }, date_iso: { $gte: fromDate, $lte: toDate } } },
703
+ { $match: { client_id: requestData.clientId,
704
+ $or: [
705
+ { store_id: { $in: requestData.storeId } },
706
+ { aiStoreList: { $in: requestData.storeId } },
707
+ ],
708
+ date_iso: { $gte: fromDate, $lte: toDate } } },
701
709
  {
702
710
  $project: {
703
711
  timeFlag: 1,
@@ -874,6 +874,11 @@ export const assignedUserDetails = async ( req, res ) => {
874
874
  query.push( { $match: { storeName: { $regex: req.query.search.trim(), $options: 'i' } } } );
875
875
  }
876
876
  }
877
+ if ( req.query.sortColumn && req.query.sortBy ) {
878
+ query.push( { $sort: { [req.query.sortColumn]: parseInt( req.query.sortBy ) } } );
879
+ } else {
880
+ query.push( { $sort: { _id: -1 } } );
881
+ }
877
882
 
878
883
  query.push( {
879
884
  $facet: {
@@ -893,19 +898,28 @@ export const assignedUserDetails = async ( req, res ) => {
893
898
  }
894
899
 
895
900
  let userDetails = [];
901
+ let storeList = [];
902
+ let userList = [];
896
903
  checklistDetails[0].data.forEach( ( item ) => {
904
+ if ( item?.store_id ) {
905
+ storeList.push( item.assignId );
906
+ } else {
907
+ userList.push( item.assignId );
908
+ }
897
909
  userDetails.push( {
898
910
  id: item._id,
899
911
  userName: item.userName,
900
912
  userEmail: item.userEmail,
901
- store_id: item.store_id,
902
- storeName: item.storeName,
913
+ store_id: item?.store_id,
914
+ storeName: item?.storeName,
903
915
  userPhone: item.userPhone,
904
916
  city: item.city,
905
917
  checkFlag: item.checkFlag,
918
+ clusterName: item?.clusterName,
919
+ teamName: item?.teamName,
906
920
  } );
907
921
  } );
908
- return res.sendSuccess( { users: userDetails, count: checklistDetails[0].count[0].total } );
922
+ return res.sendSuccess( { users: userDetails, count: checklistDetails[0].count[0].total, storeList, userList } );
909
923
  } catch ( e ) {
910
924
  logger.error( 'assignedUserDetails =>', e );
911
925
  return res.sendError( e, 500 );
@@ -2711,3 +2725,192 @@ export const checklistV2 = async ( req, res ) => {
2711
2725
  return res.sendError( e, 500 );
2712
2726
  }
2713
2727
  };
2728
+
2729
+ export async function checklistAssign( req, res ) {
2730
+ try {
2731
+ if ( !req.body.checklistId ) {
2732
+ return res.sendError( 'Checklist id is required', 400 );
2733
+ }
2734
+ if ( !req.body.coverage ) {
2735
+ return res.sendError( 'Coverage is required', 400 );
2736
+ }
2737
+ if ( !req.body.id ) {
2738
+ return res.sendError( 'Store/user id is required', 400 );
2739
+ }
2740
+
2741
+ let checklistDetails = await checklistService.findOne( { _id: req.body.checklistId } );
2742
+ if ( !checklistDetails ) {
2743
+ return res.sendError( 'No data found', 204 );
2744
+ }
2745
+ checklistDetails.coverage = req.body.coverage;
2746
+ checklistDetails.save();
2747
+ let idList;
2748
+ if ( req.body.coverage == 'store' ) {
2749
+ let clusterDetails = await clusterServices.findOneCluster( { _id: req.body.id }, { stores: 1, clusterName: 1 } );
2750
+ if ( clusterDetails ) {
2751
+ idList = clusterDetails.stores.map( ( item ) => item.store );
2752
+ } else {
2753
+ idList = [ new ObjectId( req.body.id ) ];
2754
+ }
2755
+ let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
2756
+ if ( !getStoreDetails.length ) {
2757
+ return res.sendError( 'No data found', 204 );
2758
+ }
2759
+ let assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
2760
+ let userDetails = await userService.findOne( { userEmail: store?.spocDetails?.email, clientId: store.clientId } );
2761
+ if ( !userDetails ) {
2762
+ let data = {
2763
+ clientId: store.clientId,
2764
+ userName: store.spocDetails?.[0]?.name,
2765
+ mobileNumber: store.spocDetails?.[0]?.phone || '',
2766
+ email: store.spocDetails[0].email,
2767
+ password: '5dqFKAJj29PsV6P+kL+3Dw==',
2768
+ role: 'user',
2769
+ userType: 'client',
2770
+ rolespermission: [
2771
+ {
2772
+ featureName: 'Global',
2773
+ modules: [
2774
+ {
2775
+ name: 'Store',
2776
+ isAdd: false,
2777
+ isEdit: false,
2778
+
2779
+ },
2780
+ {
2781
+ name: 'User',
2782
+ isAdd: false,
2783
+ isEdit: false,
2784
+
2785
+ },
2786
+ {
2787
+ name: 'Camera',
2788
+ isAdd: false,
2789
+ isEdit: false,
2790
+
2791
+ },
2792
+ {
2793
+ name: 'Configuration',
2794
+ isAdd: false,
2795
+ isEdit: false,
2796
+
2797
+ },
2798
+ {
2799
+ name: 'Subscription',
2800
+ isAdd: false,
2801
+ isEdit: false,
2802
+
2803
+ },
2804
+ {
2805
+ name: 'Billing',
2806
+ isAdd: false,
2807
+ isEdit: false,
2808
+
2809
+ },
2810
+ ],
2811
+ },
2812
+ {
2813
+ featurName: 'TangoEye',
2814
+ modules: [
2815
+ {
2816
+ name: 'ZoneTag',
2817
+ isAdd: false,
2818
+ isEdit: false,
2819
+
2820
+ },
2821
+ ],
2822
+ },
2823
+ {
2824
+ featurName: 'TangoTrax',
2825
+ modules: [
2826
+ {
2827
+ name: 'checklist',
2828
+ isAdd: false,
2829
+ isEdit: false,
2830
+
2831
+ },
2832
+ {
2833
+ name: 'Task',
2834
+ isAdd: false,
2835
+ isEdit: false,
2836
+
2837
+ },
2838
+ ],
2839
+ },
2840
+ ],
2841
+ };
2842
+ userDetails = await userService.create( data );
2843
+ }
2844
+ let data = {
2845
+ store_id: store.storeId,
2846
+ storeName: store.storeName,
2847
+ userId: userDetails._id,
2848
+ userName: userDetails.userName,
2849
+ userEmail: userDetails.email,
2850
+ userPhone: userDetails?.mobileNumber,
2851
+ city: store?.storeProfile?.city,
2852
+ country: store?.storeprofile?.country,
2853
+ checkFlag: true,
2854
+ checkListId: req.body.checklistId,
2855
+ checkListName: checklistDetails.checkListName,
2856
+ client_id: store.clientId,
2857
+ clusterName: clusterDetails?.clusterName,
2858
+ assignId: req.body.id,
2859
+ };
2860
+ return data;
2861
+ } ) );
2862
+ await assignedService.insertMany( assignList );
2863
+ } else {
2864
+ let teamDetails = await teamsServices.findOneTeams( { _id: req.body.id }, { users: 1, teamName: 1 } );
2865
+ if ( teamDetails ) {
2866
+ idList = teamDetails.users.map( ( item ) => item.userId );
2867
+ } else {
2868
+ idList = [ new ObjectId( req.body.id ) ];
2869
+ }
2870
+ let userDetails = await userService.find( { _id: { $in: idList } } );
2871
+ if ( !userDetails.length ) {
2872
+ return res.sendError( 'No data found', 204 );
2873
+ }
2874
+ let assignList = [];
2875
+ userDetails.forEach( ( user ) => {
2876
+ assignList.push( {
2877
+ userId: user._id,
2878
+ userName: user.userName,
2879
+ userEmail: user.email,
2880
+ userPhone: user?.mobileNumber,
2881
+ checkFlag: true,
2882
+ checkListId: req.body.checklistId,
2883
+ checkListName: checklistDetails.checkListName,
2884
+ client_id: user.clientId,
2885
+ teamName: teamDetails?.teamName,
2886
+ assignId: req.body.id,
2887
+ } );
2888
+ } );
2889
+ await assignedService.insertMany( assignList );
2890
+ }
2891
+ return res.sendSuccess( 'Details updated successfully' );
2892
+ } catch ( e ) {
2893
+ logger.error( { functionName: 'checklistAssign', error: e } );
2894
+ return res.sendError( e, 500 );
2895
+ }
2896
+ }
2897
+
2898
+ export async function removeAssign( req, res ) {
2899
+ try {
2900
+ if ( !req.body.id ) {
2901
+ return res.sendError( 'Id is required', 400 );
2902
+ }
2903
+ if ( !req.body.checkListId ) {
2904
+ return res.sendError( 'Checklist id is required', 400 );
2905
+ }
2906
+ let checklistDetails = await checklistService.findOne( { _id: req.body.checkListId } );
2907
+ if ( !checklistDetails ) {
2908
+ return res.sendError( 'No data found', 204 );
2909
+ }
2910
+ await assignedService.deleteMany( { assignId: req.body.id } );
2911
+ return res.sendSuccess( 'Details removed successfully' );
2912
+ } catch ( e ) {
2913
+ logger.error( { functionName: 'removeAssign', error: e } );
2914
+ return res.sendError( e, 500 );
2915
+ }
2916
+ }
@@ -23,6 +23,8 @@ traxRouter
23
23
  .get( '/aichecklist', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( aichecklistValidation ), traxController.aiChecklist )
24
24
  .get( '/predefinedChecklist', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( aichecklistValidation ), traxController.preDefinedChecklist )
25
25
  .post( '/selectAssign', validate( selectAssign ), traxController.selectAssign )
26
- .get( '/checklistV2', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( checklistPageSchema ), traxController.checklistV2 );
26
+ .get( '/checklistV2', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( checklistPageSchema ), traxController.checklistV2 )
27
+ .post( '/assign', isAllowedSessionHandler, traxController.checklistAssign )
28
+ .post( '/remove', isAllowedSessionHandler, traxController.removeAssign );
27
29
 
28
30
  // isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ),