tango-app-api-trax 3.3.1-beta-32 → 3.3.1-beta-34

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-32",
3
+ "version": "3.3.1-beta-34",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1580,6 +1580,7 @@ export const updateConfigurev1 =async ( req, res ) => {
1580
1580
  checkListName: checklistDetails.checkListName,
1581
1581
  checklistId: checklistDetails._id,
1582
1582
  coverage: inputBody?.checkListDetails.coverage,
1583
+ insert: true,
1583
1584
  };
1584
1585
  await assignUsers( data );
1585
1586
  } ) );
@@ -3543,7 +3544,7 @@ async function assignUsers( data ) {
3543
3544
  {
3544
3545
  $match: {
3545
3546
  clientId: data.clientId,
3546
- ...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
3547
+ ...( !data?.clusterName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
3547
3548
  },
3548
3549
  },
3549
3550
  {
@@ -3555,7 +3556,7 @@ async function assignUsers( data ) {
3555
3556
  ];
3556
3557
  let clusterDetails = await clusterServices.aggregateCluster( query );
3557
3558
  if ( clusterDetails.length ) {
3558
- if ( !data.upload ) {
3559
+ if ( data.insert ) {
3559
3560
  assignedData = {
3560
3561
  checkFlag: true,
3561
3562
  checkListId: data.checklistId,
@@ -3570,10 +3571,10 @@ async function assignUsers( data ) {
3570
3571
  let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
3571
3572
  assignedData = await Promise.all( storeDetails.map( async ( store ) => {
3572
3573
  let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
3573
- if ( !userDetails ) {
3574
+ if ( !userDetails && store?.spocDetails?.length ) {
3574
3575
  let userData = {
3575
3576
  userName: store.spocDetails?.[0]?.name,
3576
- email: store.spocDetails[0].email,
3577
+ email: store.spocDetails[0]?.email,
3577
3578
  mobileNumber: store.spocDetails?.[0]?.phone,
3578
3579
  clientId: data.clientId,
3579
3580
  };
@@ -3590,7 +3591,9 @@ async function assignUsers( data ) {
3590
3591
  client_id: data.clientId,
3591
3592
  assignId: data?.id || clusterDetails?.[0]?._id,
3592
3593
  coverage: 'store',
3593
- teamName: clusterDetails?.[0]?.clusterName,
3594
+ clusterName: clusterDetails?.[0]?.clusterName,
3595
+ storeId: store.storeId,
3596
+ storeName: store.storeName,
3594
3597
  };
3595
3598
  return userData;
3596
3599
  } ) );
@@ -3606,13 +3609,13 @@ async function assignUsers( data ) {
3606
3609
  {
3607
3610
  $match: {
3608
3611
  clientId: data.clientId,
3609
- ...( !data.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
3612
+ ...( !data.storeName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
3610
3613
  },
3611
3614
  },
3612
3615
  ];
3613
3616
  let storeDetails = await storeService.aggregate( query );
3614
3617
  if ( storeDetails.length ) {
3615
- let email = data?.upload ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
3618
+ let email = !data?.insert ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
3616
3619
  let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
3617
3620
  if ( !userDetails ) {
3618
3621
  let userData = {
@@ -3652,13 +3655,13 @@ async function assignUsers( data ) {
3652
3655
  {
3653
3656
  $match: {
3654
3657
  clientId: data.clientId,
3655
- ...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
3658
+ ...( !data?.teamName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
3656
3659
  },
3657
3660
  },
3658
3661
  ];
3659
3662
  let teamDetails = await teamsServices.aggregateTeams( query );
3660
3663
  if ( teamDetails.length ) {
3661
- if ( !data.upload ) {
3664
+ if ( data.insert ) {
3662
3665
  assignedData = {
3663
3666
  checkFlag: true,
3664
3667
  checkListId: data.checklistId,
@@ -3699,7 +3702,7 @@ async function assignUsers( data ) {
3699
3702
  {
3700
3703
  $match: {
3701
3704
  clientId: data.clientId,
3702
- ...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
3705
+ ...( !data?.userEmail ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
3703
3706
  },
3704
3707
  },
3705
3708
  ];
@@ -3729,7 +3732,9 @@ async function assignUsers( data ) {
3729
3732
  }
3730
3733
  }
3731
3734
  }
3732
- if ( assignedData && !data.upload ) {
3735
+
3736
+ console.log( assignedData, 'test', data );
3737
+ if ( assignedData && !data.upload && data.insert ) {
3733
3738
  await assignedService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
3734
3739
  } else {
3735
3740
  return assignedData;
@@ -3752,72 +3757,31 @@ export async function checklistAssign( req, res ) {
3752
3757
  if ( !checklistDetails ) {
3753
3758
  return res.sendError( 'No data found', 204 );
3754
3759
  }
3755
- let idList;
3756
- let assignList;
3757
- if ( req.body.coverage == 'store' ) {
3758
- let clusterDetails = await clusterServices.findcluster( { _id: { $in: req.body.idList } }, { stores: 1, clusterName: 1 } );
3759
- if ( clusterDetails.length ) {
3760
- let clusterList = clusterDetails.map( ( item ) => item._id.toString() );
3761
- idList = [
3762
- ...clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) ),
3763
- ...req.body.idList.filter( ( ele ) => !clusterList.includes( ele._id ) ),
3764
- ];
3765
- } else {
3766
- idList = req.body.idList;
3767
- }
3768
- let getStoreDetails = await storeService.find( { _id: { $in: idList }, status: 'active' } );
3769
- if ( !getStoreDetails.length ) {
3770
- return res.sendError( 'No data found', 204 );
3771
- }
3772
- assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
3773
- let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
3774
- if ( !userDetails ) {
3775
- let data = {
3776
- clientId: store.clientId,
3777
- userName: store.spocDetails?.[0]?.name,
3778
- mobileNumber: store.spocDetails?.[0]?.phone || '',
3779
- email: store.spocDetails[0].email,
3780
- };
3781
- userDetails = await createUser( data );
3760
+
3761
+ let userData = [];
3762
+
3763
+ await Promise.all( req.body.idList.map( async ( data ) => {
3764
+ let assignedData = {
3765
+ ...data,
3766
+ clientId: req.body.clientId,
3767
+ checkListName: checklistDetails.checkListName,
3768
+ checklistId: checklistDetails._id,
3769
+ coverage: req.body.coverage,
3770
+ insert: false,
3771
+ };
3772
+ console.log( assignedData, 'daterthj' );
3773
+ let uploadData = await assignUsers( assignedData );
3774
+ if ( uploadData ) {
3775
+ if ( Array.isArray( uploadData ) ) {
3776
+ userData.push( ...uploadData );
3777
+ } else {
3778
+ userData.push( uploadData );
3782
3779
  }
3783
- let data = {
3784
- store_id: store.storeId,
3785
- storeName: store.storeName,
3786
- userId: userDetails._id,
3787
- userName: userDetails.userName,
3788
- userEmail: userDetails.email,
3789
- userPhone: userDetails?.mobileNumber,
3790
- clusterName: clusterDetails?.clusterName,
3791
- };
3792
- return data;
3793
- } ) );
3794
- } else {
3795
- let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
3796
- if ( teamDetails.length ) {
3797
- let teamList = teamDetails.map( ( item ) => item._id.toString() );
3798
- idList = [
3799
- ...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
3800
- ...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
3801
- ];
3802
- } else {
3803
- idList = req.body.idList;
3804
3780
  }
3805
- let userDetails = await userService.find( { _id: { $in: idList } } );
3806
- if ( !userDetails.length ) {
3807
- return res.sendError( 'No data found', 204 );
3808
- }
3809
- assignList = [];
3810
- userDetails.forEach( ( user ) => {
3811
- assignList.push( {
3812
- userId: user._id,
3813
- userName: user.userName,
3814
- userEmail: user.email,
3815
- userPhone: user?.mobileNumber,
3816
- teamName: teamDetails?.teamName,
3817
- } );
3818
- } );
3819
- }
3820
- return res.sendSuccess( { count: assignList.length, assignList } );
3781
+ } ) );
3782
+
3783
+
3784
+ return res.sendSuccess( { count: userData.length, userData } );
3821
3785
  } catch ( e ) {
3822
3786
  logger.error( { functionName: 'checklistAssign', error: e } );
3823
3787
  return res.sendError( e, 500 );