tango-app-api-trax 3.3.1-beta-59 → 3.3.1-beta-61
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
|
@@ -1010,7 +1010,7 @@ export const assignedUserDetailsv1 = async ( req, res ) => {
|
|
|
1010
1010
|
let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) }, status: 'active' } );
|
|
1011
1011
|
storeDetails.forEach( ( item ) => {
|
|
1012
1012
|
userDetails.push( {
|
|
1013
|
-
|
|
1013
|
+
id: ele.assignId,
|
|
1014
1014
|
userName: item.spocDetails?.[0]?.name,
|
|
1015
1015
|
userEmail: item.spocDetails?.[0]?.email,
|
|
1016
1016
|
storeId: item?.storeId,
|
|
@@ -1029,7 +1029,7 @@ export const assignedUserDetailsv1 = async ( req, res ) => {
|
|
|
1029
1029
|
let teamUserDetails = await userService.find( { _id: { $in: teamDetails.users.map( ( item ) => item.userId ) } } );
|
|
1030
1030
|
teamUserDetails.forEach( ( item ) => {
|
|
1031
1031
|
userDetails.push( {
|
|
1032
|
-
|
|
1032
|
+
id: ele.assignId,
|
|
1033
1033
|
userName: item.userName,
|
|
1034
1034
|
userEmail: item.email,
|
|
1035
1035
|
storeId: ele?.storeId,
|
|
@@ -1496,7 +1496,6 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1496
1496
|
approver: inputBody?.checkListDetails?.approver.length ? inputBody?.checkListDetails?.approver.map( ( item ) => {
|
|
1497
1497
|
return { name: item.name, value: item.value };
|
|
1498
1498
|
} ) : [],
|
|
1499
|
-
storeCount: inputBody.checkListDetails?.assignedUsers?.length || 0,
|
|
1500
1499
|
};
|
|
1501
1500
|
|
|
1502
1501
|
if ( inputBody?.checkListDetails?.approver.length ) {
|
|
@@ -2006,8 +2005,8 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2006
2005
|
}
|
|
2007
2006
|
}
|
|
2008
2007
|
|
|
2009
|
-
let userEmailList = assignDetails.map( ( item ) => item
|
|
2010
|
-
let storeList = assignDetails.map( ( item ) => item?.storeName?.toLowerCase() );
|
|
2008
|
+
let userEmailList = assignDetails.map( ( item ) => item?.userEmail?.trim()?.toLowerCase() );
|
|
2009
|
+
let storeList = assignDetails.map( ( item ) => item?.storeName?.trim()?.toLowerCase() );
|
|
2011
2010
|
|
|
2012
2011
|
let userQuery = [
|
|
2013
2012
|
{
|
|
@@ -2015,6 +2014,8 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2015
2014
|
newEmail: { $toLower: '$email' },
|
|
2016
2015
|
isActive: 1,
|
|
2017
2016
|
clientId: 1,
|
|
2017
|
+
userName: 1,
|
|
2018
|
+
email: 1,
|
|
2018
2019
|
},
|
|
2019
2020
|
},
|
|
2020
2021
|
{
|
|
@@ -2032,6 +2033,7 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2032
2033
|
newEmail: { $toLower: '$email' },
|
|
2033
2034
|
isActive: 1,
|
|
2034
2035
|
clientId: 1,
|
|
2036
|
+
email: 1,
|
|
2035
2037
|
},
|
|
2036
2038
|
},
|
|
2037
2039
|
{
|
|
@@ -2046,17 +2048,19 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2046
2048
|
let storeQuery = [
|
|
2047
2049
|
{
|
|
2048
2050
|
$project: {
|
|
2049
|
-
'
|
|
2051
|
+
'store': { $toLower: '$storeName' },
|
|
2050
2052
|
'clientId': 1,
|
|
2051
2053
|
'storeProfile.city': 1,
|
|
2052
2054
|
'status': 1,
|
|
2053
2055
|
'storeId': 1,
|
|
2056
|
+
'spocDetails': 1,
|
|
2057
|
+
'storeName': 1,
|
|
2054
2058
|
},
|
|
2055
2059
|
},
|
|
2056
2060
|
{
|
|
2057
2061
|
$match: {
|
|
2058
2062
|
clientId: req.body.clientId,
|
|
2059
|
-
|
|
2063
|
+
store: { $in: storeList },
|
|
2060
2064
|
},
|
|
2061
2065
|
},
|
|
2062
2066
|
];
|
|
@@ -2073,21 +2077,27 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2073
2077
|
let newUserList = userEmailList.filter( ( ele ) => !existUserEmail.includes( ele ) && !existEmail.includes( ele ) );
|
|
2074
2078
|
let inActiveStores = storeDetails.filter( ( ele ) => ele.status == 'deactive' ).map( ( ele ) => ele.storeName );
|
|
2075
2079
|
|
|
2076
|
-
let existsStore = storeDetails.map( ( ele ) => ele
|
|
2080
|
+
let existsStore = storeDetails.map( ( ele ) => ele.storeName.toLowerCase() );
|
|
2077
2081
|
let newStoreList = storeList.filter( ( ele ) => ele != null && !existsStore.includes( ele.toLowerCase() ) );
|
|
2078
2082
|
if ( req.body.coverage == 'store' ) {
|
|
2079
2083
|
assignDetails.forEach( ( item ) => {
|
|
2080
|
-
let
|
|
2081
|
-
if (
|
|
2082
|
-
|
|
2083
|
-
item.
|
|
2084
|
+
let getStoreDetails = storeDetails.find( ( store ) => store.storeName.toLowerCase() == item.storeName.toLowerCase() );
|
|
2085
|
+
if ( getStoreDetails ) {
|
|
2086
|
+
let storeUserDetails = userDetails.find( ( ele ) => ele.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
|
|
2087
|
+
item._id = getStoreDetails._id;
|
|
2088
|
+
item.storeId = getStoreDetails.storeId;
|
|
2089
|
+
item.userName = storeUserDetails ? storeUserDetails?.userName : getStoreDetails?.spocDetails?.[0]?.name;
|
|
2090
|
+
item.storeName = getStoreDetails.storeName;
|
|
2091
|
+
item.userEmail = storeUserDetails ? storeUserDetails?.email : getStoreDetails?.spocDetails?.[0]?.email;
|
|
2084
2092
|
}
|
|
2085
2093
|
} );
|
|
2086
2094
|
} else {
|
|
2087
2095
|
assignDetails.forEach( ( item ) => {
|
|
2088
|
-
let
|
|
2089
|
-
if (
|
|
2090
|
-
item._id =
|
|
2096
|
+
let getUserDetails = userDetails.find( ( user ) => user.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
|
|
2097
|
+
if ( getUserDetails ) {
|
|
2098
|
+
item._id = getUserDetails._id;
|
|
2099
|
+
item.userName = getUserDetails.userName;
|
|
2100
|
+
item.userEmail = getUserDetails.email;
|
|
2091
2101
|
}
|
|
2092
2102
|
} );
|
|
2093
2103
|
}
|
|
@@ -2095,21 +2105,21 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2095
2105
|
if ( ( newUserList.length || newStoreList.length || existEmail.length || inActiveStores.length ) && !req.body?.addUser ) {
|
|
2096
2106
|
return res.sendError( { validate: false, user: newUserList, store: newStoreList, existEmail, inActiveStores, data: assignDetails }, 400 );
|
|
2097
2107
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2108
|
+
await Promise.all( newUserList.map( async ( ele ) => {
|
|
2109
|
+
let findUserIndex = assignDetails.findIndex( ( item ) => item?.userEmail?.toLowerCase() == ele?.toLowerCase() );
|
|
2110
|
+
if ( findUserIndex != -1 ) {
|
|
2111
|
+
let data = {
|
|
2112
|
+
userName: assignDetails[findUserIndex]?.userName,
|
|
2113
|
+
email: ele,
|
|
2114
|
+
mobileNumber: assignDetails[findUserIndex]?.mobileNumber,
|
|
2115
|
+
clientId: req.body.clientId,
|
|
2116
|
+
};
|
|
2117
|
+
let response = await createUser( data );
|
|
2118
|
+
if ( req.body.coverage == 'user' ) {
|
|
2109
2119
|
assignDetails[findUserIndex]._id = response._id;
|
|
2110
2120
|
}
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2121
|
+
}
|
|
2122
|
+
} ) );
|
|
2113
2123
|
return res.sendSuccess( { validate: true, data: assignDetails } );
|
|
2114
2124
|
} catch ( e ) {
|
|
2115
2125
|
logger.error( 'validateUser 2=>', e );
|
|
@@ -2931,7 +2941,6 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
2931
2941
|
getquestionQuery.push( {
|
|
2932
2942
|
$match: {
|
|
2933
2943
|
checkListId: new ObjectId( checklistId ),
|
|
2934
|
-
checkFlag: true,
|
|
2935
2944
|
isdeleted: false,
|
|
2936
2945
|
},
|
|
2937
2946
|
} );
|
|
@@ -2947,9 +2956,35 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
2947
2956
|
let idList = clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) );
|
|
2948
2957
|
let getStoreDetails = await storeService.find( { _id: { $in: idList }, status: 'active' } );
|
|
2949
2958
|
if ( getStoreDetails.length ) {
|
|
2959
|
+
getStoreDetails = getStoreDetails.filter( ( store ) => {
|
|
2960
|
+
let findStore = allQuestion.find( ( storeList ) => storeList.assignId.toString() == store._id.toString() );
|
|
2961
|
+
if ( findStore ) {
|
|
2962
|
+
return store?.spocDetails?.[0]?.email.toLowerCase() != findStore.userEmail.toLowerCase();
|
|
2963
|
+
} else {
|
|
2964
|
+
return true;
|
|
2965
|
+
}
|
|
2966
|
+
} );
|
|
2950
2967
|
assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
|
|
2951
|
-
let
|
|
2952
|
-
|
|
2968
|
+
let userQuery = [
|
|
2969
|
+
{
|
|
2970
|
+
$project: {
|
|
2971
|
+
newEmail: { $toLower: '$email' },
|
|
2972
|
+
isActive: 1,
|
|
2973
|
+
clientId: 1,
|
|
2974
|
+
userName: 1,
|
|
2975
|
+
email: 1,
|
|
2976
|
+
},
|
|
2977
|
+
},
|
|
2978
|
+
{
|
|
2979
|
+
$match: {
|
|
2980
|
+
newEmail: store?.spocDetails?.[0]?.email.toLowerCase(),
|
|
2981
|
+
isActive: true,
|
|
2982
|
+
clientId: store.clientId,
|
|
2983
|
+
},
|
|
2984
|
+
},
|
|
2985
|
+
];
|
|
2986
|
+
let userDetails = await userService.aggregate( userQuery );
|
|
2987
|
+
if ( !userDetails.length ) {
|
|
2953
2988
|
let data = {
|
|
2954
2989
|
clientId: store.clientId,
|
|
2955
2990
|
userName: store.spocDetails?.[0]?.name,
|
|
@@ -2957,14 +2992,15 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
2957
2992
|
email: store.spocDetails[0].email,
|
|
2958
2993
|
};
|
|
2959
2994
|
userDetails = await createUser( data );
|
|
2995
|
+
userDetails = [ userDetails ];
|
|
2960
2996
|
}
|
|
2961
2997
|
let data = {
|
|
2962
2998
|
store_id: store?.storeId,
|
|
2963
2999
|
storeName: store?.storeName,
|
|
2964
|
-
userId: userDetails
|
|
2965
|
-
userName: userDetails
|
|
2966
|
-
userEmail: userDetails
|
|
2967
|
-
userPhone: userDetails?.mobileNumber,
|
|
3000
|
+
userId: userDetails?.[0]?._id,
|
|
3001
|
+
userName: userDetails?.[0]?.userName,
|
|
3002
|
+
userEmail: userDetails?.[0]?.email,
|
|
3003
|
+
userPhone: userDetails?.[0]?.mobileNumber,
|
|
2968
3004
|
city: store?.storeProfile?.city,
|
|
2969
3005
|
country: store?.storeProfile?.country,
|
|
2970
3006
|
checkFlag: true,
|
|
@@ -2985,6 +3021,8 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
2985
3021
|
let teamDetails = await teamsServices.findteams( { _id: { $in: teamsList } } );
|
|
2986
3022
|
if ( teamDetails.length ) {
|
|
2987
3023
|
let idList = teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) );
|
|
3024
|
+
let userIdList = allQuestion.filter( ( qn ) => !qn?.teamName ).map( ( qn ) => qn.assignId.toString() );
|
|
3025
|
+
idList = idList.filter( ( id ) => !userIdList.includes( id.toString() ) );
|
|
2988
3026
|
let getUserDetails = await userService.find( { _id: { $in: idList } } );
|
|
2989
3027
|
if ( getUserDetails.length ) {
|
|
2990
3028
|
assignList = getUserDetails.map( ( user ) => {
|
|
@@ -3161,7 +3199,6 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3161
3199
|
let data = { ...getsubmitDetails[0]._doc };
|
|
3162
3200
|
await processedchecklist.updateOne( { _id: getsubmitDetails[0]._id }, data );
|
|
3163
3201
|
if ( editSubmit && getsubmitDetails[0].checklistStatus == 'submit' ) {
|
|
3164
|
-
console.log( editSubmit );
|
|
3165
3202
|
let user = {
|
|
3166
3203
|
_id: getsubmitDetails[0].userId,
|
|
3167
3204
|
clientId: getsubmitDetails[0].client_id,
|
|
@@ -3244,25 +3281,25 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3244
3281
|
}
|
|
3245
3282
|
}
|
|
3246
3283
|
} else {
|
|
3247
|
-
let unAssignedList = assignUserList.reduce( ( acc, item ) => {
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
}, {} );
|
|
3255
|
-
|
|
3256
|
-
let userList = Object.keys( unAssignedList );
|
|
3257
|
-
|
|
3258
|
-
await processedchecklist.deleteMany( { userEmail: { $nin: userList }, date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, checklistStatus: { $nin: [ 'submit' ] } } );
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
}
|
|
3265
|
-
|
|
3284
|
+
// let unAssignedList = assignUserList.reduce( ( acc, item ) => {
|
|
3285
|
+
// if ( !acc[item.userEmail] ) {
|
|
3286
|
+
// acc[item.userEmail]=[ item.store_id ];
|
|
3287
|
+
// } else {
|
|
3288
|
+
// acc[item.userEmail].push( item.store_id );
|
|
3289
|
+
// }
|
|
3290
|
+
// return acc;
|
|
3291
|
+
// }, {} );
|
|
3292
|
+
|
|
3293
|
+
// let userList = Object.keys( unAssignedList );
|
|
3294
|
+
|
|
3295
|
+
// await processedchecklist.deleteMany( { userEmail: { $nin: userList }, date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, checklistStatus: { $nin: [ 'submit' ] } } );
|
|
3296
|
+
await processedchecklist.deleteMany( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, checklistStatus: { $nin: [ 'submit' ] } } );
|
|
3297
|
+
|
|
3298
|
+
// for ( let key in assignUserList ) {
|
|
3299
|
+
// if ( assignUserList.hasOwnProperty( key ) ) {
|
|
3300
|
+
// await processedchecklist.deleteMany( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, $and: [ { userEmail: key }, { store_id: { $nin: unAssignedList[key] } } ], checklistStatus: { $nin: [ 'submit' ] } } );
|
|
3301
|
+
// }
|
|
3302
|
+
// }
|
|
3266
3303
|
|
|
3267
3304
|
Promise.all( assignUserList.map( async ( ele ) => {
|
|
3268
3305
|
await processedchecklist.updateOne( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, userEmail: ele.userEmail, store_id: ele.store_id }, ele );
|
|
@@ -3612,7 +3649,6 @@ async function assignUsers( data ) {
|
|
|
3612
3649
|
}
|
|
3613
3650
|
} else {
|
|
3614
3651
|
let teamDetails = await teamsServices.findteams( { clientId: data.clientId, _id: new mongoose.Types.ObjectId( data.id ) } );
|
|
3615
|
-
console.log( teamDetails, 'team' );
|
|
3616
3652
|
if ( teamDetails.length ) {
|
|
3617
3653
|
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3618
3654
|
let userDetails = await userService.find( { _id: userIdList } );
|
|
@@ -3730,6 +3766,7 @@ export async function updateAssign( req, res ) {
|
|
|
3730
3766
|
clientId: req.body.clientId,
|
|
3731
3767
|
};
|
|
3732
3768
|
userDetails = await createUser( userData );
|
|
3769
|
+
userDetails = [ userDetails ];
|
|
3733
3770
|
}
|
|
3734
3771
|
let data = {
|
|
3735
3772
|
...assign,
|
|
@@ -3738,7 +3775,7 @@ export async function updateAssign( req, res ) {
|
|
|
3738
3775
|
checkListId: req.body.checkListId,
|
|
3739
3776
|
coverage: req.body.coverage,
|
|
3740
3777
|
assignId: assign._id,
|
|
3741
|
-
userId: userDetails
|
|
3778
|
+
userId: userDetails?.[0]?._id,
|
|
3742
3779
|
checkListName: checklistDetails.checkListName,
|
|
3743
3780
|
};
|
|
3744
3781
|
delete data._id;
|