tango-app-api-trax 3.3.1-beta-32 → 3.3.1-beta-33
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
|
@@ -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?.
|
|
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 (
|
|
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]
|
|
3577
|
+
email: store.spocDetails[0]?.email,
|
|
3577
3578
|
mobileNumber: store.spocDetails?.[0]?.phone,
|
|
3578
3579
|
clientId: data.clientId,
|
|
3579
3580
|
};
|
|
@@ -3590,7 +3591,7 @@ async function assignUsers( data ) {
|
|
|
3590
3591
|
client_id: data.clientId,
|
|
3591
3592
|
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3592
3593
|
coverage: 'store',
|
|
3593
|
-
|
|
3594
|
+
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3594
3595
|
};
|
|
3595
3596
|
return userData;
|
|
3596
3597
|
} ) );
|
|
@@ -3606,13 +3607,13 @@ async function assignUsers( data ) {
|
|
|
3606
3607
|
{
|
|
3607
3608
|
$match: {
|
|
3608
3609
|
clientId: data.clientId,
|
|
3609
|
-
...( !data.
|
|
3610
|
+
...( !data.storeName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
|
|
3610
3611
|
},
|
|
3611
3612
|
},
|
|
3612
3613
|
];
|
|
3613
3614
|
let storeDetails = await storeService.aggregate( query );
|
|
3614
3615
|
if ( storeDetails.length ) {
|
|
3615
|
-
let email = data?.
|
|
3616
|
+
let email = !data?.insert ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
|
|
3616
3617
|
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3617
3618
|
if ( !userDetails ) {
|
|
3618
3619
|
let userData = {
|
|
@@ -3652,13 +3653,13 @@ async function assignUsers( data ) {
|
|
|
3652
3653
|
{
|
|
3653
3654
|
$match: {
|
|
3654
3655
|
clientId: data.clientId,
|
|
3655
|
-
...( !data?.
|
|
3656
|
+
...( !data?.teamName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
|
|
3656
3657
|
},
|
|
3657
3658
|
},
|
|
3658
3659
|
];
|
|
3659
3660
|
let teamDetails = await teamsServices.aggregateTeams( query );
|
|
3660
3661
|
if ( teamDetails.length ) {
|
|
3661
|
-
if (
|
|
3662
|
+
if ( data.insert ) {
|
|
3662
3663
|
assignedData = {
|
|
3663
3664
|
checkFlag: true,
|
|
3664
3665
|
checkListId: data.checklistId,
|
|
@@ -3699,7 +3700,7 @@ async function assignUsers( data ) {
|
|
|
3699
3700
|
{
|
|
3700
3701
|
$match: {
|
|
3701
3702
|
clientId: data.clientId,
|
|
3702
|
-
...( !data?.
|
|
3703
|
+
...( !data?.userEmail ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
|
|
3703
3704
|
},
|
|
3704
3705
|
},
|
|
3705
3706
|
];
|
|
@@ -3729,7 +3730,9 @@ async function assignUsers( data ) {
|
|
|
3729
3730
|
}
|
|
3730
3731
|
}
|
|
3731
3732
|
}
|
|
3732
|
-
|
|
3733
|
+
|
|
3734
|
+
console.log( assignedData, 'test', data );
|
|
3735
|
+
if ( assignedData && !data.upload && data.insert ) {
|
|
3733
3736
|
await assignedService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
|
|
3734
3737
|
} else {
|
|
3735
3738
|
return assignedData;
|
|
@@ -3752,72 +3755,31 @@ export async function checklistAssign( req, res ) {
|
|
|
3752
3755
|
if ( !checklistDetails ) {
|
|
3753
3756
|
return res.sendError( 'No data found', 204 );
|
|
3754
3757
|
}
|
|
3755
|
-
|
|
3756
|
-
let
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
let
|
|
3769
|
-
if (
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
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 );
|
|
3758
|
+
|
|
3759
|
+
let userData = [];
|
|
3760
|
+
|
|
3761
|
+
await Promise.all( req.body.idList.map( async ( data ) => {
|
|
3762
|
+
let assignedData = {
|
|
3763
|
+
...data,
|
|
3764
|
+
clientId: req.body.clientId,
|
|
3765
|
+
checkListName: checklistDetails.checkListName,
|
|
3766
|
+
checklistId: checklistDetails._id,
|
|
3767
|
+
coverage: req.body.coverage,
|
|
3768
|
+
insert: false,
|
|
3769
|
+
};
|
|
3770
|
+
console.log( assignedData, 'daterthj' );
|
|
3771
|
+
let uploadData = await assignUsers( assignedData );
|
|
3772
|
+
if ( uploadData ) {
|
|
3773
|
+
if ( Array.isArray( uploadData ) ) {
|
|
3774
|
+
userData.push( ...uploadData );
|
|
3775
|
+
} else {
|
|
3776
|
+
userData.push( uploadData );
|
|
3782
3777
|
}
|
|
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
3778
|
}
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
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 } );
|
|
3779
|
+
} ) );
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
return res.sendSuccess( { count: userData.length, userData } );
|
|
3821
3783
|
} catch ( e ) {
|
|
3822
3784
|
logger.error( { functionName: 'checklistAssign', error: e } );
|
|
3823
3785
|
return res.sendError( e, 500 );
|