tango-app-api-trax 3.3.1-beta-70 → 3.3.1-beta-72
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
|
@@ -463,7 +463,7 @@ async function insertData( requestData ) {
|
|
|
463
463
|
if ( teamsList.length ) {
|
|
464
464
|
let teamDetails = await teamsServices.findteams( { _id: { $in: teamsList } } );
|
|
465
465
|
if ( teamDetails.length ) {
|
|
466
|
-
let idList = teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) );
|
|
466
|
+
let idList = [ ...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ), ...teamDetails.flatMap( ( item ) => item.Teamlead.map( ( ele ) => ele.userId ) ) ];
|
|
467
467
|
let getUserDetails = await userService.find( { _id: { $in: idList } } );
|
|
468
468
|
if ( getUserDetails.length ) {
|
|
469
469
|
assignList = getUserDetails.map( ( user ) => {
|
|
@@ -3179,7 +3179,7 @@ export async function login( req, res ) {
|
|
|
3179
3179
|
return res.sendError( `User mail not Exists`, 401 );
|
|
3180
3180
|
}
|
|
3181
3181
|
if ( !result.isActive ) {
|
|
3182
|
-
return res.sendError( '
|
|
3182
|
+
return res.sendError( 'Your account is currently inactive. Please contact your admin.', 401 );
|
|
3183
3183
|
}
|
|
3184
3184
|
if ( inputData.otp ) {
|
|
3185
3185
|
const otpMatching = await findOTP( { email: result.email, type: 'login', otp: inputData.otp } );
|
|
@@ -28,7 +28,7 @@ export const overallFlagMetrics = async ( req, res ) => {
|
|
|
28
28
|
{ date_iso: { $gte: new Date( req.body.startDate ) } },
|
|
29
29
|
{ date_iso: { $lte: new Date( req.body.endDate ) } },
|
|
30
30
|
// { store_id: { $in: req.body.stores } },
|
|
31
|
-
{ $or: [ { store_id: { $in:
|
|
31
|
+
{ $or: [ { store_id: { $in: req.body.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ] },
|
|
32
32
|
],
|
|
33
33
|
},
|
|
34
34
|
},
|
|
@@ -105,10 +105,7 @@ export const overallFlagMetrics = async ( req, res ) => {
|
|
|
105
105
|
{ date_iso: { $gte: dayjs.utc( req.body.endDate ).subtract( 7, 'days' ).startOf( 'day' ).toDate() } },
|
|
106
106
|
{ date_iso: { $lte: dayjs.utc( req.body.startDate ).subtract( 1, 'day' ).startOf( 'day' ).toDate() } },
|
|
107
107
|
// { store_id: { $in: req.body.stores } },
|
|
108
|
-
{
|
|
109
|
-
{ '$and': findORQuery1 },
|
|
110
|
-
{ '$and': findORQuery2 },
|
|
111
|
-
] },
|
|
108
|
+
{ $or: [ { store_id: { $in: req.body.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ] },
|
|
112
109
|
],
|
|
113
110
|
},
|
|
114
111
|
},
|
|
@@ -1973,10 +1970,7 @@ export const flagChecklistCardsV1 = async ( req, res ) => {
|
|
|
1973
1970
|
client_id: reqestData.clientId,
|
|
1974
1971
|
sourceCheckList_id: new mongoose.Types.ObjectId( reqestData.sourceCheckList_id ),
|
|
1975
1972
|
// store_id: { $in: reqestData.storeId },
|
|
1976
|
-
$or: [
|
|
1977
|
-
{ '$and': findORQuery1 },
|
|
1978
|
-
{ '$and': findORQuery2 },
|
|
1979
|
-
],
|
|
1973
|
+
$or: [ { store_id: { $in: reqestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ],
|
|
1980
1974
|
},
|
|
1981
1975
|
},
|
|
1982
1976
|
{
|
|
@@ -1024,9 +1024,10 @@ export const assignedUserDetailsv1 = async ( req, res ) => {
|
|
|
1024
1024
|
} );
|
|
1025
1025
|
}
|
|
1026
1026
|
} else if ( ele?.teamName ) {
|
|
1027
|
-
let teamDetails = await teamsServices.findOneTeams( { _id: ele.assignId }, { users: 1, teamName: 1 } );
|
|
1027
|
+
let teamDetails = await teamsServices.findOneTeams( { _id: ele.assignId }, { users: 1, teamName: 1, Teamlead: 1 } );
|
|
1028
1028
|
if ( teamDetails ) {
|
|
1029
|
-
let
|
|
1029
|
+
let idList = [ ...teamDetails.users.map( ( ele ) => ele.userId ), ...teamDetails.Teamlead.map( ( ele ) => ele.userId ) ];
|
|
1030
|
+
let teamUserDetails = await userService.find( { _id: { $in: idList }, isActive: true } );
|
|
1030
1031
|
teamUserDetails.forEach( ( item ) => {
|
|
1031
1032
|
userDetails.push( {
|
|
1032
1033
|
id: ele.assignId,
|
|
@@ -1043,18 +1044,24 @@ export const assignedUserDetailsv1 = async ( req, res ) => {
|
|
|
1043
1044
|
} );
|
|
1044
1045
|
}
|
|
1045
1046
|
} else {
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1047
|
+
let checkActiveUsers;
|
|
1048
|
+
if ( ele?.coverage == 'user' ) {
|
|
1049
|
+
checkActiveUsers = await userService.findOne( { _id: ele.userId, isActive: true } );
|
|
1050
|
+
}
|
|
1051
|
+
if ( checkActiveUsers || ele?.coverage == 'store' ) {
|
|
1052
|
+
userDetails.push( {
|
|
1053
|
+
_id: ele.assignId,
|
|
1054
|
+
userName: ele.userName,
|
|
1055
|
+
userEmail: ele.userEmail,
|
|
1056
|
+
storeId: ele?.store_id,
|
|
1057
|
+
storeName: ele?.storeName,
|
|
1058
|
+
userPhone: ele.userPhone,
|
|
1059
|
+
city: ele.city,
|
|
1060
|
+
checkFlag: ele.checkFlag,
|
|
1061
|
+
clusterName: ele?.clusterName || '',
|
|
1062
|
+
teamName: ele?.teamName || '',
|
|
1063
|
+
} );
|
|
1064
|
+
}
|
|
1058
1065
|
}
|
|
1059
1066
|
} ) );
|
|
1060
1067
|
|
|
@@ -1944,7 +1951,7 @@ export const validateUser = async ( req, res ) => {
|
|
|
1944
1951
|
|
|
1945
1952
|
export const validateUserv1 = async ( req, res ) => {
|
|
1946
1953
|
try {
|
|
1947
|
-
if ( !req.body.assignedUsers
|
|
1954
|
+
if ( !req.body.assignedUsers?.length ) {
|
|
1948
1955
|
return res.sendError( 'Please Enter user Details', 400 );
|
|
1949
1956
|
}
|
|
1950
1957
|
|
|
@@ -1982,17 +1989,15 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
1982
1989
|
};
|
|
1983
1990
|
} else {
|
|
1984
1991
|
if ( acc[obj.userEmail.toLowerCase()] ) {
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
} else {
|
|
1988
|
-
acc[obj.userEmail.toLowerCase()].name.push( obj.userEmail.toLowerCase() );
|
|
1989
|
-
}
|
|
1992
|
+
acc[obj.userEmail.toLowerCase()].name.push( obj.userName.toLowerCase() );
|
|
1993
|
+
acc[obj.userEmail.toLowerCase()].count++;
|
|
1990
1994
|
}
|
|
1991
1995
|
}
|
|
1992
1996
|
return acc;
|
|
1993
1997
|
}, {} );
|
|
1994
1998
|
|
|
1995
1999
|
const duplicateUsers = Object.keys( duplicateUser ).filter( ( storeName ) => duplicateUser[storeName].count > 1 );
|
|
2000
|
+
console.log( duplicateUsers, 'user' );
|
|
1996
2001
|
if ( duplicateUsers.length ) {
|
|
1997
2002
|
return res.sendError( { validate: false, duplicates: duplicateUsers, message: 'Email is Duplicated' }, 400 );
|
|
1998
2003
|
}
|
|
@@ -3053,74 +3058,90 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3053
3058
|
let notifyUserList = [];
|
|
3054
3059
|
let status = [ { checklistStatus: { $ne: 'open' } } ];
|
|
3055
3060
|
let assignUserList = [];
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3061
|
+
let userList = allQuestion.map( ( item ) => item.userId );
|
|
3062
|
+
let submittedDetails = [];
|
|
3063
|
+
let userDetails = await userService.find( { _id: { $in: userList } }, { fcmToken: 1 } );
|
|
3064
|
+
userDetails = new Map( userDetails.map( ( ele ) => [ ele._id.toString(), ele.fcmToken ] ) );
|
|
3065
|
+
if ( !getCLconfig?.allowedMultiSubmit ) {
|
|
3066
|
+
let query;
|
|
3067
|
+
if ( getCLconfig.allowOnce && ![ 'onetime', 'daily' ].includes( getCLconfig.schedule ) ) {
|
|
3068
|
+
if ( [ 'weekday', 'weekly', 'monthly' ].includes( getCLconfig.schedule ) ) {
|
|
3069
|
+
let startDate; let endDate;
|
|
3070
|
+
if ( [ 'weekday', 'weekly' ].includes( getCLconfig.schedule ) ) {
|
|
3071
|
+
startDate = dayjs.utc( date ).clone().startOf( 'week' );
|
|
3072
|
+
endDate = dayjs.utc( date ).clone().endOf( 'week' );
|
|
3073
|
+
} else {
|
|
3074
|
+
startDate = dayjs.utc( date ).clone().startOf( 'month' );
|
|
3075
|
+
endDate = dayjs.utc( date ).clone().endOf( 'month' );
|
|
3076
|
+
}
|
|
3077
|
+
query = {
|
|
3078
|
+
sourceCheckList_id: getCLconfig._id,
|
|
3079
|
+
$or: [
|
|
3080
|
+
{ submitTime: { $exists: true } },
|
|
3081
|
+
...status,
|
|
3082
|
+
],
|
|
3083
|
+
// userId: { $in: userList },
|
|
3084
|
+
// ...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3085
|
+
$and: [ {
|
|
3086
|
+
date_iso: {
|
|
3087
|
+
$gte: new Date( startDate.format( 'YYYY-MM-DD' ) ),
|
|
3088
|
+
$lte: new Date( endDate.format( 'YYYY-MM-DD' ) ) },
|
|
3089
|
+
} ],
|
|
3090
|
+
};
|
|
3091
|
+
} else {
|
|
3092
|
+
if ( getCLconfig.schedule == 'range' ) {
|
|
3076
3093
|
query = {
|
|
3077
3094
|
sourceCheckList_id: getCLconfig._id,
|
|
3078
3095
|
$or: [
|
|
3079
3096
|
{ submitTime: { $exists: true } },
|
|
3080
3097
|
...status,
|
|
3081
3098
|
],
|
|
3082
|
-
userId: element4.userId,
|
|
3083
|
-
...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3084
|
-
$and: [
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
};
|
|
3090
|
-
} else {
|
|
3091
|
-
if ( getCLconfig.schedule == 'range' ) {
|
|
3092
|
-
query = {
|
|
3093
|
-
sourceCheckList_id: getCLconfig._id,
|
|
3094
|
-
$or: [
|
|
3095
|
-
{ submitTime: { $exists: true } },
|
|
3096
|
-
...status,
|
|
3097
|
-
],
|
|
3098
|
-
userId: element4.userId,
|
|
3099
|
-
...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3100
|
-
$and: [
|
|
3101
|
-
{
|
|
3102
|
-
date_iso: {
|
|
3103
|
-
$gte: new Date( dayjs( getCLconfig.configStartDate ).format( 'YYYY-MM-DD' ) ),
|
|
3104
|
-
$lte: new Date( dayjs( getCLconfig.configEndDate ).format( 'YYYY-MM-DD' ) ),
|
|
3105
|
-
},
|
|
3099
|
+
// userId: element4.userId,
|
|
3100
|
+
// ...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3101
|
+
$and: [
|
|
3102
|
+
{
|
|
3103
|
+
date_iso: {
|
|
3104
|
+
$gte: new Date( dayjs( getCLconfig.configStartDate ).format( 'YYYY-MM-DD' ) ),
|
|
3105
|
+
$lte: new Date( dayjs( getCLconfig.configEndDate ).format( 'YYYY-MM-DD' ) ),
|
|
3106
3106
|
},
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
}
|
|
3107
|
+
},
|
|
3108
|
+
],
|
|
3109
|
+
};
|
|
3110
3110
|
}
|
|
3111
|
+
}
|
|
3112
|
+
} else {
|
|
3113
|
+
query = {
|
|
3114
|
+
date_string: date,
|
|
3115
|
+
sourceCheckList_id: getCLconfig._id,
|
|
3116
|
+
$or: [
|
|
3117
|
+
...status,
|
|
3118
|
+
{ submitTime: { $exists: true } },
|
|
3119
|
+
],
|
|
3120
|
+
// userId: element4.userId,
|
|
3121
|
+
// ...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3122
|
+
};
|
|
3123
|
+
}
|
|
3124
|
+
submittedDetails = await processedchecklist.find( query );
|
|
3125
|
+
}
|
|
3126
|
+
await Promise.all( allQuestion.map( async ( element4 ) => {
|
|
3127
|
+
let getToken = userDetails.get( element4.userId.toString() );
|
|
3128
|
+
if ( getToken && element4?.sendNotification && showEdit ) {
|
|
3129
|
+
tokenList.push( getToken );
|
|
3130
|
+
}
|
|
3131
|
+
if ( !element4?.sendNotification ) {
|
|
3132
|
+
notifyUserList.push( { token: getToken, storeName: element4.storeName, id: element4._id } );
|
|
3133
|
+
}
|
|
3134
|
+
if ( !getCLconfig?.allowedMultiSubmit ) {
|
|
3135
|
+
let getsubmitDetails;
|
|
3136
|
+
if ( getCLconfig.coverage == 'store' ) {
|
|
3137
|
+
getsubmitDetails = submittedDetails.find( ( checklist ) => checklist.userId.toString() == element4.userId.toString() && checklist.store_id == element4.store_id );
|
|
3111
3138
|
} else {
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
{ submitTime: { $exists: true } },
|
|
3118
|
-
],
|
|
3119
|
-
userId: element4.userId,
|
|
3120
|
-
...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3121
|
-
};
|
|
3139
|
+
getsubmitDetails = submittedDetails.find( ( checklist ) => checklist.userId.toString() == element4.userId.toString() );
|
|
3140
|
+
}
|
|
3141
|
+
if ( getsubmitDetails ) {
|
|
3142
|
+
getsubmitDetails = [ getsubmitDetails ];
|
|
3143
|
+
console.log( submittedDetails, getsubmitDetails );
|
|
3122
3144
|
}
|
|
3123
|
-
let getsubmitDetails = await processedchecklist.find( query );
|
|
3124
3145
|
function findDifferences( obj1, obj2 ) {
|
|
3125
3146
|
return Object.keys( obj1 ).reduce( ( diff, key ) => {
|
|
3126
3147
|
if ( !isEqual( obj1[key], obj2[key] ) ) {
|
|
@@ -3129,7 +3150,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3129
3150
|
return diff;
|
|
3130
3151
|
}, {} );
|
|
3131
3152
|
}
|
|
3132
|
-
if ( getsubmitDetails
|
|
3153
|
+
if ( getsubmitDetails?.length ) {
|
|
3133
3154
|
if ( showEdit && ( ( editSubmit && getsubmitDetails[0].checklistStatus == 'submit' ) || getsubmitDetails[0].checklistStatus == 'inprogress' ) ) {
|
|
3134
3155
|
let modifiedCount = 0;
|
|
3135
3156
|
let questionList = insertdata.questionAnswers;
|
|
@@ -3282,29 +3303,47 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3282
3303
|
}
|
|
3283
3304
|
}
|
|
3284
3305
|
} else {
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
// let userList = Object.keys( unAssignedList );
|
|
3295
|
-
|
|
3296
|
-
// 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' ] } } );
|
|
3297
|
-
await processedchecklist.deleteMany( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, checklistStatus: { $nin: [ 'submit' ] } } );
|
|
3298
|
-
|
|
3299
|
-
// for ( let key in assignUserList ) {
|
|
3300
|
-
// if ( assignUserList.hasOwnProperty( key ) ) {
|
|
3301
|
-
// 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' ] } } );
|
|
3302
|
-
// }
|
|
3303
|
-
// }
|
|
3306
|
+
let unAssignedList = assignUserList.reduce( ( acc, item ) => {
|
|
3307
|
+
if ( !acc[item.userEmail] ) {
|
|
3308
|
+
acc[item.userEmail]=[ item.store_id ];
|
|
3309
|
+
} else {
|
|
3310
|
+
acc[item.userEmail].push( item.store_id );
|
|
3311
|
+
}
|
|
3312
|
+
return acc;
|
|
3313
|
+
}, {} );
|
|
3304
3314
|
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
}
|
|
3315
|
+
let userList = Object.keys( unAssignedList );
|
|
3316
|
+
|
|
3317
|
+
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' ] } } );
|
|
3318
|
+
if ( getCLconfig.coverage == 'store' ) {
|
|
3319
|
+
for ( let key in unAssignedList ) {
|
|
3320
|
+
if ( unAssignedList.hasOwnProperty( key ) ) {
|
|
3321
|
+
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' ] } } );
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3326
|
+
let inprogressData = await processedchecklist.find( {
|
|
3327
|
+
date_string: insertdata.date_string,
|
|
3328
|
+
date_iso: insertdata.date_iso,
|
|
3329
|
+
client_id: insertdata.client_id,
|
|
3330
|
+
checkListId: updatedchecklist._id,
|
|
3331
|
+
}, { userId: 1, store_id: 1 } );
|
|
3332
|
+
|
|
3333
|
+
if ( inprogressData.length ) {
|
|
3334
|
+
assignUserList = assignUserList.filter( ( item ) => {
|
|
3335
|
+
let findData = inprogressData.find( ( ele ) => ele.userId.toString() == item.userId.toString() && ele.store_id == item.store_id );
|
|
3336
|
+
if ( !findData ) {
|
|
3337
|
+
return item;
|
|
3338
|
+
}
|
|
3339
|
+
} );
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3342
|
+
await processedchecklist.deleteMany( { date_string: insertdata.date_string,
|
|
3343
|
+
date_iso: insertdata.date_iso,
|
|
3344
|
+
client_id: insertdata.client_id,
|
|
3345
|
+
checkListId: updatedchecklist._id, checklistStatus: 'open' } );
|
|
3346
|
+
await processedchecklist.insertMany( assignUserList );
|
|
3308
3347
|
}
|
|
3309
3348
|
|
|
3310
3349
|
tokenList.forEach( ( item ) => {
|
|
@@ -3604,7 +3643,7 @@ export const selectAssign = async ( req, res ) => {
|
|
|
3604
3643
|
// //Select User and Teams
|
|
3605
3644
|
if ( requestData.assignType == 'user' ) {
|
|
3606
3645
|
let userQuery = [
|
|
3607
|
-
{ $match: { clientId: requestData.clientId } },
|
|
3646
|
+
{ $match: { clientId: requestData.clientId, isActive: true } },
|
|
3608
3647
|
{ $project: { 'userEmail': '$email', 'userName': 1, 'type': 'user' } },
|
|
3609
3648
|
];
|
|
3610
3649
|
resuldData = await userService.aggregate( userQuery );
|
|
@@ -3651,7 +3690,7 @@ async function assignUsers( data ) {
|
|
|
3651
3690
|
} else {
|
|
3652
3691
|
let teamDetails = await teamsServices.findteams( { clientId: data.clientId, _id: new mongoose.Types.ObjectId( data.id ) } );
|
|
3653
3692
|
if ( teamDetails.length ) {
|
|
3654
|
-
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3693
|
+
let userIdList = [ ...teamDetails[0].users.map( ( ele ) => ele.userId ), ...teamDetails[0].Teamlead.map( ( ele ) => ele.userId ) ];
|
|
3655
3694
|
let userDetails = await userService.find( { _id: userIdList } );
|
|
3656
3695
|
assignedData = userDetails.map( ( user ) => {
|
|
3657
3696
|
let userData = {
|
|
@@ -3739,27 +3778,29 @@ export async function updateAssign( req, res ) {
|
|
|
3739
3778
|
return res.sendError( 'No data found', 204 );
|
|
3740
3779
|
}
|
|
3741
3780
|
req.body.assignedGroup = [ ...new Set( req.body.assignedGroup.map( ( item ) => item.id ) ) ];
|
|
3742
|
-
req.body.assignedGroup = req.body.assignedGroup.map( ( ele ) => {
|
|
3743
|
-
|
|
3744
|
-
} );
|
|
3781
|
+
// req.body.assignedGroup = req.body.assignedGroup.map( ( ele ) => {
|
|
3782
|
+
// return { id: ele };
|
|
3783
|
+
// } );
|
|
3745
3784
|
await assignedService.deleteMany( { checkListId: req.body.checkListId } );
|
|
3746
3785
|
let assignedUserList = [];
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
},
|
|
3786
|
+
let userEmailList = req.body.assignedList.map( ( ele ) => ele.userEmail.toLowerCase() );
|
|
3787
|
+
let query = [
|
|
3788
|
+
{
|
|
3789
|
+
$addFields: {
|
|
3790
|
+
emailToLower: { $toLower: '$email' },
|
|
3753
3791
|
},
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
},
|
|
3792
|
+
},
|
|
3793
|
+
{
|
|
3794
|
+
$match: {
|
|
3795
|
+
clientId: req.body.clientId,
|
|
3796
|
+
emailToLower: { $in: userEmailList },
|
|
3759
3797
|
},
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3798
|
+
},
|
|
3799
|
+
];
|
|
3800
|
+
let assignUserDetails = await userService.aggregate( query );
|
|
3801
|
+
await Promise.all( req.body.assignedList.map( async ( assign ) => {
|
|
3802
|
+
let userDetails = assignUserDetails.find( ( ele ) => ele.email.toLowerCase() == assign.userEmail.toLowerCase() );
|
|
3803
|
+
if ( !userDetails ) {
|
|
3763
3804
|
let userData = {
|
|
3764
3805
|
userName: assign.userName,
|
|
3765
3806
|
email: assign.userEmail,
|
|
@@ -3767,7 +3808,7 @@ export async function updateAssign( req, res ) {
|
|
|
3767
3808
|
clientId: req.body.clientId,
|
|
3768
3809
|
};
|
|
3769
3810
|
userDetails = await createUser( userData );
|
|
3770
|
-
userDetails =
|
|
3811
|
+
userDetails = userDetails;
|
|
3771
3812
|
}
|
|
3772
3813
|
let data = {
|
|
3773
3814
|
...assign,
|
|
@@ -3776,25 +3817,26 @@ export async function updateAssign( req, res ) {
|
|
|
3776
3817
|
checkListId: req.body.checkListId,
|
|
3777
3818
|
coverage: req.body.coverage,
|
|
3778
3819
|
assignId: assign._id,
|
|
3779
|
-
userId: userDetails?.
|
|
3820
|
+
userId: userDetails?._id,
|
|
3780
3821
|
checkListName: checklistDetails.checkListName,
|
|
3781
3822
|
};
|
|
3782
3823
|
delete data._id;
|
|
3783
3824
|
assignedUserList.push( data );
|
|
3784
3825
|
} ) );
|
|
3826
|
+
let assignGroupDetails = [];
|
|
3827
|
+
if ( req.body.coverage == 'store' ) {
|
|
3828
|
+
assignGroupDetails = await clusterServices.findcluster( { _id: { $in: req.body.assignedGroup } } );
|
|
3829
|
+
} else {
|
|
3830
|
+
assignGroupDetails = await teamsServices.findteams( { _id: { $in: req.body.assignedGroup } } );
|
|
3831
|
+
}
|
|
3785
3832
|
await Promise.all( req.body.assignedGroup.map( async ( assign ) => {
|
|
3786
|
-
let groupDetails;
|
|
3787
|
-
if ( req.body.coverage == 'store' ) {
|
|
3788
|
-
groupDetails = await clusterServices.findOneCluster( { _id: assign.id } );
|
|
3789
|
-
} else {
|
|
3790
|
-
groupDetails = await teamsServices.findOneTeams( { _id: assign.id } );
|
|
3791
|
-
}
|
|
3833
|
+
let groupDetails = assignGroupDetails.find( ( ele ) => ele._id.toString() == assign );
|
|
3792
3834
|
if ( groupDetails ) {
|
|
3793
3835
|
let groupData = {
|
|
3794
3836
|
client_id: req.body.clientId,
|
|
3795
3837
|
checkListId: req.body.checkListId,
|
|
3796
3838
|
coverage: req.body.coverage,
|
|
3797
|
-
assignId: assign
|
|
3839
|
+
assignId: assign,
|
|
3798
3840
|
checkListName: checklistDetails.checkListName,
|
|
3799
3841
|
...( req.body.coverage == 'store' ) ? { clusterName: groupDetails?.clusterName } : { teamName: groupDetails?.teamName },
|
|
3800
3842
|
};
|