tango-app-api-trax 3.3.1-beta-30 → 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 +1 -1
- package/src/controllers/trax.controller.js +48 -84
- package/src/hbs/login-otp.hbs +943 -943
package/package.json
CHANGED
|
@@ -895,7 +895,7 @@ export const assignedUserDetails = async ( req, res ) => {
|
|
|
895
895
|
if ( ele?.clusterName ) {
|
|
896
896
|
let clusterDetails = await clusterServices.findOneCluster( { _id: ele.assignId }, { stores: 1 } );
|
|
897
897
|
if ( clusterDetails ) {
|
|
898
|
-
let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) } } );
|
|
898
|
+
let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) }, status: 'active' } );
|
|
899
899
|
storeDetails.forEach( ( item ) => {
|
|
900
900
|
userDetails.push( {
|
|
901
901
|
id: ele._id,
|
|
@@ -1004,7 +1004,7 @@ export const assignedUserDetailsv1 = async ( req, res ) => {
|
|
|
1004
1004
|
if ( ele?.clusterName ) {
|
|
1005
1005
|
let clusterDetails = await clusterServices.findOneCluster( { _id: ele.assignId }, { stores: 1 } );
|
|
1006
1006
|
if ( clusterDetails ) {
|
|
1007
|
-
let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) } } );
|
|
1007
|
+
let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) }, status: 'active' } );
|
|
1008
1008
|
storeDetails.forEach( ( item ) => {
|
|
1009
1009
|
userDetails.push( {
|
|
1010
1010
|
id: ele._id,
|
|
@@ -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
|
} ) );
|
|
@@ -2094,13 +2095,15 @@ export async function assignChecklistUser( req, res ) {
|
|
|
2094
2095
|
assign.clientId = inputBody.clientId;
|
|
2095
2096
|
assign.upload = inputBody.type;
|
|
2096
2097
|
let uploadData = await assignUsers( assign );
|
|
2097
|
-
if (
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2098
|
+
if ( uploadData ) {
|
|
2099
|
+
if ( Array.isArray( uploadData ) ) {
|
|
2100
|
+
assignData.push( ...uploadData );
|
|
2101
|
+
} else {
|
|
2102
|
+
assignData.push( uploadData );
|
|
2103
|
+
}
|
|
2101
2104
|
}
|
|
2102
2105
|
} ) );
|
|
2103
|
-
return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => item
|
|
2106
|
+
return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => item?.assignId?.toString() ) ) ], assignData } );
|
|
2104
2107
|
} catch ( e ) {
|
|
2105
2108
|
logger.error( { functionName: 'assignUser', error: e } );
|
|
2106
2109
|
return res.sendError( e, 500 );
|
|
@@ -2891,7 +2894,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
2891
2894
|
let clusterDetails = await clusterServices.findcluster( { _id: { $in: clusterList } } );
|
|
2892
2895
|
if ( clusterDetails.length ) {
|
|
2893
2896
|
let idList = clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) );
|
|
2894
|
-
let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
|
|
2897
|
+
let getStoreDetails = await storeService.find( { _id: { $in: idList }, status: 'active' } );
|
|
2895
2898
|
if ( getStoreDetails.length ) {
|
|
2896
2899
|
assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
|
|
2897
2900
|
let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
|
|
@@ -3541,7 +3544,7 @@ async function assignUsers( data ) {
|
|
|
3541
3544
|
{
|
|
3542
3545
|
$match: {
|
|
3543
3546
|
clientId: data.clientId,
|
|
3544
|
-
...( !data?.
|
|
3547
|
+
...( !data?.clusterName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
|
|
3545
3548
|
},
|
|
3546
3549
|
},
|
|
3547
3550
|
{
|
|
@@ -3553,7 +3556,7 @@ async function assignUsers( data ) {
|
|
|
3553
3556
|
];
|
|
3554
3557
|
let clusterDetails = await clusterServices.aggregateCluster( query );
|
|
3555
3558
|
if ( clusterDetails.length ) {
|
|
3556
|
-
if (
|
|
3559
|
+
if ( data.insert ) {
|
|
3557
3560
|
assignedData = {
|
|
3558
3561
|
checkFlag: true,
|
|
3559
3562
|
checkListId: data.checklistId,
|
|
@@ -3565,13 +3568,13 @@ async function assignUsers( data ) {
|
|
|
3565
3568
|
};
|
|
3566
3569
|
} else {
|
|
3567
3570
|
let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
|
|
3568
|
-
let storeDetails = await storeService.find( { _id: clusterList } );
|
|
3571
|
+
let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
|
|
3569
3572
|
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3570
3573
|
let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
|
|
3571
|
-
if ( !userDetails ) {
|
|
3574
|
+
if ( !userDetails && store?.spocDetails?.length ) {
|
|
3572
3575
|
let userData = {
|
|
3573
3576
|
userName: store.spocDetails?.[0]?.name,
|
|
3574
|
-
email: store.spocDetails[0]
|
|
3577
|
+
email: store.spocDetails[0]?.email,
|
|
3575
3578
|
mobileNumber: store.spocDetails?.[0]?.phone,
|
|
3576
3579
|
clientId: data.clientId,
|
|
3577
3580
|
};
|
|
@@ -3588,7 +3591,7 @@ async function assignUsers( data ) {
|
|
|
3588
3591
|
client_id: data.clientId,
|
|
3589
3592
|
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3590
3593
|
coverage: 'store',
|
|
3591
|
-
|
|
3594
|
+
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3592
3595
|
};
|
|
3593
3596
|
return userData;
|
|
3594
3597
|
} ) );
|
|
@@ -3604,13 +3607,13 @@ async function assignUsers( data ) {
|
|
|
3604
3607
|
{
|
|
3605
3608
|
$match: {
|
|
3606
3609
|
clientId: data.clientId,
|
|
3607
|
-
...( !data.
|
|
3610
|
+
...( !data.storeName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
|
|
3608
3611
|
},
|
|
3609
3612
|
},
|
|
3610
3613
|
];
|
|
3611
3614
|
let storeDetails = await storeService.aggregate( query );
|
|
3612
3615
|
if ( storeDetails.length ) {
|
|
3613
|
-
let email = data?.
|
|
3616
|
+
let email = !data?.insert ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
|
|
3614
3617
|
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3615
3618
|
if ( !userDetails ) {
|
|
3616
3619
|
let userData = {
|
|
@@ -3650,13 +3653,13 @@ async function assignUsers( data ) {
|
|
|
3650
3653
|
{
|
|
3651
3654
|
$match: {
|
|
3652
3655
|
clientId: data.clientId,
|
|
3653
|
-
...( !data?.
|
|
3656
|
+
...( !data?.teamName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
|
|
3654
3657
|
},
|
|
3655
3658
|
},
|
|
3656
3659
|
];
|
|
3657
3660
|
let teamDetails = await teamsServices.aggregateTeams( query );
|
|
3658
3661
|
if ( teamDetails.length ) {
|
|
3659
|
-
if (
|
|
3662
|
+
if ( data.insert ) {
|
|
3660
3663
|
assignedData = {
|
|
3661
3664
|
checkFlag: true,
|
|
3662
3665
|
checkListId: data.checklistId,
|
|
@@ -3697,7 +3700,7 @@ async function assignUsers( data ) {
|
|
|
3697
3700
|
{
|
|
3698
3701
|
$match: {
|
|
3699
3702
|
clientId: data.clientId,
|
|
3700
|
-
...( !data?.
|
|
3703
|
+
...( !data?.userEmail ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
|
|
3701
3704
|
},
|
|
3702
3705
|
},
|
|
3703
3706
|
];
|
|
@@ -3727,7 +3730,9 @@ async function assignUsers( data ) {
|
|
|
3727
3730
|
}
|
|
3728
3731
|
}
|
|
3729
3732
|
}
|
|
3730
|
-
|
|
3733
|
+
|
|
3734
|
+
console.log( assignedData, 'test', data );
|
|
3735
|
+
if ( assignedData && !data.upload && data.insert ) {
|
|
3731
3736
|
await assignedService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
|
|
3732
3737
|
} else {
|
|
3733
3738
|
return assignedData;
|
|
@@ -3750,72 +3755,31 @@ export async function checklistAssign( req, res ) {
|
|
|
3750
3755
|
if ( !checklistDetails ) {
|
|
3751
3756
|
return res.sendError( 'No data found', 204 );
|
|
3752
3757
|
}
|
|
3753
|
-
|
|
3754
|
-
let
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
let
|
|
3767
|
-
if (
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
if ( !userDetails ) {
|
|
3773
|
-
let data = {
|
|
3774
|
-
clientId: store.clientId,
|
|
3775
|
-
userName: store.spocDetails?.[0]?.name,
|
|
3776
|
-
mobileNumber: store.spocDetails?.[0]?.phone || '',
|
|
3777
|
-
email: store.spocDetails[0].email,
|
|
3778
|
-
};
|
|
3779
|
-
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 );
|
|
3780
3777
|
}
|
|
3781
|
-
let data = {
|
|
3782
|
-
store_id: store.storeId,
|
|
3783
|
-
storeName: store.storeName,
|
|
3784
|
-
userId: userDetails._id,
|
|
3785
|
-
userName: userDetails.userName,
|
|
3786
|
-
userEmail: userDetails.email,
|
|
3787
|
-
userPhone: userDetails?.mobileNumber,
|
|
3788
|
-
clusterName: clusterDetails?.clusterName,
|
|
3789
|
-
};
|
|
3790
|
-
return data;
|
|
3791
|
-
} ) );
|
|
3792
|
-
} else {
|
|
3793
|
-
let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
|
|
3794
|
-
if ( teamDetails.length ) {
|
|
3795
|
-
let teamList = teamDetails.map( ( item ) => item._id.toString() );
|
|
3796
|
-
idList = [
|
|
3797
|
-
...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
|
|
3798
|
-
...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
|
|
3799
|
-
];
|
|
3800
|
-
} else {
|
|
3801
|
-
idList = req.body.idList;
|
|
3802
3778
|
}
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
assignList = [];
|
|
3808
|
-
userDetails.forEach( ( user ) => {
|
|
3809
|
-
assignList.push( {
|
|
3810
|
-
userId: user._id,
|
|
3811
|
-
userName: user.userName,
|
|
3812
|
-
userEmail: user.email,
|
|
3813
|
-
userPhone: user?.mobileNumber,
|
|
3814
|
-
teamName: teamDetails?.teamName,
|
|
3815
|
-
} );
|
|
3816
|
-
} );
|
|
3817
|
-
}
|
|
3818
|
-
return res.sendSuccess( { count: assignList.length, assignList } );
|
|
3779
|
+
} ) );
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
return res.sendSuccess( { count: userData.length, userData } );
|
|
3819
3783
|
} catch ( e ) {
|
|
3820
3784
|
logger.error( { functionName: 'checklistAssign', error: e } );
|
|
3821
3785
|
return res.sendError( e, 500 );
|