tango-app-api-trax 3.3.1-beta-9 → 3.3.1-beta-10
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
|
@@ -859,11 +859,11 @@ export const assignedUserDetails = async ( req, res ) => {
|
|
|
859
859
|
if ( !req.params.checklistId ) {
|
|
860
860
|
return res.sendError( { message: 'checklist Id is required' }, 400 );
|
|
861
861
|
}
|
|
862
|
-
let limit = parseInt( req.query.limit ) ||
|
|
862
|
+
let limit = parseInt( req.query.limit ) || 5;
|
|
863
863
|
let page = parseInt( req.query.offset ) || 0;
|
|
864
864
|
let skip = limit * page;
|
|
865
865
|
|
|
866
|
-
let query = [ { $match: { checkListId: new ObjectId( req.params.checklistId ) } } ];
|
|
866
|
+
let query = [ { $match: { checkListId: new ObjectId( req.params.checklistId ), coverage: req.body.coverage } } ];
|
|
867
867
|
if ( req.query.search.trim() && req.query.search.trim() != '' ) {
|
|
868
868
|
let searchValue = req.query.search;
|
|
869
869
|
searchValue = searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
|
|
@@ -874,52 +874,82 @@ export const assignedUserDetails = async ( req, res ) => {
|
|
|
874
874
|
query.push( { $match: { storeName: { $regex: req.query.search.trim(), $options: 'i' } } } );
|
|
875
875
|
}
|
|
876
876
|
}
|
|
877
|
-
if ( req.query.sortColumn && req.query.sortBy ) {
|
|
878
|
-
query.push( { $sort: { [req.query.sortColumn]: parseInt( req.query.sortBy ) } } );
|
|
879
|
-
} else {
|
|
880
|
-
query.push( { $sort: { _id: -1 } } );
|
|
881
|
-
}
|
|
882
877
|
|
|
883
|
-
query.push( {
|
|
884
|
-
$facet: {
|
|
885
|
-
data: [
|
|
886
|
-
{ $skip: skip }, { $limit: limit },
|
|
887
|
-
],
|
|
888
|
-
count: [
|
|
889
|
-
{ $count: 'total' },
|
|
890
|
-
],
|
|
891
|
-
},
|
|
892
|
-
} );
|
|
878
|
+
query.push( { $sort: { _id: -1 } } );
|
|
893
879
|
|
|
894
880
|
let checklistDetails = await assignedService.aggregate( query );
|
|
895
|
-
|
|
896
|
-
if ( !checklistDetails[0].data.length ) {
|
|
881
|
+
if ( !checklistDetails.length ) {
|
|
897
882
|
return res.sendError( 'no data found', 204 );
|
|
898
883
|
}
|
|
899
884
|
|
|
900
885
|
let userDetails = [];
|
|
901
886
|
let storeList = [];
|
|
902
887
|
let userList = [];
|
|
903
|
-
checklistDetails
|
|
904
|
-
if (
|
|
905
|
-
storeList.push(
|
|
888
|
+
await Promise.all( checklistDetails.map( async ( ele ) => {
|
|
889
|
+
if ( ele?.store_id || ele?.clusterName ) {
|
|
890
|
+
storeList.push( ele.assignId );
|
|
906
891
|
} else {
|
|
907
|
-
userList.push(
|
|
892
|
+
userList.push( ele.assignId );
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
if ( ele?.clusterName ) {
|
|
896
|
+
let clusterDetails = await clusterServices.findOneCluster( { _id: ele.assignId }, { stores: 1 } );
|
|
897
|
+
if ( clusterDetails ) {
|
|
898
|
+
let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) } } );
|
|
899
|
+
storeDetails.forEach( ( item ) => {
|
|
900
|
+
userDetails.push( {
|
|
901
|
+
id: ele._id,
|
|
902
|
+
userName: item.spocDetails?.[0]?.name,
|
|
903
|
+
userEmail: item.spocDetails[0].email,
|
|
904
|
+
store_id: item?.storeId,
|
|
905
|
+
storeName: item?.storeName,
|
|
906
|
+
userPhone: item.spocDetails?.[0]?.phone,
|
|
907
|
+
city: ele?.city,
|
|
908
|
+
checkFlag: ele.checkFlag,
|
|
909
|
+
clusterName: ele?.clusterName || '',
|
|
910
|
+
teamName: ele?.teamName || '',
|
|
911
|
+
} );
|
|
912
|
+
} );
|
|
913
|
+
}
|
|
914
|
+
} else if ( ele?.teamName ) {
|
|
915
|
+
let teamDetails = await teamsServices.findOneTeams( { _id: ele.assignId }, { users: 1, teamName: 1 } );
|
|
916
|
+
if ( teamDetails ) {
|
|
917
|
+
let teamUserDetails = await userService.find( { _id: { $in: teamDetails.users.map( ( item ) => item.userId ) } } );
|
|
918
|
+
teamUserDetails.forEach( ( item ) => {
|
|
919
|
+
userDetails.push( {
|
|
920
|
+
id: ele._id,
|
|
921
|
+
userName: item.userName,
|
|
922
|
+
userEmail: item.email,
|
|
923
|
+
store_id: ele?.storeId,
|
|
924
|
+
storeName: ele?.storeName,
|
|
925
|
+
userPhone: item?.mobileNumber,
|
|
926
|
+
city: ele?.city,
|
|
927
|
+
checkFlag: ele.checkFlag,
|
|
928
|
+
clusterName: ele?.clusterName || '',
|
|
929
|
+
teamName: ele?.teamName || '',
|
|
930
|
+
} );
|
|
931
|
+
} );
|
|
932
|
+
}
|
|
933
|
+
} else {
|
|
934
|
+
userDetails.push( {
|
|
935
|
+
id: ele._id,
|
|
936
|
+
userName: ele.userName,
|
|
937
|
+
userEmail: ele.userEmail,
|
|
938
|
+
store_id: ele?.store_id,
|
|
939
|
+
storeName: ele?.storeName,
|
|
940
|
+
userPhone: ele.userPhone,
|
|
941
|
+
city: ele.city,
|
|
942
|
+
checkFlag: ele.checkFlag,
|
|
943
|
+
clusterName: ele?.clusterName || '',
|
|
944
|
+
teamName: ele?.teamName || '',
|
|
945
|
+
} );
|
|
908
946
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
userPhone: item.userPhone,
|
|
916
|
-
city: item.city,
|
|
917
|
-
checkFlag: item.checkFlag,
|
|
918
|
-
clusterName: item?.clusterName,
|
|
919
|
-
teamName: item?.teamName,
|
|
920
|
-
} );
|
|
921
|
-
} );
|
|
922
|
-
return res.sendSuccess( { users: userDetails, count: checklistDetails[0].count[0].total, storeList, userList } );
|
|
947
|
+
} ) );
|
|
948
|
+
|
|
949
|
+
userDetails.sort( ( a, b ) => b.teamName - a.teamName );
|
|
950
|
+
console.log( userDetails );
|
|
951
|
+
let limitedData = userDetails.slice( skip, limit + skip );
|
|
952
|
+
return res.sendSuccess( { count: userDetails.length, storeList, userList, users: limitedData } );
|
|
923
953
|
} catch ( e ) {
|
|
924
954
|
logger.error( 'assignedUserDetails =>', e );
|
|
925
955
|
return res.sendError( e, 500 );
|
|
@@ -1266,6 +1296,226 @@ export const updateConfigure =async ( req, res ) => {
|
|
|
1266
1296
|
}
|
|
1267
1297
|
};
|
|
1268
1298
|
|
|
1299
|
+
export const updateConfigurev1 =async ( req, res ) => {
|
|
1300
|
+
try {
|
|
1301
|
+
let inputBody = req.body;
|
|
1302
|
+
let id;
|
|
1303
|
+
let checklistDetails;
|
|
1304
|
+
if ( !inputBody.checkListDetails._id ) {
|
|
1305
|
+
return res.sendError( 'checkListId is Required', 400 );
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
if ( inputBody.checkListDetails.checkListType == 'mobileusagedetection' && inputBody.submitType == 'publish' ) {
|
|
1309
|
+
if ( !inputBody?.checkListDetails?.alert?.usageExceeds ) {
|
|
1310
|
+
return res.sendError( 'Please Enter usage exceeds', 400 );
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
if ( !inputBody?.checkListDetails?.alert?.alertsTo.length ) {
|
|
1314
|
+
return res.sendError( 'Please select users to send alert', 400 );
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
if ( !inputBody?.checkListDetails?.detectionArea.length ) {
|
|
1318
|
+
return res.sendError( 'Please select detection area', 400 );
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
if ( !inputBody.checkListDetails.assignedUsers.length && inputBody.submitType == 'publish' ) {
|
|
1323
|
+
return res.sendError( 'Please Assigned a user', 400 );
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
if ( !inputBody?.checkListDetails?.approver.length && inputBody.submitType == 'publish' ) {
|
|
1327
|
+
return res.sendError( 'Please assign approver', 400 );
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
|
|
1331
|
+
let logInsertData = {
|
|
1332
|
+
action: inputBody.submitType == 'publish' ? 'checklistPublishUsingConfigPage' : 'checklistConfigDraft',
|
|
1333
|
+
checklistId: inputBody.checkListDetails._id,
|
|
1334
|
+
checkListName: inputBody?.checkListDetails.checkListName,
|
|
1335
|
+
createdBy: req.user._id,
|
|
1336
|
+
createdByName: req.user.userName,
|
|
1337
|
+
client_id: req.body.clientId,
|
|
1338
|
+
createdByEmail: req.user.email,
|
|
1339
|
+
approver: inputBody?.checkListDetails?.approver || [],
|
|
1340
|
+
};
|
|
1341
|
+
await checklistLogs.create( logInsertData );
|
|
1342
|
+
|
|
1343
|
+
checklistDetails = await checklistService.findOne( { _id: inputBody.checkListDetails._id, type: 'checklist', isdeleted: false } );
|
|
1344
|
+
|
|
1345
|
+
if ( [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection' ].includes( inputBody.checkListDetails.checkListType ) && inputBody.uploadUser ) {
|
|
1346
|
+
checklistDetails = await checklistService.findOne( { _id: inputBody.checkListDetails._id, type: 'checklist' } );
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
if ( !checklistDetails ) {
|
|
1350
|
+
return res.sendError( 'no data found', 204 );
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
let currentDate = dayjs.utc().format();
|
|
1354
|
+
let updatedscheduleEndTimeISO = dayjs.utc( inputBody?.checkListDetails?.scheduleEndTime, 'hh:mm A' ).format( 'HH:mm:ss' );
|
|
1355
|
+
let newUpdatedDate = dayjs.utc( updatedscheduleEndTimeISO, 'HH:mm:ss' ).format();
|
|
1356
|
+
|
|
1357
|
+
if ( inputBody.submitType == 'publish' && inputBody?.showEdit && typeof inputBody?.editSubmit == 'undefined' && newUpdatedDate > currentDate ) {
|
|
1358
|
+
let checkSubmitDetails = await processedchecklist.findOne( { sourceCheckList_id: inputBody.checkListDetails._id, date_string: dayjs().format( 'YYYY-MM-DD' ), checklistStatus: 'submit' } );
|
|
1359
|
+
if ( checkSubmitDetails ) {
|
|
1360
|
+
return res.sendError( 'Checklist got submitted', 400 );
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
if ( checklistDetails?.publishDate && inputBody.submitType == 'publish' ) {
|
|
1365
|
+
let date = dayjs();
|
|
1366
|
+
let diff = date.diff( dayjs.utc( checklistDetails?.publishDate ), 'minutes' );
|
|
1367
|
+
if ( diff < 5 ) {
|
|
1368
|
+
let mins = ( 5 - diff ) > 1 ? 'minutes' : 'minute';
|
|
1369
|
+
return res.sendError( `Please try after ${5 - diff} ${mins}`, 400 );
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
if ( inputBody?.checkListDetails?.scheduleRepeatedMonthSetup == 'date' ) {
|
|
1374
|
+
inputBody.checkListDetails.scheduleRepeatedDay = inputBody?.checkListDetails?.scheduleRepeatedDay;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
if ( inputBody?.checkListDetails?.scheduleDate ) {
|
|
1378
|
+
inputBody.checkListDetails.scheduleDate = new Date( inputBody?.checkListDetails?.scheduleDate );
|
|
1379
|
+
}
|
|
1380
|
+
let configDetails = {
|
|
1381
|
+
...inputBody?.checkListDetails,
|
|
1382
|
+
publishDate: inputBody.checkListDetails.publish ? new Date() : '',
|
|
1383
|
+
scheduleStartTimeISO: dayjs.utc( inputBody?.checkListDetails?.scheduleStartTime, 'hh:mm A' ).format(),
|
|
1384
|
+
scheduleEndTimeISO: dayjs.utc( inputBody?.checkListDetails?.scheduleEndTime, 'hh:mm A' ).format(),
|
|
1385
|
+
scheduleDate: inputBody?.checkListDetails?.scheduleDate ? dayjs( inputBody.checkListDetails.scheduleDate ).format() : '',
|
|
1386
|
+
approver: inputBody?.checkListDetails?.approver.length ? inputBody?.checkListDetails?.approver.map( ( item ) => {
|
|
1387
|
+
return { name: item.name, value: item.value };
|
|
1388
|
+
} ) : [],
|
|
1389
|
+
};
|
|
1390
|
+
|
|
1391
|
+
if ( inputBody?.checkListDetails?.approver.length ) {
|
|
1392
|
+
let data = [];
|
|
1393
|
+
let existEmail = await traxApprover.find( { checkListId: inputBody.checkListDetails._id, isDeleted: false } );
|
|
1394
|
+
let mailList = existEmail.map( ( item ) => item.userEmail );
|
|
1395
|
+
existEmail = inputBody?.checkListDetails?.approver.filter( ( item ) => mailList.includes( item.value ) ).map( ( item ) => item.value );
|
|
1396
|
+
let userMailList = inputBody?.checkListDetails?.approver.map( ( ele ) => ele.value );
|
|
1397
|
+
inputBody?.checkListDetails?.approver.forEach( ( ele ) => {
|
|
1398
|
+
if ( !existEmail.includes( ele.value ) ) {
|
|
1399
|
+
data.push( {
|
|
1400
|
+
userEmail: ele.value,
|
|
1401
|
+
checkListId: inputBody.checkListDetails._id,
|
|
1402
|
+
type: 'checklist',
|
|
1403
|
+
checkListName: inputBody?.checkListDetails.checkListName,
|
|
1404
|
+
client_id: inputBody?.clientId,
|
|
1405
|
+
} );
|
|
1406
|
+
}
|
|
1407
|
+
} );
|
|
1408
|
+
|
|
1409
|
+
await traxApprover.updateMany( { checkListId: inputBody.checkListDetails._id, userEmail: { $nin: userMailList } }, { isDeleted: true } );
|
|
1410
|
+
if ( data.length ) {
|
|
1411
|
+
await traxApprover.insertMany( data );
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
if ( checklistDetails.checkListType != 'custom' && !checklistDetails.client_id ) {
|
|
1416
|
+
let getchecklistNumber = await checklistService.findOne( { client_id: req.body.clientId, type: 'checklist' }, { checkListNumber: 1 } );
|
|
1417
|
+
let name = checklistDetails.checkListName.split( '(' )[0];
|
|
1418
|
+
let checkListNameDetails = await checklistService.find( { checkListName: { $regex: name }, client_id: req.body.clientId, type: 'checklist', isdeleted: false } );
|
|
1419
|
+
if ( checkListNameDetails.length ) {
|
|
1420
|
+
let nameLength = ( checkListNameDetails.length-1 ) + 1;
|
|
1421
|
+
checklistDetails.checkListName = checklistDetails.checkListName.split( '(' )[0] + '(' + nameLength + ')';
|
|
1422
|
+
} else {
|
|
1423
|
+
checklistDetails.checkListName = checklistDetails.checkListName;
|
|
1424
|
+
}
|
|
1425
|
+
configDetails.type = 'checklist';
|
|
1426
|
+
configDetails.checkListName = checklistDetails.checkListName;
|
|
1427
|
+
configDetails.checkListDescription = checklistDetails.checkListDescription;
|
|
1428
|
+
if ( getchecklistNumber ) {
|
|
1429
|
+
configDetails.checkListNumber = getchecklistNumber.checkListNumber + 1;
|
|
1430
|
+
} else {
|
|
1431
|
+
configDetails.checkListNumber = 1;
|
|
1432
|
+
}
|
|
1433
|
+
configDetails.createdBy= req.user._id;
|
|
1434
|
+
configDetails.createdByName=req.user.userName;
|
|
1435
|
+
delete inputBody.checkListDetails['_id'];
|
|
1436
|
+
if ( [ 'storeopenandclose', 'uniformdetection' ].includes( checklistDetails.checkListType ) ) {
|
|
1437
|
+
let query = { client_id: req.body.clientId, type: 'checklist', isdeleted: false };
|
|
1438
|
+
if ( checklistDetails.checkListType == 'storeopenandclose' ) {
|
|
1439
|
+
query.checkListType= 'storeopenandclose';
|
|
1440
|
+
} else {
|
|
1441
|
+
query.checkListType= 'uniformdetection';
|
|
1442
|
+
}
|
|
1443
|
+
let storeChecklisDetails = await checklistService.findOne( query );
|
|
1444
|
+
if ( storeChecklisDetails ) {
|
|
1445
|
+
inputBody.checkListDetails._id = storeChecklisDetails._id;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
let query = {
|
|
1450
|
+
client_id: req.body.clientId,
|
|
1451
|
+
checkListType: checklistDetails.checkListType,
|
|
1452
|
+
_id: inputBody.checkListDetails._id,
|
|
1453
|
+
};
|
|
1454
|
+
let response;
|
|
1455
|
+
if ( inputBody.checkListDetails._id ) {
|
|
1456
|
+
if ( [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection' ].includes( inputBody.checkListDetails.checkListType ) && inputBody.uploadUser ) {
|
|
1457
|
+
configDetails.isdeleted = false;
|
|
1458
|
+
}
|
|
1459
|
+
id = inputBody.checkListDetails._id;
|
|
1460
|
+
response = await checklistService.updateOne( query, configDetails );
|
|
1461
|
+
} else {
|
|
1462
|
+
configDetails.client_id = req.body.clientId;
|
|
1463
|
+
configDetails.checkListType = checklistDetails.checkListType;
|
|
1464
|
+
response = await checklistService.create( configDetails );
|
|
1465
|
+
id = response._id;
|
|
1466
|
+
}
|
|
1467
|
+
// if ( inputBody.checkListDetails.assignedUsers.length ) {
|
|
1468
|
+
// await assignedService.deleteMany( { checkListId: inputBody.checkListDetails._id } );
|
|
1469
|
+
// await Promise.all( inputBody.checkListDetails.assignedUsers.map( async ( user ) => {
|
|
1470
|
+
// let data = {
|
|
1471
|
+
// ...user,
|
|
1472
|
+
// clientId: req.body.clientId,
|
|
1473
|
+
// checkListName: checklistDetails.checkListName,
|
|
1474
|
+
// checklistId: checklistDetails._id,
|
|
1475
|
+
// };
|
|
1476
|
+
// await assignUsers( data );
|
|
1477
|
+
// } ) );
|
|
1478
|
+
// }
|
|
1479
|
+
if ( inputBody.submitType == 'publish' ) {
|
|
1480
|
+
if ( inputBody.checkListDetails.checkListType == 'custom' ) {
|
|
1481
|
+
let currentDate = dayjs.utc().format();
|
|
1482
|
+
let updatedscheduleEndTimeISO = dayjs.utc( configDetails.scheduleEndTimeISO ).format( 'HH:mm:ss' );
|
|
1483
|
+
let newUpdatedDate = dayjs.utc( updatedscheduleEndTimeISO, 'HH:mm:ss' ).format();
|
|
1484
|
+
if ( newUpdatedDate > currentDate ) {
|
|
1485
|
+
let deleteQuery = {
|
|
1486
|
+
$and: [
|
|
1487
|
+
{ date_string: dayjs().format( 'YYYY-MM-DD' ) },
|
|
1488
|
+
{ sourceCheckList_id: new ObjectId( req.params.checklistId ) },
|
|
1489
|
+
{ scheduleEndTime_iso: { $gt: currentDate } },
|
|
1490
|
+
],
|
|
1491
|
+
};
|
|
1492
|
+
deleteQuery.$and.push( { checklistStatus: { $ne: 'submit' } } );
|
|
1493
|
+
let PClicklist = await processedchecklist.deleteMany( deleteQuery );
|
|
1494
|
+
logger.info( { function: 'updateConfigure', query: deleteQuery } );
|
|
1495
|
+
if ( PClicklist.acknowledged || inputBody.updateConfigure ) {
|
|
1496
|
+
await insertSingleProcessData( inputBody.checkListDetails._id, 0, inputBody.updateConfigure, inputBody?.editSubmit, inputBody?.showEdit );
|
|
1497
|
+
} else {
|
|
1498
|
+
res.sendError( 'something went wrong, please try again', 500 );
|
|
1499
|
+
}
|
|
1500
|
+
} else {
|
|
1501
|
+
logger.info( `Schudled End Time Breached Checklist publish true => Checklist Name: ${checklistDetails.checkListName}` );
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
futureDaysDataRemove( currentDate, req.params.checklistId, checklistDetails.checkListName, '333' );
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
if ( response?.modifiedCount || response?.matchedCount || response?.upsertedCount ) {
|
|
1508
|
+
return res.sendSuccess( { id, message: 'Configured Updated Successfully' } );
|
|
1509
|
+
}
|
|
1510
|
+
if ( response._id ) {
|
|
1511
|
+
return res.sendSuccess( { id, message: 'Configured Added Successfully' } );
|
|
1512
|
+
}
|
|
1513
|
+
} catch ( e ) {
|
|
1514
|
+
logger.error( 'updateConfigure =>', e );
|
|
1515
|
+
return res.sendError( e, 500 );
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1269
1519
|
export const updatePublish = async ( req, res ) => {
|
|
1270
1520
|
try {
|
|
1271
1521
|
if ( typeof req?.body?.checklistId == 'undefined' && typeof req.body.type == 'undefined' ) {
|
|
@@ -1594,6 +1844,127 @@ export const validateUser = async ( req, res ) => {
|
|
|
1594
1844
|
}
|
|
1595
1845
|
};
|
|
1596
1846
|
|
|
1847
|
+
export const validateUserv1 = async ( req, res ) => {
|
|
1848
|
+
try {
|
|
1849
|
+
if ( !req.body.assignedUsers.length ) {
|
|
1850
|
+
return res.sendError( 'Please Enter user Details', 400 );
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
let assignDetails = req.body.assignedUsers;
|
|
1854
|
+
|
|
1855
|
+
const duplicateStore = assignDetails.reduce( ( acc, obj ) => {
|
|
1856
|
+
if ( !acc[obj.storeName.toLowerCase()] ) {
|
|
1857
|
+
acc[obj.storeName.toLowerCase()] = {
|
|
1858
|
+
email: [ obj.userEmail.toLowerCase() ],
|
|
1859
|
+
count: 1,
|
|
1860
|
+
};
|
|
1861
|
+
} else {
|
|
1862
|
+
if ( acc[obj.storeName.toLowerCase()] ) {
|
|
1863
|
+
if ( acc[obj.storeName.toLowerCase()].email.includes( obj.userEmail.toLowerCase() ) ) {
|
|
1864
|
+
acc[obj.storeName.toLowerCase()].count++;
|
|
1865
|
+
} else {
|
|
1866
|
+
acc[obj.storeName.toLowerCase()].email.push( obj.userEmail.toLowerCase() );
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
return acc;
|
|
1871
|
+
}, {} );
|
|
1872
|
+
|
|
1873
|
+
const duplicateStores = Object.keys( duplicateStore ).filter( ( storeName ) => duplicateStore[storeName].count > 1 );
|
|
1874
|
+
if ( duplicateStores.length ) {
|
|
1875
|
+
return res.sendSuccess( { validate: false, ExistsEmail: duplicateStores, message: 'store and email is Duplicated' } );
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
if ( req.body.hasOwnProperty( 'delete' ) ) {
|
|
1879
|
+
let checkExists = await assignedService.findOne( { userEmail: assignDetails[0].userEmail, storeName: assignDetails[0].storeName, checkListId: req.body.id } );
|
|
1880
|
+
if ( checkExists ) {
|
|
1881
|
+
return res.sendError( 'User already Exists', 400 );
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
// let userChunk =await chunkArray( users, 10 );
|
|
1885
|
+
|
|
1886
|
+
await Promise.all( users.map( async ( chunk ) => {
|
|
1887
|
+
await processUser( [ chunk ] );
|
|
1888
|
+
} ) );
|
|
1889
|
+
|
|
1890
|
+
let userEmailList = assignDetails.map( ( item ) => item.userEmail.toLowerCase() );
|
|
1891
|
+
let storeList = assignDetails.map( ( item ) => item.storeName.toLowerCase() );
|
|
1892
|
+
|
|
1893
|
+
let userQuery = [
|
|
1894
|
+
{
|
|
1895
|
+
$project: {
|
|
1896
|
+
newEmail: { $toLower: '$email' },
|
|
1897
|
+
isActive: 1,
|
|
1898
|
+
clientId: 1,
|
|
1899
|
+
},
|
|
1900
|
+
},
|
|
1901
|
+
{
|
|
1902
|
+
$match: {
|
|
1903
|
+
newEmail: { $in: userEmailList },
|
|
1904
|
+
isActive: true,
|
|
1905
|
+
clientId: req.body.clientId,
|
|
1906
|
+
},
|
|
1907
|
+
},
|
|
1908
|
+
];
|
|
1909
|
+
|
|
1910
|
+
let storeQuery = [
|
|
1911
|
+
{
|
|
1912
|
+
$project: {
|
|
1913
|
+
'storeName': { $toLower: '$storeName' },
|
|
1914
|
+
'clientId': 1,
|
|
1915
|
+
'storeProfile.city': 1,
|
|
1916
|
+
'status': 1,
|
|
1917
|
+
},
|
|
1918
|
+
},
|
|
1919
|
+
{
|
|
1920
|
+
$match: {
|
|
1921
|
+
clientId: req.body.clientId,
|
|
1922
|
+
storeName: { $in: storeList },
|
|
1923
|
+
},
|
|
1924
|
+
},
|
|
1925
|
+
];
|
|
1926
|
+
|
|
1927
|
+
let [ userDetails, storeDetails ] = await Promise.all[
|
|
1928
|
+
await userService.aggregate( userQuery ),
|
|
1929
|
+
await storeService.aggregate( storeQuery )
|
|
1930
|
+
];
|
|
1931
|
+
|
|
1932
|
+
let existUSerEmail = userDetails.map( ( ele ) => ele.email );
|
|
1933
|
+
|
|
1934
|
+
userDetails = userEmailList.filter( ( ele ) => !existUSerEmail.includes( ele ) );
|
|
1935
|
+
|
|
1936
|
+
let existsStore = storeDetails.map( ( ele ) => ele.storeName );
|
|
1937
|
+
storeDetails = storeList.filter( ( ele ) => !existsStore.includes( ele ) );
|
|
1938
|
+
|
|
1939
|
+
if ( userDetails.length || storeDetails.length ) {
|
|
1940
|
+
return res.sendError( { validate: false, user: userDetails, store: storeDetails }, 400 );
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
return res.sendSuccess( { validate: true } );
|
|
1944
|
+
} catch ( e ) {
|
|
1945
|
+
logger.error( 'validateUser 2=>', e );
|
|
1946
|
+
return res.sendError( e, 500 );
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
|
|
1950
|
+
export async function assignUser( req, res ) {
|
|
1951
|
+
try {
|
|
1952
|
+
let inputBody = req.body;
|
|
1953
|
+
let assignDetails = inputBody.assignUsers;
|
|
1954
|
+
if ( inputBody.type == 'upload' ) {
|
|
1955
|
+
await assignedService.deleteMany( { checkListId: inputBody.checklistId } );
|
|
1956
|
+
}
|
|
1957
|
+
await Promise.all( assignDetails.map( ( assign ) => {
|
|
1958
|
+
assignUsers( assign );
|
|
1959
|
+
} ) );
|
|
1960
|
+
return res.sendSuccess( 'Details updated successfully' );
|
|
1961
|
+
} catch ( e ) {
|
|
1962
|
+
logger.error( { functionName: 'assignUser', error: e } );
|
|
1963
|
+
return res.sendError( e, 500 );
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
|
|
1597
1968
|
async function uploadUser( req, res ) {
|
|
1598
1969
|
try {
|
|
1599
1970
|
let inputBody = req.body;
|
|
@@ -2726,168 +3097,107 @@ export const checklistV2 = async ( req, res ) => {
|
|
|
2726
3097
|
}
|
|
2727
3098
|
};
|
|
2728
3099
|
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
if ( !req.body.coverage ) {
|
|
2735
|
-
return res.sendError( 'Coverage is required', 400 );
|
|
2736
|
-
}
|
|
2737
|
-
if ( !req.body.id ) {
|
|
2738
|
-
return res.sendError( 'Store/user id is required', 400 );
|
|
2739
|
-
}
|
|
2740
|
-
|
|
2741
|
-
let checklistDetails = await checklistService.findOne( { _id: req.body.checklistId } );
|
|
2742
|
-
if ( !checklistDetails ) {
|
|
2743
|
-
return res.sendError( 'No data found', 204 );
|
|
2744
|
-
}
|
|
2745
|
-
checklistDetails.coverage = req.body.coverage;
|
|
2746
|
-
checklistDetails.save();
|
|
2747
|
-
let idList;
|
|
2748
|
-
if ( req.body.coverage == 'store' ) {
|
|
2749
|
-
let clusterDetails = await clusterServices.findOneCluster( { _id: req.body.id }, { stores: 1, clusterName: 1 } );
|
|
3100
|
+
async function assignUsers( data ) {
|
|
3101
|
+
let assignedData;
|
|
3102
|
+
if ( data.coverage == 'store' ) {
|
|
3103
|
+
if ( data.type == 'cluster' ) {
|
|
3104
|
+
let clusterDetails = await clusterServices.findOneCluster( { _id: data.id }, { stores: 1, clusterName: 1 } );
|
|
2750
3105
|
if ( clusterDetails ) {
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
3106
|
+
assignedData = {
|
|
3107
|
+
checkFlag: true,
|
|
3108
|
+
checkListId: data.checklistId,
|
|
3109
|
+
checkListName: data.checkListName,
|
|
3110
|
+
client_id: data?.clientId,
|
|
3111
|
+
clusterName: clusterDetails?.clusterName,
|
|
3112
|
+
assignId: data.id,
|
|
3113
|
+
};
|
|
2758
3114
|
}
|
|
2759
|
-
|
|
2760
|
-
|
|
3115
|
+
} else {
|
|
3116
|
+
let storeDetails = await storeService.findOne( { _id: data.id } );
|
|
3117
|
+
if ( storeDetails ) {
|
|
3118
|
+
let userDetails = await userService.findOne( { userEmail: storeDetails?.spocDetails?.email, clientId: data.clientId } );
|
|
2761
3119
|
if ( !userDetails ) {
|
|
2762
|
-
let
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
mobileNumber:
|
|
2766
|
-
|
|
2767
|
-
password: '5dqFKAJj29PsV6P+kL+3Dw==',
|
|
2768
|
-
role: 'user',
|
|
2769
|
-
userType: 'client',
|
|
2770
|
-
rolespermission: [
|
|
2771
|
-
{
|
|
2772
|
-
featureName: 'Global',
|
|
2773
|
-
modules: [
|
|
2774
|
-
{
|
|
2775
|
-
name: 'Store',
|
|
2776
|
-
isAdd: false,
|
|
2777
|
-
isEdit: false,
|
|
2778
|
-
|
|
2779
|
-
},
|
|
2780
|
-
{
|
|
2781
|
-
name: 'User',
|
|
2782
|
-
isAdd: false,
|
|
2783
|
-
isEdit: false,
|
|
2784
|
-
|
|
2785
|
-
},
|
|
2786
|
-
{
|
|
2787
|
-
name: 'Camera',
|
|
2788
|
-
isAdd: false,
|
|
2789
|
-
isEdit: false,
|
|
2790
|
-
|
|
2791
|
-
},
|
|
2792
|
-
{
|
|
2793
|
-
name: 'Configuration',
|
|
2794
|
-
isAdd: false,
|
|
2795
|
-
isEdit: false,
|
|
2796
|
-
|
|
2797
|
-
},
|
|
2798
|
-
{
|
|
2799
|
-
name: 'Subscription',
|
|
2800
|
-
isAdd: false,
|
|
2801
|
-
isEdit: false,
|
|
2802
|
-
|
|
2803
|
-
},
|
|
2804
|
-
{
|
|
2805
|
-
name: 'Billing',
|
|
2806
|
-
isAdd: false,
|
|
2807
|
-
isEdit: false,
|
|
2808
|
-
|
|
2809
|
-
},
|
|
2810
|
-
],
|
|
2811
|
-
},
|
|
2812
|
-
{
|
|
2813
|
-
featurName: 'TangoEye',
|
|
2814
|
-
modules: [
|
|
2815
|
-
{
|
|
2816
|
-
name: 'ZoneTag',
|
|
2817
|
-
isAdd: false,
|
|
2818
|
-
isEdit: false,
|
|
2819
|
-
|
|
2820
|
-
},
|
|
2821
|
-
],
|
|
2822
|
-
},
|
|
2823
|
-
{
|
|
2824
|
-
featurName: 'TangoTrax',
|
|
2825
|
-
modules: [
|
|
2826
|
-
{
|
|
2827
|
-
name: 'checklist',
|
|
2828
|
-
isAdd: false,
|
|
2829
|
-
isEdit: false,
|
|
2830
|
-
|
|
2831
|
-
},
|
|
2832
|
-
{
|
|
2833
|
-
name: 'Task',
|
|
2834
|
-
isAdd: false,
|
|
2835
|
-
isEdit: false,
|
|
2836
|
-
|
|
2837
|
-
},
|
|
2838
|
-
],
|
|
2839
|
-
},
|
|
2840
|
-
],
|
|
3120
|
+
let userData = {
|
|
3121
|
+
userName: storeDetails.spocDetails?.[0]?.name,
|
|
3122
|
+
email: storeDetails.spocDetails[0].email,
|
|
3123
|
+
mobileNumber: storeDetails.spocDetails?.[0]?.phone,
|
|
3124
|
+
clientId: data.clientId,
|
|
2841
3125
|
};
|
|
2842
|
-
|
|
3126
|
+
createUser( userData );
|
|
2843
3127
|
}
|
|
2844
|
-
|
|
2845
|
-
store_id:
|
|
2846
|
-
storeName:
|
|
3128
|
+
assignedData = {
|
|
3129
|
+
store_id: storeDetails.storeId,
|
|
3130
|
+
storeName: storeDetails.storeName,
|
|
2847
3131
|
userId: userDetails._id,
|
|
2848
3132
|
userName: userDetails.userName,
|
|
2849
3133
|
userEmail: userDetails.email,
|
|
2850
3134
|
userPhone: userDetails?.mobileNumber,
|
|
2851
|
-
city:
|
|
2852
|
-
country:
|
|
3135
|
+
city: storeDetails?.storeProfile?.city,
|
|
3136
|
+
country: storeDetails?.storeprofile?.country,
|
|
2853
3137
|
checkFlag: true,
|
|
2854
|
-
checkListId:
|
|
2855
|
-
checkListName:
|
|
2856
|
-
client_id:
|
|
2857
|
-
|
|
2858
|
-
assignId: req.body.id,
|
|
3138
|
+
checkListId: data.checklistId,
|
|
3139
|
+
checkListName: data.checkListName,
|
|
3140
|
+
client_id: data.clientId,
|
|
3141
|
+
assignId: data.id,
|
|
2859
3142
|
};
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
let teamDetails = await teamsServices.findOneTeams( { _id:
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
} else {
|
|
3146
|
+
if ( data.type == 'teams' ) {
|
|
3147
|
+
let teamDetails = await teamsServices.findOneTeams( { _id: data.id }, { users: 1, teamName: 1 } );
|
|
2865
3148
|
if ( teamDetails ) {
|
|
2866
|
-
|
|
2867
|
-
} else {
|
|
2868
|
-
idList = [ new ObjectId( req.body.id ) ];
|
|
2869
|
-
}
|
|
2870
|
-
let userDetails = await userService.find( { _id: { $in: idList } } );
|
|
2871
|
-
if ( !userDetails.length ) {
|
|
2872
|
-
return res.sendError( 'No data found', 204 );
|
|
2873
|
-
}
|
|
2874
|
-
let assignList = [];
|
|
2875
|
-
userDetails.forEach( ( user ) => {
|
|
2876
|
-
assignList.push( {
|
|
2877
|
-
userId: user._id,
|
|
2878
|
-
userName: user.userName,
|
|
2879
|
-
userEmail: user.email,
|
|
2880
|
-
userPhone: user?.mobileNumber,
|
|
3149
|
+
assignedData = {
|
|
2881
3150
|
checkFlag: true,
|
|
2882
|
-
checkListId:
|
|
2883
|
-
checkListName:
|
|
2884
|
-
client_id:
|
|
3151
|
+
checkListId: data.checklistId,
|
|
3152
|
+
checkListName: data.checkListName,
|
|
3153
|
+
client_id: data.clientId,
|
|
2885
3154
|
teamName: teamDetails?.teamName,
|
|
2886
|
-
assignId:
|
|
2887
|
-
}
|
|
2888
|
-
}
|
|
2889
|
-
|
|
3155
|
+
assignId: data.id,
|
|
3156
|
+
};
|
|
3157
|
+
}
|
|
3158
|
+
} else {
|
|
3159
|
+
let userDetails = await userService.findOne( { _id: { $in: data.id } } );
|
|
3160
|
+
if ( userDetails ) {
|
|
3161
|
+
assignedData = {
|
|
3162
|
+
userId: userDetails._id,
|
|
3163
|
+
userName: userDetails.userName,
|
|
3164
|
+
userEmail: userDetails.email,
|
|
3165
|
+
userPhone: userDetails?.mobileNumber,
|
|
3166
|
+
checkFlag: true,
|
|
3167
|
+
checkListId: data.checklistId,
|
|
3168
|
+
checkListName: data.checkListName,
|
|
3169
|
+
client_id: data.clientId,
|
|
3170
|
+
assignId: data.id,
|
|
3171
|
+
};
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
await assignedService.create( assignedData );
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3178
|
+
export async function checklistAssign( req, res ) {
|
|
3179
|
+
try {
|
|
3180
|
+
if ( !req.body.type ) {
|
|
3181
|
+
return res.sendError( 'Type is required', 400 );
|
|
2890
3182
|
}
|
|
3183
|
+
if ( !req.body.coverage ) {
|
|
3184
|
+
return res.sendError( 'coverage is required', 400 );
|
|
3185
|
+
}
|
|
3186
|
+
if ( !req.body.id ) {
|
|
3187
|
+
return res.sendError( 'coverage is required', 400 );
|
|
3188
|
+
}
|
|
3189
|
+
if ( !req.body.checklistId ) {
|
|
3190
|
+
return res.sendError( 'Checklist id is required', 400 );
|
|
3191
|
+
}
|
|
3192
|
+
if ( !req.body.clientId ) {
|
|
3193
|
+
return res.sendError( 'Client id is required', 400 );
|
|
3194
|
+
}
|
|
3195
|
+
let checklistDetails = await checklistService.findOne( { _id: req.body.checklistId } );
|
|
3196
|
+
if ( !checklistDetails ) {
|
|
3197
|
+
return res.sendError( 'No data found', 204 );
|
|
3198
|
+
}
|
|
3199
|
+
req.body.checkListName = checklistDetails.checkListName;
|
|
3200
|
+
await assignUsers( req.body );
|
|
2891
3201
|
return res.sendSuccess( 'Details updated successfully' );
|
|
2892
3202
|
} catch ( e ) {
|
|
2893
3203
|
logger.error( { functionName: 'checklistAssign', error: e } );
|
|
@@ -2914,3 +3224,20 @@ export async function removeAssign( req, res ) {
|
|
|
2914
3224
|
return res.sendError( e, 500 );
|
|
2915
3225
|
}
|
|
2916
3226
|
}
|
|
3227
|
+
|
|
3228
|
+
export async function deleteAssignList( req, res ) {
|
|
3229
|
+
try {
|
|
3230
|
+
if ( !req.body.checkListId ) {
|
|
3231
|
+
return res.sendError( 'Checklist id is required', 400 );
|
|
3232
|
+
}
|
|
3233
|
+
let checklistDetails = await checklistService.findOne( { _id: req.body.checkListId, isdeleted: false } );
|
|
3234
|
+
if ( !checklistDetails ) {
|
|
3235
|
+
return res.sendError( 'No data found', 204 );
|
|
3236
|
+
}
|
|
3237
|
+
await assignedService.updateMany( { checkListId: req.body.checkListId }, { isdeleted: true } );
|
|
3238
|
+
return res.sendSuccess( 'Assign details removed successfully' );
|
|
3239
|
+
} catch ( e ) {
|
|
3240
|
+
logger.error( { functionName: 'deleteAssignList', error: e } );
|
|
3241
|
+
return res.sendError( e, 500 );
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
@@ -16,6 +16,7 @@ traxRouter
|
|
|
16
16
|
.post( '/validateUser', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), validate( uploadUserValidation ), traxController.validateUser )
|
|
17
17
|
.get( '/userDetails/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( duplicateValidation ), traxController.assignedUserDetails )
|
|
18
18
|
.post( '/checklistConfigure', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), traxController.updateConfigure )
|
|
19
|
+
.post( '/checklistConfigurev1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), traxController.updateConfigurev1 )
|
|
19
20
|
.delete( '/deleteChecklist/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), validate( duplicateValidation ), traxController.deleteChecklist )
|
|
20
21
|
.put( '/publish', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), validate( publishValidation ), traxController.updatePublish )
|
|
21
22
|
.get( '/userList', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), traxController.userlist )
|
|
@@ -25,6 +26,7 @@ traxRouter
|
|
|
25
26
|
.post( '/selectAssign', validate( selectAssign ), traxController.selectAssign )
|
|
26
27
|
.get( '/checklistV2', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( checklistPageSchema ), traxController.checklistV2 )
|
|
27
28
|
.post( '/assign', isAllowedSessionHandler, traxController.checklistAssign )
|
|
28
|
-
.post( '/remove', isAllowedSessionHandler, traxController.removeAssign )
|
|
29
|
+
.post( '/remove', isAllowedSessionHandler, traxController.removeAssign )
|
|
30
|
+
.post( '/removeAssignList', isAllowedSessionHandler, traxController.deleteAssignList );
|
|
29
31
|
|
|
30
32
|
// isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ),
|