tango-app-api-trax 3.3.1-beta-70 → 3.3.1-beta-71
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
|
|
|
@@ -3053,74 +3060,90 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3053
3060
|
let notifyUserList = [];
|
|
3054
3061
|
let status = [ { checklistStatus: { $ne: 'open' } } ];
|
|
3055
3062
|
let assignUserList = [];
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3063
|
+
let userList = allQuestion.map( ( item ) => item.userId );
|
|
3064
|
+
let submittedDetails = [];
|
|
3065
|
+
let userDetails = await userService.find( { _id: { $in: userList } }, { fcmToken: 1 } );
|
|
3066
|
+
userDetails = new Map( userDetails.map( ( ele ) => [ ele._id.toString(), ele.fcmToken ] ) );
|
|
3067
|
+
if ( !getCLconfig?.allowedMultiSubmit ) {
|
|
3068
|
+
let query;
|
|
3069
|
+
if ( getCLconfig.allowOnce && ![ 'onetime', 'daily' ].includes( getCLconfig.schedule ) ) {
|
|
3070
|
+
if ( [ 'weekday', 'weekly', 'monthly' ].includes( getCLconfig.schedule ) ) {
|
|
3071
|
+
let startDate; let endDate;
|
|
3072
|
+
if ( [ 'weekday', 'weekly' ].includes( getCLconfig.schedule ) ) {
|
|
3073
|
+
startDate = dayjs.utc( date ).clone().startOf( 'week' );
|
|
3074
|
+
endDate = dayjs.utc( date ).clone().endOf( 'week' );
|
|
3075
|
+
} else {
|
|
3076
|
+
startDate = dayjs.utc( date ).clone().startOf( 'month' );
|
|
3077
|
+
endDate = dayjs.utc( date ).clone().endOf( 'month' );
|
|
3078
|
+
}
|
|
3079
|
+
query = {
|
|
3080
|
+
sourceCheckList_id: getCLconfig._id,
|
|
3081
|
+
$or: [
|
|
3082
|
+
{ submitTime: { $exists: true } },
|
|
3083
|
+
...status,
|
|
3084
|
+
],
|
|
3085
|
+
// userId: { $in: userList },
|
|
3086
|
+
// ...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3087
|
+
$and: [ {
|
|
3088
|
+
date_iso: {
|
|
3089
|
+
$gte: new Date( startDate.format( 'YYYY-MM-DD' ) ),
|
|
3090
|
+
$lte: new Date( endDate.format( 'YYYY-MM-DD' ) ) },
|
|
3091
|
+
} ],
|
|
3092
|
+
};
|
|
3093
|
+
} else {
|
|
3094
|
+
if ( getCLconfig.schedule == 'range' ) {
|
|
3076
3095
|
query = {
|
|
3077
3096
|
sourceCheckList_id: getCLconfig._id,
|
|
3078
3097
|
$or: [
|
|
3079
3098
|
{ submitTime: { $exists: true } },
|
|
3080
3099
|
...status,
|
|
3081
3100
|
],
|
|
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
|
-
},
|
|
3101
|
+
// userId: element4.userId,
|
|
3102
|
+
// ...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3103
|
+
$and: [
|
|
3104
|
+
{
|
|
3105
|
+
date_iso: {
|
|
3106
|
+
$gte: new Date( dayjs( getCLconfig.configStartDate ).format( 'YYYY-MM-DD' ) ),
|
|
3107
|
+
$lte: new Date( dayjs( getCLconfig.configEndDate ).format( 'YYYY-MM-DD' ) ),
|
|
3106
3108
|
},
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
}
|
|
3109
|
+
},
|
|
3110
|
+
],
|
|
3111
|
+
};
|
|
3110
3112
|
}
|
|
3113
|
+
}
|
|
3114
|
+
} else {
|
|
3115
|
+
query = {
|
|
3116
|
+
date_string: date,
|
|
3117
|
+
sourceCheckList_id: getCLconfig._id,
|
|
3118
|
+
$or: [
|
|
3119
|
+
...status,
|
|
3120
|
+
{ submitTime: { $exists: true } },
|
|
3121
|
+
],
|
|
3122
|
+
// userId: element4.userId,
|
|
3123
|
+
// ...( getCLconfig.coverage == 'store' ) ? { store_id: element4.store_id }:{},
|
|
3124
|
+
};
|
|
3125
|
+
}
|
|
3126
|
+
submittedDetails = await processedchecklist.find( query );
|
|
3127
|
+
}
|
|
3128
|
+
await Promise.all( allQuestion.map( async ( element4 ) => {
|
|
3129
|
+
let getToken = userDetails.get( element4.userId.toString() );
|
|
3130
|
+
if ( getToken && element4?.sendNotification && showEdit ) {
|
|
3131
|
+
tokenList.push( getToken );
|
|
3132
|
+
}
|
|
3133
|
+
if ( !element4?.sendNotification ) {
|
|
3134
|
+
notifyUserList.push( { token: getToken, storeName: element4.storeName, id: element4._id } );
|
|
3135
|
+
}
|
|
3136
|
+
if ( !getCLconfig?.allowedMultiSubmit ) {
|
|
3137
|
+
let getsubmitDetails;
|
|
3138
|
+
if ( getCLconfig.coverage == 'store' ) {
|
|
3139
|
+
getsubmitDetails = submittedDetails.find( ( checklist ) => checklist.userId.toString() == element4.userId.toString() && checklist.store_id == element4.store_id );
|
|
3111
3140
|
} 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
|
-
};
|
|
3141
|
+
getsubmitDetails = submittedDetails.find( ( checklist ) => checklist.userId.toString() == element4.userId.toString() );
|
|
3142
|
+
}
|
|
3143
|
+
if ( getsubmitDetails ) {
|
|
3144
|
+
getsubmitDetails = [ getsubmitDetails ];
|
|
3145
|
+
console.log( submittedDetails, getsubmitDetails );
|
|
3122
3146
|
}
|
|
3123
|
-
let getsubmitDetails = await processedchecklist.find( query );
|
|
3124
3147
|
function findDifferences( obj1, obj2 ) {
|
|
3125
3148
|
return Object.keys( obj1 ).reduce( ( diff, key ) => {
|
|
3126
3149
|
if ( !isEqual( obj1[key], obj2[key] ) ) {
|
|
@@ -3129,7 +3152,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3129
3152
|
return diff;
|
|
3130
3153
|
}, {} );
|
|
3131
3154
|
}
|
|
3132
|
-
if ( getsubmitDetails
|
|
3155
|
+
if ( getsubmitDetails?.length ) {
|
|
3133
3156
|
if ( showEdit && ( ( editSubmit && getsubmitDetails[0].checklistStatus == 'submit' ) || getsubmitDetails[0].checklistStatus == 'inprogress' ) ) {
|
|
3134
3157
|
let modifiedCount = 0;
|
|
3135
3158
|
let questionList = insertdata.questionAnswers;
|
|
@@ -3282,29 +3305,52 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3282
3305
|
}
|
|
3283
3306
|
}
|
|
3284
3307
|
} 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
|
-
// }
|
|
3308
|
+
let unAssignedList = assignUserList.reduce( ( acc, item ) => {
|
|
3309
|
+
if ( !acc[item.userEmail] ) {
|
|
3310
|
+
acc[item.userEmail]=[ item.store_id ];
|
|
3311
|
+
} else {
|
|
3312
|
+
acc[item.userEmail].push( item.store_id );
|
|
3313
|
+
}
|
|
3314
|
+
return acc;
|
|
3315
|
+
}, {} );
|
|
3304
3316
|
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
}
|
|
3317
|
+
let userList = Object.keys( unAssignedList );
|
|
3318
|
+
|
|
3319
|
+
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' ] } } );
|
|
3320
|
+
if ( getCLconfig.coverage == 'store' ) {
|
|
3321
|
+
await Promise.all( assignUserList.map( async ( item ) => {
|
|
3322
|
+
if ( unAssignedList.hasOwnProperty( item.userEmail ) ) {
|
|
3323
|
+
await processedchecklist.deleteMany( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, $and: [ { userEmail: item.userEmail }, { store_id: { $nin: unAssignedList[item.userEmail] } } ], checklistStatus: { $nin: [ 'submit' ] } } );
|
|
3324
|
+
}
|
|
3325
|
+
} ) );
|
|
3326
|
+
// for ( let key in unAssignedList ) {
|
|
3327
|
+
// if ( unAssignedList.hasOwnProperty( key ) ) {
|
|
3328
|
+
// 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' ] } } );
|
|
3329
|
+
// }
|
|
3330
|
+
// }
|
|
3331
|
+
}
|
|
3332
|
+
|
|
3333
|
+
let inprogressData = await processedchecklist.find( {
|
|
3334
|
+
date_string: insertdata.date_string,
|
|
3335
|
+
date_iso: insertdata.date_iso,
|
|
3336
|
+
client_id: insertdata.client_id,
|
|
3337
|
+
checkListId: updatedchecklist._id,
|
|
3338
|
+
}, { userId: 1, store_id: 1 } );
|
|
3339
|
+
|
|
3340
|
+
if ( inprogressData.length ) {
|
|
3341
|
+
assignUserList = assignUserList.filter( ( item ) => {
|
|
3342
|
+
let findData = inprogressData.find( ( ele ) => ele.userId.toString() == item.userId.toString() && ele.store_id == item.store_id );
|
|
3343
|
+
if ( !findData ) {
|
|
3344
|
+
return item;
|
|
3345
|
+
}
|
|
3346
|
+
} );
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
await processedchecklist.deleteMany( { date_string: insertdata.date_string,
|
|
3350
|
+
date_iso: insertdata.date_iso,
|
|
3351
|
+
client_id: insertdata.client_id,
|
|
3352
|
+
checkListId: updatedchecklist._id, checklistStatus: 'open' } );
|
|
3353
|
+
await processedchecklist.insertMany( assignUserList );
|
|
3308
3354
|
}
|
|
3309
3355
|
|
|
3310
3356
|
tokenList.forEach( ( item ) => {
|
|
@@ -3604,7 +3650,7 @@ export const selectAssign = async ( req, res ) => {
|
|
|
3604
3650
|
// //Select User and Teams
|
|
3605
3651
|
if ( requestData.assignType == 'user' ) {
|
|
3606
3652
|
let userQuery = [
|
|
3607
|
-
{ $match: { clientId: requestData.clientId } },
|
|
3653
|
+
{ $match: { clientId: requestData.clientId, isActive: true } },
|
|
3608
3654
|
{ $project: { 'userEmail': '$email', 'userName': 1, 'type': 'user' } },
|
|
3609
3655
|
];
|
|
3610
3656
|
resuldData = await userService.aggregate( userQuery );
|
|
@@ -3651,7 +3697,7 @@ async function assignUsers( data ) {
|
|
|
3651
3697
|
} else {
|
|
3652
3698
|
let teamDetails = await teamsServices.findteams( { clientId: data.clientId, _id: new mongoose.Types.ObjectId( data.id ) } );
|
|
3653
3699
|
if ( teamDetails.length ) {
|
|
3654
|
-
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3700
|
+
let userIdList = [ ...teamDetails[0].users.map( ( ele ) => ele.userId ), ...teamDetails[0].Teamlead.map( ( ele ) => ele.userId ) ];
|
|
3655
3701
|
let userDetails = await userService.find( { _id: userIdList } );
|
|
3656
3702
|
assignedData = userDetails.map( ( user ) => {
|
|
3657
3703
|
let userData = {
|
|
@@ -3739,27 +3785,29 @@ export async function updateAssign( req, res ) {
|
|
|
3739
3785
|
return res.sendError( 'No data found', 204 );
|
|
3740
3786
|
}
|
|
3741
3787
|
req.body.assignedGroup = [ ...new Set( req.body.assignedGroup.map( ( item ) => item.id ) ) ];
|
|
3742
|
-
req.body.assignedGroup = req.body.assignedGroup.map( ( ele ) => {
|
|
3743
|
-
|
|
3744
|
-
} );
|
|
3788
|
+
// req.body.assignedGroup = req.body.assignedGroup.map( ( ele ) => {
|
|
3789
|
+
// return { id: ele };
|
|
3790
|
+
// } );
|
|
3745
3791
|
await assignedService.deleteMany( { checkListId: req.body.checkListId } );
|
|
3746
3792
|
let assignedUserList = [];
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
},
|
|
3793
|
+
let userEmailList = req.body.assignedList.map( ( ele ) => ele.userEmail.toLowerCase() );
|
|
3794
|
+
let query = [
|
|
3795
|
+
{
|
|
3796
|
+
$addFields: {
|
|
3797
|
+
emailToLower: { $toLower: '$email' },
|
|
3753
3798
|
},
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
},
|
|
3799
|
+
},
|
|
3800
|
+
{
|
|
3801
|
+
$match: {
|
|
3802
|
+
clientId: req.body.clientId,
|
|
3803
|
+
emailToLower: { $in: userEmailList },
|
|
3759
3804
|
},
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3805
|
+
},
|
|
3806
|
+
];
|
|
3807
|
+
let assignUserDetails = await userService.aggregate( query );
|
|
3808
|
+
await Promise.all( req.body.assignedList.map( async ( assign ) => {
|
|
3809
|
+
let userDetails = assignUserDetails.find( ( ele ) => ele.email.toLowerCase() == assign.userEmail.toLowerCase() );
|
|
3810
|
+
if ( !userDetails ) {
|
|
3763
3811
|
let userData = {
|
|
3764
3812
|
userName: assign.userName,
|
|
3765
3813
|
email: assign.userEmail,
|
|
@@ -3767,7 +3815,7 @@ export async function updateAssign( req, res ) {
|
|
|
3767
3815
|
clientId: req.body.clientId,
|
|
3768
3816
|
};
|
|
3769
3817
|
userDetails = await createUser( userData );
|
|
3770
|
-
userDetails =
|
|
3818
|
+
userDetails = userDetails;
|
|
3771
3819
|
}
|
|
3772
3820
|
let data = {
|
|
3773
3821
|
...assign,
|
|
@@ -3776,25 +3824,26 @@ export async function updateAssign( req, res ) {
|
|
|
3776
3824
|
checkListId: req.body.checkListId,
|
|
3777
3825
|
coverage: req.body.coverage,
|
|
3778
3826
|
assignId: assign._id,
|
|
3779
|
-
userId: userDetails?.
|
|
3827
|
+
userId: userDetails?._id,
|
|
3780
3828
|
checkListName: checklistDetails.checkListName,
|
|
3781
3829
|
};
|
|
3782
3830
|
delete data._id;
|
|
3783
3831
|
assignedUserList.push( data );
|
|
3784
3832
|
} ) );
|
|
3833
|
+
let assignGroupDetails = [];
|
|
3834
|
+
if ( req.body.coverage == 'store' ) {
|
|
3835
|
+
assignGroupDetails = await clusterServices.findcluster( { _id: { $in: req.body.assignedGroup } } );
|
|
3836
|
+
} else {
|
|
3837
|
+
assignGroupDetails = await teamsServices.findteams( { _id: { $in: req.body.assignedGroup } } );
|
|
3838
|
+
}
|
|
3785
3839
|
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
|
-
}
|
|
3840
|
+
let groupDetails = assignGroupDetails.find( ( ele ) => ele._id.toString() == assign );
|
|
3792
3841
|
if ( groupDetails ) {
|
|
3793
3842
|
let groupData = {
|
|
3794
3843
|
client_id: req.body.clientId,
|
|
3795
3844
|
checkListId: req.body.checkListId,
|
|
3796
3845
|
coverage: req.body.coverage,
|
|
3797
|
-
assignId: assign
|
|
3846
|
+
assignId: assign,
|
|
3798
3847
|
checkListName: checklistDetails.checkListName,
|
|
3799
3848
|
...( req.body.coverage == 'store' ) ? { clusterName: groupDetails?.clusterName } : { teamName: groupDetails?.teamName },
|
|
3800
3849
|
};
|