tango-app-api-task 3.2.1-beta-31 → 3.2.1-beta-32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/controllers/task.controller.js +365 -557
- package/src/dtos/task.dto.js +0 -13
- package/src/routes/task.routes.js +5 -5
package/package.json
CHANGED
|
@@ -264,9 +264,29 @@ export async function taskDetails( req, res ) {
|
|
|
264
264
|
}
|
|
265
265
|
if ( storechecklistdetails ) {
|
|
266
266
|
result.checkListDetails = { ...storechecklistdetails._doc };
|
|
267
|
-
let
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
let query = {
|
|
268
|
+
checkListId: storechecklistdetails._id,
|
|
269
|
+
...( storechecklistdetails.coverage == 'store' ) ? { $or: [ { store_id: { $exists: true } }, { clusterName: { $exists: true } } ] } : { $or: [ { userEmail: { $exists: true } }, { teamName: { $exists: true } } ] },
|
|
270
|
+
};
|
|
271
|
+
let assignList = await taskAssignService.find( query, { _id: 1, store_id: 1, clusterName: 1, userEmail: 1, teamName: 1, assignId: 1 } );
|
|
272
|
+
let singleAssign;
|
|
273
|
+
let groupAssign;
|
|
274
|
+
if ( storechecklistdetails.coverage == 'store' ) {
|
|
275
|
+
singleAssign = assignList.filter( ( item ) => typeof item?.store_id != 'undefined' && item?.store_id != '' ).map( ( item ) => {
|
|
276
|
+
return { id: item.assignId, type: 'store' };
|
|
277
|
+
} );
|
|
278
|
+
groupAssign = assignList.filter( ( item ) => typeof item?.clusterName != 'undefined' && item?.clusterName != '' ).map( ( item ) => {
|
|
279
|
+
return { id: item.assignId, type: 'cluster' };
|
|
280
|
+
} );
|
|
281
|
+
} else {
|
|
282
|
+
singleAssign = assignList.filter( ( item ) => typeof item?.userEmail != 'undefined' && item?.userEmail !='' ).map( ( item ) => {
|
|
283
|
+
return { id: item.assignId, type: 'user' };
|
|
284
|
+
} );
|
|
285
|
+
groupAssign = assignList.filter( ( item ) => typeof item?.teamName != 'undefined' && item?.teamName != '' ).map( ( item ) => {
|
|
286
|
+
return { id: item.assignId, type: 'teams' };
|
|
287
|
+
} );
|
|
288
|
+
}
|
|
289
|
+
result.checkListDetails = { ...result.checkListDetails, ...{ sections: sectionList }, singleAssign, groupAssign };
|
|
270
290
|
}
|
|
271
291
|
return res.sendSuccess( result );
|
|
272
292
|
} catch ( e ) {
|
|
@@ -435,6 +455,179 @@ export async function validateUser( req, res ) {
|
|
|
435
455
|
}
|
|
436
456
|
};
|
|
437
457
|
|
|
458
|
+
export const validateUserv1 = async ( req, res ) => {
|
|
459
|
+
try {
|
|
460
|
+
if ( !req.body.assignedUsers.length ) {
|
|
461
|
+
return res.sendError( 'Please Enter user Details', 400 );
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
let assignDetails = req.body.assignedUsers;
|
|
465
|
+
|
|
466
|
+
if ( req.body.coverage == 'store' ) {
|
|
467
|
+
const duplicateStore = assignDetails.reduce( ( acc, obj ) => {
|
|
468
|
+
if ( !acc[obj.storeName.toLowerCase()] ) {
|
|
469
|
+
acc[obj.storeName.toLowerCase()] = {
|
|
470
|
+
email: [ obj.userEmail.toLowerCase() ],
|
|
471
|
+
count: 1,
|
|
472
|
+
};
|
|
473
|
+
} else {
|
|
474
|
+
if ( acc[obj.storeName.toLowerCase()] ) {
|
|
475
|
+
if ( acc[obj.storeName.toLowerCase()].email.includes( obj.userEmail.toLowerCase() ) ) {
|
|
476
|
+
acc[obj.storeName.toLowerCase()].count++;
|
|
477
|
+
} else {
|
|
478
|
+
acc[obj.storeName.toLowerCase()].email.push( obj.userEmail.toLowerCase() );
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return acc;
|
|
483
|
+
}, {} );
|
|
484
|
+
|
|
485
|
+
const duplicateStores = Object.keys( duplicateStore ).filter( ( storeName ) => duplicateStore[storeName].count > 1 );
|
|
486
|
+
if ( duplicateStores.length ) {
|
|
487
|
+
return res.sendSuccess( { validate: false, ExistsEmail: duplicateStores, message: 'Store and email is duplicated' } );
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
const duplicateUser = assignDetails.reduce( ( acc, obj ) => {
|
|
491
|
+
if ( !acc[obj.userEmail.toLowerCase()] ) {
|
|
492
|
+
acc[obj.userEmail.toLowerCase()] = {
|
|
493
|
+
name: [ obj.userName.toLowerCase() ],
|
|
494
|
+
count: 1,
|
|
495
|
+
};
|
|
496
|
+
} else {
|
|
497
|
+
if ( acc[obj.userEmail.toLowerCase()] ) {
|
|
498
|
+
if ( acc[obj.userEmail.toLowerCase()].name.includes( obj.userName.toLowerCase() ) ) {
|
|
499
|
+
acc[obj.userEmail.toLowerCase()].count++;
|
|
500
|
+
} else {
|
|
501
|
+
acc[obj.userEmail.toLowerCase()].name.push( obj.userEmail.toLowerCase() );
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return acc;
|
|
506
|
+
}, {} );
|
|
507
|
+
|
|
508
|
+
const duplicateUsers = Object.keys( duplicateUser ).filter( ( storeName ) => duplicateUser[storeName].count > 1 );
|
|
509
|
+
if ( duplicateUsers.length ) {
|
|
510
|
+
return res.sendSuccess( { validate: false, ExistsEmail: duplicateUsers, message: 'Email is Duplicated' } );
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if ( req.body.hasOwnProperty( 'addSingle' ) ) {
|
|
515
|
+
let checkExists = await taskAssignService.findOne( { userEmail: assignDetails[0]?.userEmail, storeName: assignDetails[0]?.storeName, checkListId: req.body.id } );
|
|
516
|
+
if ( checkExists ) {
|
|
517
|
+
return res.sendError( 'User already Exists', 400 );
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
let userEmailList = assignDetails.map( ( item ) => item.userEmail.toLowerCase() );
|
|
522
|
+
let storeList = assignDetails.map( ( item ) => item?.storeName?.toLowerCase() );
|
|
523
|
+
|
|
524
|
+
let userQuery = [
|
|
525
|
+
{
|
|
526
|
+
$project: {
|
|
527
|
+
newEmail: { $toLower: '$email' },
|
|
528
|
+
isActive: 1,
|
|
529
|
+
clientId: 1,
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
$match: {
|
|
534
|
+
newEmail: { $in: userEmailList },
|
|
535
|
+
isActive: true,
|
|
536
|
+
clientId: req.body.clientId,
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
];
|
|
540
|
+
|
|
541
|
+
let emailCheckQuery = [
|
|
542
|
+
{
|
|
543
|
+
$project: {
|
|
544
|
+
newEmail: { $toLower: '$email' },
|
|
545
|
+
isActive: 1,
|
|
546
|
+
clientId: 1,
|
|
547
|
+
},
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
$match: {
|
|
551
|
+
newEmail: { $in: userEmailList },
|
|
552
|
+
isActive: true,
|
|
553
|
+
clientId: { $ne: req.body.clientId },
|
|
554
|
+
},
|
|
555
|
+
},
|
|
556
|
+
];
|
|
557
|
+
|
|
558
|
+
let storeQuery = [
|
|
559
|
+
{
|
|
560
|
+
$project: {
|
|
561
|
+
'storeName': { $toLower: '$storeName' },
|
|
562
|
+
'clientId': 1,
|
|
563
|
+
'storeProfile.city': 1,
|
|
564
|
+
'status': 1,
|
|
565
|
+
'storeId': 1,
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
$match: {
|
|
570
|
+
clientId: req.body.clientId,
|
|
571
|
+
storeName: { $in: storeList },
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
];
|
|
575
|
+
|
|
576
|
+
let [ userDetails, storeDetails, existEmail ] = await Promise.all( [
|
|
577
|
+
await userService.aggregate( userQuery ),
|
|
578
|
+
await storeService.aggregate( storeQuery ),
|
|
579
|
+
await userService.aggregate( emailCheckQuery ),
|
|
580
|
+
] );
|
|
581
|
+
|
|
582
|
+
existEmail = existEmail.map( ( ele ) => ele.newEmail );
|
|
583
|
+
let existUserEmail = userDetails.map( ( ele ) => ele.newEmail );
|
|
584
|
+
let newUserList = userEmailList.filter( ( ele ) => !existUserEmail.includes( ele ) && !existEmail.includes( ele ) );
|
|
585
|
+
let inActiveStores = storeDetails.filter( ( ele ) => ele.status == 'deactive' ).map( ( ele ) => ele.storeName );
|
|
586
|
+
|
|
587
|
+
let existsStore = storeDetails.map( ( ele ) => ele?.storeName );
|
|
588
|
+
let newStoreList = storeList.filter( ( ele ) => ele != null && !existsStore.includes( ele.toLowerCase() ) );
|
|
589
|
+
if ( req.body.coverage == 'store' ) {
|
|
590
|
+
assignDetails.forEach( ( item ) => {
|
|
591
|
+
let getStoreId = storeDetails.find( ( store ) => store.storeName.toLowerCase() == item.storeName.toLowerCase() );
|
|
592
|
+
if ( getStoreId ) {
|
|
593
|
+
item._id = getStoreId._id;
|
|
594
|
+
item.storeId = getStoreId.storeId;
|
|
595
|
+
}
|
|
596
|
+
} );
|
|
597
|
+
} else {
|
|
598
|
+
assignDetails.forEach( ( item ) => {
|
|
599
|
+
let getUserId = userDetails.find( ( user ) => user.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
|
|
600
|
+
if ( getUserId ) {
|
|
601
|
+
item._id = getUserId._id;
|
|
602
|
+
}
|
|
603
|
+
} );
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
if ( ( newUserList.length || newStoreList.length || existEmail.length || inActiveStores.length ) && !req.body?.addUser ) {
|
|
607
|
+
return res.sendError( { validate: false, user: newUserList, store: newStoreList, existEmail, inActiveStores, data: assignDetails }, 400 );
|
|
608
|
+
}
|
|
609
|
+
if ( req.body.coverage == 'user' ) {
|
|
610
|
+
await Promise.all( newUserList.map( async ( ele ) => {
|
|
611
|
+
let findUserIndex = assignDetails.findIndex( ( item ) => item?.userEmail?.toLowerCase() == ele?.toLowerCase() );
|
|
612
|
+
if ( findUserIndex != -1 ) {
|
|
613
|
+
let data = {
|
|
614
|
+
userName: assignDetails[findUserIndex]?.userName,
|
|
615
|
+
email: ele,
|
|
616
|
+
mobileNumber: assignDetails[findUserIndex]?.mobileNumber,
|
|
617
|
+
clientId: req.body.clientId,
|
|
618
|
+
};
|
|
619
|
+
let response = await createUser( data );
|
|
620
|
+
assignDetails[findUserIndex]._id = response._id;
|
|
621
|
+
}
|
|
622
|
+
} ) );
|
|
623
|
+
}
|
|
624
|
+
return res.sendSuccess( { validate: true, data: assignDetails } );
|
|
625
|
+
} catch ( e ) {
|
|
626
|
+
logger.error( 'validateUser 2=>', e );
|
|
627
|
+
return res.sendError( e, 500 );
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
|
|
438
631
|
async function uploadUser( req, res ) {
|
|
439
632
|
try {
|
|
440
633
|
let inputBody = req.body;
|
|
@@ -565,45 +758,29 @@ export async function userDetails( req, res ) {
|
|
|
565
758
|
if ( !req.query.taskId ) {
|
|
566
759
|
return res.sendError( { message: 'Task Id is required' }, 400 );
|
|
567
760
|
}
|
|
761
|
+
// let limit = parseInt( req.query.limit ) || 5;
|
|
762
|
+
// let page = parseInt( req.query.offset ) || 0;
|
|
763
|
+
// let skip = limit * page;
|
|
568
764
|
|
|
569
|
-
let query = [ { $match: { checkListId: new ObjectId( req.query.taskId ),
|
|
570
|
-
if ( req.query?.search?.trim() && req.query?.search?.trim() != '' ) {
|
|
571
|
-
let searchValue = req.query.search;
|
|
572
|
-
searchValue = searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
|
|
573
|
-
if ( searchValue.length > 1 ) {
|
|
574
|
-
query.push( { $addFields: { storeLower: { $toLower: '$storeName' } } } );
|
|
575
|
-
query.push( { $match: { storeLower: { $in: searchValue } } } );
|
|
576
|
-
} else {
|
|
577
|
-
query.push( { $match: { storeName: { $regex: req.query.search.trim(), $options: 'i' } } } );
|
|
578
|
-
}
|
|
579
|
-
}
|
|
765
|
+
let query = [ { $match: { checkListId: new ObjectId( req.query.taskId ), isdeleted: false } }, { $sort: { _id: -1 } } ];
|
|
580
766
|
|
|
581
767
|
let taskDetails = await taskAssignService.aggregate( query );
|
|
582
|
-
|
|
583
|
-
if ( !taskDetails[0].data.length ) {
|
|
768
|
+
if ( !taskDetails.length ) {
|
|
584
769
|
return res.sendError( 'No data found', 204 );
|
|
585
770
|
}
|
|
586
771
|
|
|
587
772
|
let userDetails = [];
|
|
588
|
-
let storeList = [];
|
|
589
|
-
let userList = [];
|
|
590
773
|
await Promise.all( taskDetails.map( async ( ele ) => {
|
|
591
|
-
if ( ele?.store_id || ele?.clusterName ) {
|
|
592
|
-
storeList.push( ele.assignId );
|
|
593
|
-
} else {
|
|
594
|
-
userList.push( ele.assignId );
|
|
595
|
-
}
|
|
596
|
-
|
|
597
774
|
if ( ele?.clusterName ) {
|
|
598
775
|
let clusterDetails = await clusterServices.findOneCluster( { _id: ele.assignId }, { stores: 1 } );
|
|
599
776
|
if ( clusterDetails ) {
|
|
600
777
|
let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) }, status: 'active' } );
|
|
601
778
|
storeDetails.forEach( ( item ) => {
|
|
602
779
|
userDetails.push( {
|
|
603
|
-
|
|
780
|
+
_id: ele.assignId,
|
|
604
781
|
userName: item.spocDetails?.[0]?.name,
|
|
605
782
|
userEmail: item.spocDetails?.[0]?.email,
|
|
606
|
-
|
|
783
|
+
storeId: item?.storeId,
|
|
607
784
|
storeName: item?.storeName,
|
|
608
785
|
userPhone: item.spocDetails?.[0]?.phone,
|
|
609
786
|
city: ele?.city,
|
|
@@ -619,10 +796,10 @@ export async function userDetails( req, res ) {
|
|
|
619
796
|
let teamUserDetails = await userService.find( { _id: { $in: teamDetails.users.map( ( item ) => item.userId ) } } );
|
|
620
797
|
teamUserDetails.forEach( ( item ) => {
|
|
621
798
|
userDetails.push( {
|
|
622
|
-
|
|
799
|
+
_id: ele.assignId,
|
|
623
800
|
userName: item.userName,
|
|
624
801
|
userEmail: item.email,
|
|
625
|
-
|
|
802
|
+
storeId: ele?.storeId,
|
|
626
803
|
storeName: ele?.storeName,
|
|
627
804
|
userPhone: item?.mobileNumber,
|
|
628
805
|
city: ele?.city,
|
|
@@ -634,10 +811,10 @@ export async function userDetails( req, res ) {
|
|
|
634
811
|
}
|
|
635
812
|
} else {
|
|
636
813
|
userDetails.push( {
|
|
637
|
-
|
|
814
|
+
_id: ele.assignId,
|
|
638
815
|
userName: ele.userName,
|
|
639
816
|
userEmail: ele.userEmail,
|
|
640
|
-
|
|
817
|
+
storeId: ele?.store_id,
|
|
641
818
|
storeName: ele?.storeName,
|
|
642
819
|
userPhone: ele.userPhone,
|
|
643
820
|
city: ele.city,
|
|
@@ -648,9 +825,9 @@ export async function userDetails( req, res ) {
|
|
|
648
825
|
}
|
|
649
826
|
} ) );
|
|
650
827
|
|
|
651
|
-
return res.sendSuccess( { count: userDetails.length,
|
|
828
|
+
return res.sendSuccess( { count: userDetails.length, userDetails } );
|
|
652
829
|
} catch ( e ) {
|
|
653
|
-
logger.error(
|
|
830
|
+
logger.error( 'userDetails =>', e );
|
|
654
831
|
return res.sendError( e, 500 );
|
|
655
832
|
}
|
|
656
833
|
};
|
|
@@ -729,20 +906,6 @@ export async function taskConfig( req, res ) {
|
|
|
729
906
|
await traxApprover.insertMany( data );
|
|
730
907
|
}
|
|
731
908
|
}
|
|
732
|
-
if ( inputBody.assignedUsers.length ) {
|
|
733
|
-
await taskAssignService.deleteMany( { checkListId: inputBody._id } );
|
|
734
|
-
await Promise.all( inputBody.assignedUsers.map( async ( user ) => {
|
|
735
|
-
let data = {
|
|
736
|
-
...user,
|
|
737
|
-
clientId: req.body.clientId,
|
|
738
|
-
checkListName: checklistDetails.checkListName,
|
|
739
|
-
checklistId: checklistDetails._id,
|
|
740
|
-
coverage: inputBody.coverage,
|
|
741
|
-
insert: true,
|
|
742
|
-
};
|
|
743
|
-
await assignUsers( data );
|
|
744
|
-
} ) );
|
|
745
|
-
}
|
|
746
909
|
let storeConfigDetails = await taskAssignService.find( { checkListId: inputBody._id, checkFlag: true }, { _id: 0, store_id: 1, userEmail: 1, storeName: 1 } );
|
|
747
910
|
if ( inputBody.submitType == 'publish' ) {
|
|
748
911
|
let taskName = checklistDetails.checkListName;
|
|
@@ -916,6 +1079,10 @@ export async function insertSingleProcessData( checklistId ) {
|
|
|
916
1079
|
|
|
917
1080
|
async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date, startTimeIso, endTimeIso, insertdata ) {
|
|
918
1081
|
let getquestionQuery = [];
|
|
1082
|
+
if ( dayjs( getCLconfig.publishDate ).format( 'YYYY-MM-DD' ) != dayjs( date ).format( 'YYYY-MM-DD' ) ) {
|
|
1083
|
+
let todayDate = `${dayjs( date ).format( 'YYYY-MM-DD' )} 00:00 AM`;
|
|
1084
|
+
startTimeIso = dayjs( todayDate, 'YYYY-MM-DD HH:mm A' );
|
|
1085
|
+
}
|
|
919
1086
|
getquestionQuery.push( {
|
|
920
1087
|
$match: {
|
|
921
1088
|
checkListId: new ObjectId( checklistId ),
|
|
@@ -2649,212 +2816,6 @@ export async function StoreHygienetask( req, res ) {
|
|
|
2649
2816
|
return res.sendError( e, 500 );
|
|
2650
2817
|
}
|
|
2651
2818
|
}
|
|
2652
|
-
export async function commonAiTask( req, res ) {
|
|
2653
|
-
try {
|
|
2654
|
-
let inputBody = req.body;
|
|
2655
|
-
|
|
2656
|
-
inputBody.clientId = 11;
|
|
2657
|
-
inputBody.taskDescription = '';
|
|
2658
|
-
let userId;
|
|
2659
|
-
let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
|
|
2660
|
-
if ( !storeDetails ) {
|
|
2661
|
-
return res.sendError( 'Store Not Found', 500 );
|
|
2662
|
-
}
|
|
2663
|
-
|
|
2664
|
-
let url = JSON.parse( process.env.LAMBDAURL );
|
|
2665
|
-
let checklistId = url.dailystoreChecklistId;
|
|
2666
|
-
let finduser = await checklistassignconfigModel.findOne( { checkListId: new mongoose.Types.ObjectId( checklistId ), store_id: storeDetails.storeId } );
|
|
2667
|
-
|
|
2668
|
-
if ( !finduser ) {
|
|
2669
|
-
return res.sendError( 'No user Found For this store', 500 );
|
|
2670
|
-
}
|
|
2671
|
-
|
|
2672
|
-
userId = finduser.userId;
|
|
2673
|
-
inputBody.userName = finduser.userName;
|
|
2674
|
-
inputBody.userEmail = finduser.userEmail;
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
let teamList = await findteams( { users: { $elemMatch: { email: finduser.userEmail } } } );
|
|
2678
|
-
|
|
2679
|
-
inputBody.approver = '';
|
|
2680
|
-
for ( let team of teamList ) {
|
|
2681
|
-
for ( let user of team.Teamlead ) {
|
|
2682
|
-
inputBody.approver = user.email + ',' + inputBody.approver;
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2685
|
-
inputBody.approver = inputBody.approver.replace( /,$/, '' );
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
|
|
2689
|
-
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
2690
|
-
let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
|
|
2691
|
-
let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
|
|
2692
|
-
if ( userDetails&&userDetails.fcmToken ) {
|
|
2693
|
-
const fcmToken = userDetails.fcmToken;
|
|
2694
|
-
await sendPushNotification( title, description, fcmToken );
|
|
2695
|
-
}
|
|
2696
|
-
const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
|
|
2697
|
-
const currentTime = dayjs.utc();
|
|
2698
|
-
if ( inputDateTime.isBefore( currentTime ) ) {
|
|
2699
|
-
return res.sendError( 'The input date-time is before the current time.', 500 );
|
|
2700
|
-
}
|
|
2701
|
-
|
|
2702
|
-
let approverList = inputBody?.approver.split( ',' );
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
|
|
2706
|
-
|
|
2707
|
-
if ( userAdmin && userAdmin.length === 0 ) {
|
|
2708
|
-
userAdmin = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
|
|
2709
|
-
}
|
|
2710
|
-
|
|
2711
|
-
let creator = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true } );
|
|
2712
|
-
if ( creator && creator.length === 0 ) {
|
|
2713
|
-
return res.sendError( 'Invalid Creator Details', 500 );
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
|
|
2717
|
-
return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
|
|
2718
|
-
}
|
|
2719
|
-
let data = {
|
|
2720
|
-
checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )})`,
|
|
2721
|
-
checkListDescription: inputBody.taskDescription,
|
|
2722
|
-
createdBy: creator[0]._id,
|
|
2723
|
-
createdByName: creator[0].userName,
|
|
2724
|
-
publish: true,
|
|
2725
|
-
questionCount: 1,
|
|
2726
|
-
storeCount: 1,
|
|
2727
|
-
scheduleDate: date,
|
|
2728
|
-
scheduleEndTime: time,
|
|
2729
|
-
scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
|
|
2730
|
-
priorityType: 'high',
|
|
2731
|
-
client_id: inputBody.clientId,
|
|
2732
|
-
checkListType: 'task',
|
|
2733
|
-
publishDate: new Date(),
|
|
2734
|
-
locationCount: 1,
|
|
2735
|
-
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
2736
|
-
};
|
|
2737
|
-
data['approver'] = userAdmin;
|
|
2738
|
-
let answer = await findAnswer( inputBody?.answerType );
|
|
2739
|
-
if ( answer.length == 0 ) {
|
|
2740
|
-
return res.sendError( 'please enter Valid AnswerType', 500 );
|
|
2741
|
-
}
|
|
2742
|
-
if ( inputBody?.answerType === 'multiplechoicesingle' || inputBody?.answerType === 'multiplechoicemultiple' ) {
|
|
2743
|
-
if ( inputBody?.options && inputBody?.options.length > 0 ) {
|
|
2744
|
-
let optionsResult = [];
|
|
2745
|
-
let optionList = inputBody?.options.split( ',' );
|
|
2746
|
-
for ( let option of optionList ) {
|
|
2747
|
-
let optiondata = {
|
|
2748
|
-
'answer': '',
|
|
2749
|
-
'sopFlag': false,
|
|
2750
|
-
'validation': false,
|
|
2751
|
-
'validationType': '',
|
|
2752
|
-
'referenceImage': [],
|
|
2753
|
-
'runAI': false,
|
|
2754
|
-
'allowUploadfromGallery': false,
|
|
2755
|
-
'descriptivetype': '',
|
|
2756
|
-
'showLinked': false,
|
|
2757
|
-
'linkedQuestion': 0,
|
|
2758
|
-
'nestedQuestion': [],
|
|
2759
|
-
};
|
|
2760
|
-
optiondata.answer = option;
|
|
2761
|
-
optionsResult.push( optiondata );
|
|
2762
|
-
}
|
|
2763
|
-
answer = optionsResult;
|
|
2764
|
-
} else {
|
|
2765
|
-
return res.sendError( 'please enter Valid Options', 500 );
|
|
2766
|
-
}
|
|
2767
|
-
}
|
|
2768
|
-
let response = await taskService.create( data );
|
|
2769
|
-
if ( response?.approver.length ) {
|
|
2770
|
-
let inputData = [];
|
|
2771
|
-
response?.approver.forEach( ( ele ) => {
|
|
2772
|
-
inputData.push( {
|
|
2773
|
-
userEmail: ele.email,
|
|
2774
|
-
checkListId: response._id,
|
|
2775
|
-
type: 'task',
|
|
2776
|
-
client_id: inputBody.clientId,
|
|
2777
|
-
checkListName: data?.checkListName || '',
|
|
2778
|
-
} );
|
|
2779
|
-
} );
|
|
2780
|
-
await traxApprover.insertMany( inputData );
|
|
2781
|
-
}
|
|
2782
|
-
if ( response?._id ) {
|
|
2783
|
-
let question = [
|
|
2784
|
-
{
|
|
2785
|
-
'qno': 1,
|
|
2786
|
-
'qname': inputBody.question,
|
|
2787
|
-
'answerType': inputBody?.answerType || 'yes/no',
|
|
2788
|
-
'runAI': false,
|
|
2789
|
-
'runAIDescription': '',
|
|
2790
|
-
'allowUploadfromGallery': false,
|
|
2791
|
-
'linkType': false,
|
|
2792
|
-
'questionReferenceImage': [],
|
|
2793
|
-
'answers': answer,
|
|
2794
|
-
'descriptivetype': 'text',
|
|
2795
|
-
},
|
|
2796
|
-
];
|
|
2797
|
-
let images = [];
|
|
2798
|
-
for ( let imgpath of req.body.referenceImage ) {
|
|
2799
|
-
let configURL = JSON.parse( process.env.BUCKET );
|
|
2800
|
-
let inputData = {
|
|
2801
|
-
Bucket: configURL.commonAiTaskBucket,
|
|
2802
|
-
Key: imgpath,
|
|
2803
|
-
};
|
|
2804
|
-
let output = await getObject( inputData );
|
|
2805
|
-
console.log( output );
|
|
2806
|
-
|
|
2807
|
-
let image = {
|
|
2808
|
-
data: output.Body,
|
|
2809
|
-
name: imgpath,
|
|
2810
|
-
mimetype: output.ContentType,
|
|
2811
|
-
};
|
|
2812
|
-
let uplaodedImage = await uploadmultiImage( image );
|
|
2813
|
-
|
|
2814
|
-
let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
|
|
2815
|
-
let url = imgUrl.split( '/' );
|
|
2816
|
-
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
2817
|
-
url.splice( 0, 3 );
|
|
2818
|
-
}
|
|
2819
|
-
images.push( url.join( '/' ) );
|
|
2820
|
-
}
|
|
2821
|
-
question[0].questionReferenceImage = images;
|
|
2822
|
-
|
|
2823
|
-
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
2824
|
-
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
2825
|
-
}
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
question = {
|
|
2829
|
-
checkListId: response?._id,
|
|
2830
|
-
question: question,
|
|
2831
|
-
section: 'Section 1',
|
|
2832
|
-
checkList: data.checkListName,
|
|
2833
|
-
client_id: inputBody.clientId,
|
|
2834
|
-
};
|
|
2835
|
-
await taskQuestionService.create( question );
|
|
2836
|
-
|
|
2837
|
-
let userDetails = {
|
|
2838
|
-
userName: inputBody.userName,
|
|
2839
|
-
userEmail: inputBody.userEmail,
|
|
2840
|
-
store_id: storeDetails.storeId,
|
|
2841
|
-
storeName: storeDetails.storeName,
|
|
2842
|
-
city: storeDetails?.storeProfile?.city,
|
|
2843
|
-
checkFlag: true,
|
|
2844
|
-
checkListId: response?._id,
|
|
2845
|
-
checkListName: data.checkListName,
|
|
2846
|
-
client_id: inputBody.clientId,
|
|
2847
|
-
userId: userId,
|
|
2848
|
-
};
|
|
2849
|
-
await taskAssignService.create( userDetails );
|
|
2850
|
-
await insertSingleProcessData( response?._id );
|
|
2851
|
-
return res.sendSuccess( 'Task created successfully' );
|
|
2852
|
-
}
|
|
2853
|
-
} catch ( e ) {
|
|
2854
|
-
logger.error( { function: 'commonAiTask', error: e } );
|
|
2855
|
-
return res.sendError( e, 500 );
|
|
2856
|
-
}
|
|
2857
|
-
}
|
|
2858
2819
|
export async function eyeTesttask( req, res ) {
|
|
2859
2820
|
try {
|
|
2860
2821
|
let inputBody = req.body;
|
|
@@ -3102,14 +3063,14 @@ export async function createAiTask( req, res ) {
|
|
|
3102
3063
|
inputBody.userEmail = finduser.userEmail;
|
|
3103
3064
|
|
|
3104
3065
|
|
|
3105
|
-
let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
|
|
3066
|
+
// let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
|
|
3106
3067
|
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
3107
3068
|
let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
|
|
3108
|
-
let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
|
|
3109
|
-
if ( userDetails&&userDetails.fcmToken ) {
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
}
|
|
3069
|
+
// let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
|
|
3070
|
+
// if ( userDetails&&userDetails.fcmToken ) {
|
|
3071
|
+
// const fcmToken = userDetails.fcmToken;
|
|
3072
|
+
// await sendPushNotification( title, description, fcmToken );
|
|
3073
|
+
// }
|
|
3113
3074
|
const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
|
|
3114
3075
|
const currentTime = dayjs.utc();
|
|
3115
3076
|
if ( inputDateTime.isBefore( currentTime ) ) {
|
|
@@ -3547,6 +3508,68 @@ export async function uploadmultiImage( images ) {
|
|
|
3547
3508
|
}
|
|
3548
3509
|
};
|
|
3549
3510
|
|
|
3511
|
+
async function assignUsers( data ) {
|
|
3512
|
+
let assignedData;
|
|
3513
|
+
if ( data?.type == 'cluster' ) {
|
|
3514
|
+
let clusterDetails = await clusterServices.findcluster( { clientId: data.clientId, _id: new mongoose.Types.ObjectId( data.id ) } );
|
|
3515
|
+
if ( clusterDetails.length ) {
|
|
3516
|
+
let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
|
|
3517
|
+
let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
|
|
3518
|
+
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3519
|
+
let userData = {
|
|
3520
|
+
storeId: store.storeId,
|
|
3521
|
+
storeName: store.storeName,
|
|
3522
|
+
userName: store.spocDetails?.[0]?.name,
|
|
3523
|
+
userEmail: store.spocDetails?.[0]?.email,
|
|
3524
|
+
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3525
|
+
id: clusterDetails?.[0]?._id,
|
|
3526
|
+
};
|
|
3527
|
+
return userData;
|
|
3528
|
+
} ) );
|
|
3529
|
+
}
|
|
3530
|
+
} else {
|
|
3531
|
+
let teamDetails = await teamsServices.findteams( { clientId: data.clientId, _id: new mongoose.Types.ObjectId( data.id ) } );
|
|
3532
|
+
if ( teamDetails.length ) {
|
|
3533
|
+
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3534
|
+
let userDetails = await userService.find( { _id: userIdList } );
|
|
3535
|
+
assignedData = userDetails.map( ( user ) => {
|
|
3536
|
+
let userData = {
|
|
3537
|
+
userName: user.userName,
|
|
3538
|
+
userEmail: user.email,
|
|
3539
|
+
teamName: teamDetails?.[0]?.teamName,
|
|
3540
|
+
id: teamDetails?.[0]?._id,
|
|
3541
|
+
};
|
|
3542
|
+
return userData;
|
|
3543
|
+
} );
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
return assignedData;
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
export async function customertrial( params ) {
|
|
3550
|
+
try {
|
|
3551
|
+
// let inputData = {
|
|
3552
|
+
// Bucket: 'tango-trax-audit',
|
|
3553
|
+
// file_path: 'trail/59-147/b1c5b15c0133dec0c45640d923fda221_10_09_59_000_24_01_2025_false.mp4',
|
|
3554
|
+
// };
|
|
3555
|
+
// let url = await signedUrl( inputData );
|
|
3556
|
+
// console.log( url );
|
|
3557
|
+
|
|
3558
|
+
|
|
3559
|
+
let inputData = {
|
|
3560
|
+
Bucket: 'tango-trax-audit',
|
|
3561
|
+
Key: 'hygiene/16-01-2025/11-2212/11-2212_13d76f2dd3ea3123aa476a885893c9fd_labelled.jpeg',
|
|
3562
|
+
};
|
|
3563
|
+
|
|
3564
|
+
|
|
3565
|
+
let url = await getObject( inputData );
|
|
3566
|
+
console.log( url );
|
|
3567
|
+
} catch ( e ) {
|
|
3568
|
+
logger.error( 'uploadImage =>', e );
|
|
3569
|
+
return e;
|
|
3570
|
+
}
|
|
3571
|
+
};
|
|
3572
|
+
|
|
3550
3573
|
export async function taskAssign( req, res ) {
|
|
3551
3574
|
try {
|
|
3552
3575
|
if ( !req.body.taskId ) {
|
|
@@ -3563,343 +3586,128 @@ export async function taskAssign( req, res ) {
|
|
|
3563
3586
|
if ( !taskDetails ) {
|
|
3564
3587
|
return res.sendError( 'No data found', 204 );
|
|
3565
3588
|
}
|
|
3566
|
-
let assignList = [];
|
|
3567
3589
|
|
|
3568
|
-
|
|
3569
|
-
// let assignedData = {
|
|
3570
|
-
// ...data,
|
|
3571
|
-
// clientId: req.body.clientId,
|
|
3572
|
-
// checkListName: taskDetails.checkListName,
|
|
3573
|
-
// checklistId: taskDetails._id,
|
|
3574
|
-
// coverage: req.body.coverage,
|
|
3575
|
-
// insert: false,
|
|
3576
|
-
// };
|
|
3577
|
-
// // console.log( assignedData, 'daterthj' );
|
|
3578
|
-
// let uploadData = await assignUsers( assignedData );
|
|
3579
|
-
// if ( uploadData ) {
|
|
3580
|
-
// if ( Array.isArray( uploadData ) ) {
|
|
3581
|
-
// assignList.push( ...uploadData );
|
|
3582
|
-
// } else {
|
|
3583
|
-
// assignList.push( uploadData );
|
|
3584
|
-
// }
|
|
3585
|
-
// }
|
|
3586
|
-
// }
|
|
3590
|
+
let uniqueArr = [];
|
|
3587
3591
|
|
|
3588
3592
|
await Promise.all( req.body.idList.map( async ( data ) => {
|
|
3589
3593
|
let assignedData = {
|
|
3590
3594
|
...data,
|
|
3591
3595
|
clientId: req.body.clientId,
|
|
3592
|
-
checkListName: taskDetails.checkListName,
|
|
3593
|
-
checklistId: taskDetails._id,
|
|
3594
|
-
coverage: req.body.coverage,
|
|
3595
|
-
insert: false,
|
|
3596
3596
|
};
|
|
3597
|
-
// console.log( assignedData, 'daterthj' );
|
|
3598
3597
|
let uploadData = await assignUsers( assignedData );
|
|
3599
|
-
if ( uploadData ) {
|
|
3600
|
-
|
|
3601
|
-
assignList.push( ...uploadData );
|
|
3602
|
-
} else {
|
|
3603
|
-
assignList.push( uploadData );
|
|
3604
|
-
}
|
|
3598
|
+
if ( uploadData.length ) {
|
|
3599
|
+
uniqueArr.push( ...uploadData );
|
|
3605
3600
|
}
|
|
3606
3601
|
} ) );
|
|
3607
3602
|
|
|
3603
|
+
if ( uniqueArr.length ) {
|
|
3604
|
+
if ( req.body.coverage == 'store' ) {
|
|
3605
|
+
uniqueArr = uniqueArr.reduce( ( acc, obj ) => {
|
|
3606
|
+
if ( acc[obj.storeName] ) {
|
|
3607
|
+
acc[obj.storeName].clusterName += ',' + obj.clusterName;
|
|
3608
|
+
} else {
|
|
3609
|
+
acc[obj.storeName] = { ...obj };
|
|
3610
|
+
}
|
|
3611
|
+
return acc;
|
|
3612
|
+
}, {} );
|
|
3613
|
+
|
|
3614
|
+
uniqueArr= Object.values( uniqueArr );
|
|
3615
|
+
} else {
|
|
3616
|
+
uniqueArr = uniqueArr.reduce( ( acc, obj ) => {
|
|
3617
|
+
if ( acc[obj.userEmail] ) {
|
|
3618
|
+
acc[obj.userEmail].teamName += ','+ obj.teamName;
|
|
3619
|
+
} else {
|
|
3620
|
+
acc[obj.userEmail] = { ...obj };
|
|
3621
|
+
}
|
|
3622
|
+
return acc;
|
|
3623
|
+
}, {} );
|
|
3624
|
+
uniqueArr = Object.values( uniqueArr );
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3608
3627
|
|
|
3609
|
-
return res.sendSuccess( { count:
|
|
3628
|
+
return res.sendSuccess( { count: uniqueArr.length, uniqueArr } );
|
|
3610
3629
|
} catch ( e ) {
|
|
3611
|
-
logger.error( { functionName: '
|
|
3630
|
+
logger.error( { functionName: 'taskAssign', error: e } );
|
|
3612
3631
|
return res.sendError( e, 500 );
|
|
3613
3632
|
}
|
|
3614
3633
|
}
|
|
3615
3634
|
|
|
3616
|
-
async function
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
if ( data?.type == 'cluster' ) {
|
|
3621
|
-
let query = [
|
|
3622
|
-
{
|
|
3623
|
-
$addFields: {
|
|
3624
|
-
cluster: { $toLower: '$clusterName' },
|
|
3625
|
-
},
|
|
3626
|
-
},
|
|
3627
|
-
{
|
|
3628
|
-
$match: {
|
|
3629
|
-
clientId: data.clientId,
|
|
3630
|
-
...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
|
|
3631
|
-
},
|
|
3632
|
-
},
|
|
3633
|
-
{
|
|
3634
|
-
$project: {
|
|
3635
|
-
stores: 1,
|
|
3636
|
-
clusterName: 1,
|
|
3637
|
-
},
|
|
3638
|
-
},
|
|
3639
|
-
];
|
|
3640
|
-
let clusterDetails = await clusterServices.aggregateCluster( query );
|
|
3641
|
-
if ( clusterDetails.length ) {
|
|
3642
|
-
if ( data.insert ) {
|
|
3643
|
-
assignedData = {
|
|
3644
|
-
checkFlag: true,
|
|
3645
|
-
checkListId: data.checklistId,
|
|
3646
|
-
checkListName: data.checkListName,
|
|
3647
|
-
client_id: data?.clientId,
|
|
3648
|
-
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3649
|
-
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3650
|
-
coverage: 'store',
|
|
3651
|
-
};
|
|
3652
|
-
} else {
|
|
3653
|
-
let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
|
|
3654
|
-
let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
|
|
3655
|
-
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3656
|
-
let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
|
|
3657
|
-
if ( !userDetails && store?.spocDetails?.length ) {
|
|
3658
|
-
let userData = {
|
|
3659
|
-
userName: store.spocDetails?.[0]?.name,
|
|
3660
|
-
email: store.spocDetails[0]?.email,
|
|
3661
|
-
mobileNumber: store.spocDetails?.[0]?.phone,
|
|
3662
|
-
clientId: data.clientId,
|
|
3663
|
-
};
|
|
3664
|
-
userDetails = await createUser( userData );
|
|
3665
|
-
}
|
|
3666
|
-
let userData = {
|
|
3667
|
-
userId: userDetails?._id,
|
|
3668
|
-
userName: userDetails?.userName,
|
|
3669
|
-
userEmail: userDetails?.email,
|
|
3670
|
-
userPhone: userDetails?.mobileNumber,
|
|
3671
|
-
checkFlag: true,
|
|
3672
|
-
checkListId: data.checklistId,
|
|
3673
|
-
checkListName: data.checkListName,
|
|
3674
|
-
client_id: data.clientId,
|
|
3675
|
-
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3676
|
-
coverage: 'store',
|
|
3677
|
-
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3678
|
-
storeId: store.storeId,
|
|
3679
|
-
storeName: store.storeName,
|
|
3680
|
-
};
|
|
3681
|
-
return userData;
|
|
3682
|
-
} ) );
|
|
3683
|
-
}
|
|
3684
|
-
}
|
|
3685
|
-
} else {
|
|
3686
|
-
let query = [
|
|
3687
|
-
{
|
|
3688
|
-
$addFields: {
|
|
3689
|
-
store: { $toLower: '$storeName' },
|
|
3690
|
-
},
|
|
3691
|
-
},
|
|
3692
|
-
{
|
|
3693
|
-
$match: {
|
|
3694
|
-
clientId: data.clientId,
|
|
3695
|
-
...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
|
|
3696
|
-
},
|
|
3697
|
-
},
|
|
3698
|
-
];
|
|
3699
|
-
let storeDetails = await storeService.aggregate( query );
|
|
3700
|
-
if ( storeDetails.length ) {
|
|
3701
|
-
let email = data?.userEmail ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
|
|
3702
|
-
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3703
|
-
if ( !userDetails ) {
|
|
3704
|
-
let userData = {
|
|
3705
|
-
userName: storeDetails?.[0]?.spocDetails?.[0]?.name,
|
|
3706
|
-
email: storeDetails?.[0]?.spocDetails[0].email,
|
|
3707
|
-
mobileNumber: storeDetails?.[0]?.spocDetails?.[0]?.phone,
|
|
3708
|
-
clientId: data.clientId,
|
|
3709
|
-
};
|
|
3710
|
-
userDetails = await createUser( userData );
|
|
3711
|
-
console.log( 'userDetails =>', userDetails );
|
|
3712
|
-
}
|
|
3713
|
-
assignedData = {
|
|
3714
|
-
store_id: storeDetails?.[0]?.storeId,
|
|
3715
|
-
storeName: storeDetails?.[0]?.storeName,
|
|
3716
|
-
userId: userDetails._id,
|
|
3717
|
-
userName: userDetails.userName,
|
|
3718
|
-
userEmail: userDetails.email,
|
|
3719
|
-
userPhone: userDetails?.mobileNumber,
|
|
3720
|
-
city: storeDetails?.[0]?.storeProfile?.city,
|
|
3721
|
-
country: storeDetails?.[0]?.storeProfile?.country,
|
|
3722
|
-
checkFlag: true,
|
|
3723
|
-
checkListId: data.checklistId,
|
|
3724
|
-
checkListName: data.checkListName,
|
|
3725
|
-
client_id: data.clientId,
|
|
3726
|
-
assignId: data?.id || storeDetails?.[0]?._id,
|
|
3727
|
-
coverage: 'store',
|
|
3728
|
-
};
|
|
3729
|
-
}
|
|
3635
|
+
export async function updateAssign( req, res ) {
|
|
3636
|
+
try {
|
|
3637
|
+
if ( !req.body.assignedList.length && !req.body.assignedGroup.length ) {
|
|
3638
|
+
return res.sendError( 'No data found', 204 );
|
|
3730
3639
|
}
|
|
3731
|
-
|
|
3732
|
-
if (
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
|
|
3743
|
-
},
|
|
3744
|
-
},
|
|
3745
|
-
];
|
|
3746
|
-
let teamDetails = await teamsServices.aggregateTeams( query );
|
|
3747
|
-
if ( teamDetails.length ) {
|
|
3748
|
-
if ( data.insert ) {
|
|
3749
|
-
assignedData = {
|
|
3750
|
-
checkFlag: true,
|
|
3751
|
-
checkListId: data.checklistId,
|
|
3752
|
-
checkListName: data.checkListName,
|
|
3753
|
-
client_id: data.clientId,
|
|
3754
|
-
teamName: teamDetails?.[0]?.teamName,
|
|
3755
|
-
assignId: data?.id || teamDetails?.[0]?._id,
|
|
3756
|
-
coverage: 'user',
|
|
3757
|
-
};
|
|
3758
|
-
} else {
|
|
3759
|
-
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3760
|
-
let userDetails = await userService.find( { _id: userIdList } );
|
|
3761
|
-
assignedData = userDetails.map( ( user ) => {
|
|
3762
|
-
let userData = {
|
|
3763
|
-
userId: user._id,
|
|
3764
|
-
userName: user.userName,
|
|
3765
|
-
userEmail: user.email,
|
|
3766
|
-
userPhone: user.mobileNumber,
|
|
3767
|
-
checkFlag: true,
|
|
3768
|
-
checkListId: data.checklistId,
|
|
3769
|
-
checkListName: data.checkListName,
|
|
3770
|
-
client_id: data.clientId,
|
|
3771
|
-
assignId: data?.id || teamDetails?.[0]?._id,
|
|
3772
|
-
coverage: 'user',
|
|
3773
|
-
teamName: teamDetails?.[0]?.teamName,
|
|
3774
|
-
};
|
|
3775
|
-
return userData;
|
|
3776
|
-
} );
|
|
3777
|
-
}
|
|
3778
|
-
}
|
|
3779
|
-
} else {
|
|
3640
|
+
let taskDetails = await taskService.findOne( { _id: req.body.taskId, client_id: req.body.clientId } );
|
|
3641
|
+
if ( !taskDetails ) {
|
|
3642
|
+
return res.sendError( 'No data found', 204 );
|
|
3643
|
+
}
|
|
3644
|
+
req.body.assignedGroup = [ ...new Set( req.body.assignedGroup.map( ( item ) => item.id ) ) ];
|
|
3645
|
+
req.body.assignedGroup = req.body.assignedGroup.map( ( ele ) => {
|
|
3646
|
+
return { id: ele };
|
|
3647
|
+
} );
|
|
3648
|
+
await taskAssignService.deleteMany( { checkListId: req.body.taskId } );
|
|
3649
|
+
let assignedUserList = [];
|
|
3650
|
+
await Promise.all( req.body.assignedList.map( async ( assign ) => {
|
|
3780
3651
|
let query = [
|
|
3781
3652
|
{
|
|
3782
3653
|
$addFields: {
|
|
3783
|
-
|
|
3654
|
+
emailToLower: { $toLower: '$email' },
|
|
3784
3655
|
},
|
|
3785
3656
|
},
|
|
3786
3657
|
{
|
|
3787
3658
|
$match: {
|
|
3788
|
-
clientId:
|
|
3789
|
-
|
|
3659
|
+
clientId: req.body.clientId,
|
|
3660
|
+
emailToLower: assign.userEmail.toLowerCase(),
|
|
3790
3661
|
},
|
|
3791
3662
|
},
|
|
3792
3663
|
];
|
|
3793
|
-
// console.log( 'data?.userEmail=>', data.userEmail );
|
|
3794
3664
|
let userDetails = await userService.aggregate( query );
|
|
3795
3665
|
if ( !userDetails.length ) {
|
|
3796
3666
|
let userData = {
|
|
3797
|
-
userName:
|
|
3798
|
-
email:
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
// console.log( userData, 'userData', data );
|
|
3802
|
-
let details = await createUser( userData );
|
|
3803
|
-
userDetails = [ details ];
|
|
3804
|
-
}
|
|
3805
|
-
if ( userDetails.length ) {
|
|
3806
|
-
assignedData = {
|
|
3807
|
-
userId: userDetails?.[0]?._id,
|
|
3808
|
-
userName: userDetails?.[0]?.userName,
|
|
3809
|
-
userEmail: userDetails?.[0]?.email,
|
|
3810
|
-
userPhone: userDetails?.[0]?.mobileNumber,
|
|
3811
|
-
checkFlag: true,
|
|
3812
|
-
checkListId: data.checklistId,
|
|
3813
|
-
checkListName: data.checkListName,
|
|
3814
|
-
client_id: data.clientId,
|
|
3815
|
-
assignId: data?.id || userDetails?.[0]?._id,
|
|
3816
|
-
coverage: 'user',
|
|
3667
|
+
userName: assign.userName,
|
|
3668
|
+
email: assign.userEmail,
|
|
3669
|
+
mobileNumber: assign?.phone || '',
|
|
3670
|
+
clientId: req.body.clientId,
|
|
3817
3671
|
};
|
|
3672
|
+
userDetails = await createUser( userData );
|
|
3818
3673
|
}
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
}
|
|
3829
|
-
|
|
3830
|
-
export async function assignTaskUser( req, res ) {
|
|
3831
|
-
try {
|
|
3832
|
-
let inputBody = req.body;
|
|
3833
|
-
let assignDetails = inputBody.assignUsers;
|
|
3834
|
-
let newUsers = inputBody.newUsers;
|
|
3835
|
-
let taskDetails = await taskService.findOne( { _id: inputBody.taskId } );
|
|
3836
|
-
if ( !taskDetails ) {
|
|
3837
|
-
return res.sendError( 'No data found', 204 );
|
|
3838
|
-
}
|
|
3839
|
-
// await Promise.all( newUsers.map( async ( user ) => {
|
|
3840
|
-
// let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
|
|
3841
|
-
// let userData = {
|
|
3842
|
-
// userName: getUser.userName,
|
|
3843
|
-
// email: user,
|
|
3844
|
-
// mobileNumber: getUser?.phone,
|
|
3845
|
-
// clientId: inputBody.clientId,
|
|
3846
|
-
// };
|
|
3847
|
-
// await createUser( userData );
|
|
3848
|
-
// } ) );
|
|
3849
|
-
for ( let i = 0; i < newUsers.length; i++ ) {
|
|
3850
|
-
let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == newUsers[i].toLowerCase() );
|
|
3851
|
-
let userData = {
|
|
3852
|
-
userName: getUser.userName,
|
|
3853
|
-
email: newUsers[i],
|
|
3854
|
-
mobileNumber: getUser?.phone,
|
|
3855
|
-
clientId: inputBody.clientId,
|
|
3674
|
+
let data = {
|
|
3675
|
+
...assign,
|
|
3676
|
+
store_id: assign?.storeId,
|
|
3677
|
+
client_id: req.body.clientId,
|
|
3678
|
+
checkListId: req.body.taskId,
|
|
3679
|
+
coverage: req.body.coverage,
|
|
3680
|
+
assignId: assign._id,
|
|
3681
|
+
userId: userDetails._id,
|
|
3682
|
+
checkListName: taskDetails.checkListName,
|
|
3856
3683
|
};
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
await Promise.all(
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
if (
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3684
|
+
delete data._id;
|
|
3685
|
+
assignedUserList.push( data );
|
|
3686
|
+
} ) );
|
|
3687
|
+
await Promise.all( req.body.assignedGroup.map( async ( assign ) => {
|
|
3688
|
+
let groupDetails;
|
|
3689
|
+
if ( req.body.coverage == 'store' ) {
|
|
3690
|
+
groupDetails = await clusterServices.findOneCluster( { _id: assign.id } );
|
|
3691
|
+
} else {
|
|
3692
|
+
groupDetails = await teamsServices.findOneTeams( { _id: assign.id } );
|
|
3693
|
+
}
|
|
3694
|
+
if ( groupDetails ) {
|
|
3695
|
+
let groupData = {
|
|
3696
|
+
client_id: req.body.clientId,
|
|
3697
|
+
checkListId: req.body.taskId,
|
|
3698
|
+
coverage: req.body.coverage,
|
|
3699
|
+
assignId: assign.id,
|
|
3700
|
+
checkListName: taskDetails.checkListName,
|
|
3701
|
+
...( req.body.coverage == 'store' ) ? { clusterName: groupDetails?.clusterName } : { teamName: groupDetails?.teamName },
|
|
3702
|
+
};
|
|
3703
|
+
assignedUserList.push( groupData );
|
|
3873
3704
|
}
|
|
3874
3705
|
} ) );
|
|
3875
|
-
|
|
3706
|
+
await taskAssignService.insertMany( assignedUserList );
|
|
3707
|
+
return res.sendSuccess( 'Assign details updated successfully' );
|
|
3876
3708
|
} catch ( e ) {
|
|
3877
|
-
logger.error( { functionName: '
|
|
3709
|
+
logger.error( { functionName: 'updateAssign', error: e } );
|
|
3878
3710
|
return res.sendError( e, 500 );
|
|
3879
3711
|
}
|
|
3880
3712
|
}
|
|
3881
3713
|
|
|
3882
|
-
export async function customertrial( params ) {
|
|
3883
|
-
try {
|
|
3884
|
-
// let inputData = {
|
|
3885
|
-
// Bucket: 'tango-trax-audit',
|
|
3886
|
-
// file_path: 'trail/59-147/b1c5b15c0133dec0c45640d923fda221_10_09_59_000_24_01_2025_false.mp4',
|
|
3887
|
-
// };
|
|
3888
|
-
// let url = await signedUrl( inputData );
|
|
3889
|
-
// console.log( url );
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
let inputData = {
|
|
3893
|
-
Bucket: 'tango-trax-audit',
|
|
3894
|
-
Key: 'hygiene/16-01-2025/11-2212/11-2212_13d76f2dd3ea3123aa476a885893c9fd_labelled.jpeg',
|
|
3895
|
-
};
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
let url = await getObject( inputData );
|
|
3899
|
-
console.log( url );
|
|
3900
|
-
} catch ( e ) {
|
|
3901
|
-
logger.error( 'uploadImage =>', e );
|
|
3902
|
-
return e;
|
|
3903
|
-
}
|
|
3904
|
-
};
|
|
3905
|
-
|
package/src/dtos/task.dto.js
CHANGED
|
@@ -23,16 +23,6 @@ export const StoreHygienetaskSchema = Joi.object().keys( {
|
|
|
23
23
|
referenceImage: Joi.array().required(),
|
|
24
24
|
count: Joi.number().required(),
|
|
25
25
|
} );
|
|
26
|
-
export const commonAiTaskSchema = Joi.object().keys( {
|
|
27
|
-
storeName: Joi.string().required(),
|
|
28
|
-
taskName: Joi.string().required(),
|
|
29
|
-
question: Joi.string().required(),
|
|
30
|
-
answerType: Joi.string().required(),
|
|
31
|
-
options: Joi.string().optional(),
|
|
32
|
-
scheduleDate: Joi.string().optional(),
|
|
33
|
-
scheduleEndTime: Joi.string().optional(),
|
|
34
|
-
referenceImage: Joi.array().required(),
|
|
35
|
-
} );
|
|
36
26
|
|
|
37
27
|
|
|
38
28
|
export const eyeTesttaskSchema = Joi.object().keys( {
|
|
@@ -51,9 +41,6 @@ export const aitaskvalidation = {
|
|
|
51
41
|
export const StoreHygienetaskvalidation = {
|
|
52
42
|
body: StoreHygienetaskSchema,
|
|
53
43
|
};
|
|
54
|
-
export const commonAiTaskvalidation = {
|
|
55
|
-
body: commonAiTaskSchema,
|
|
56
|
-
};
|
|
57
44
|
export const eyeTesttaskvalidation = {
|
|
58
45
|
body: eyeTesttaskSchema,
|
|
59
46
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as taskController from '../controllers/task.controller.js';
|
|
3
3
|
import { isAllowedSessionHandler, validate, accessVerification, isAllowedClient, isAllowedInternalAPIHandler } from 'tango-app-api-middleware';
|
|
4
4
|
import express from 'express';
|
|
5
|
-
import { aitaskvalidation, StoreHygienetaskvalidation, eyeTesttaskvalidation
|
|
5
|
+
import { aitaskvalidation, StoreHygienetaskvalidation, eyeTesttaskvalidation } from '../dtos/task.dto.js';
|
|
6
6
|
export const taskRouter = express.Router();
|
|
7
7
|
|
|
8
8
|
taskRouter
|
|
@@ -10,7 +10,7 @@ taskRouter
|
|
|
10
10
|
.post( '/delete/:taskIds', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.deleteTask )
|
|
11
11
|
.get( '/details', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskController.taskDetails )
|
|
12
12
|
.get( '/userDetails', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskController.userDetails )
|
|
13
|
-
.post( '/upload', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.
|
|
13
|
+
.post( '/upload', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.validateUserv1 )
|
|
14
14
|
.post( '/uploadImage', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.uploadImage )
|
|
15
15
|
.post( '/config', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.taskConfig )
|
|
16
16
|
.post( '/reinitiate', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.reinitiateTask )
|
|
@@ -30,11 +30,11 @@ taskRouter
|
|
|
30
30
|
.post( '/createaiChecklist', isAllowedInternalAPIHandler, taskController.createAiChecklist )
|
|
31
31
|
.post( '/createaiTask', isAllowedInternalAPIHandler, taskController.createAiTask )
|
|
32
32
|
.post( '/assign', isAllowedSessionHandler, taskController.taskAssign )
|
|
33
|
-
.post( '/assignUpload', isAllowedSessionHandler, taskController.assignTaskUser )
|
|
33
|
+
// .post( '/assignUpload', isAllowedSessionHandler, taskController.assignTaskUser )
|
|
34
34
|
.post( '/createaiTask', isAllowedInternalAPIHandler, validate( aitaskvalidation ), taskController.createAiTask )
|
|
35
35
|
.post( '/StoreHygienetask', isAllowedInternalAPIHandler, validate( StoreHygienetaskvalidation ), taskController.StoreHygienetask )
|
|
36
36
|
.post( '/eyeTesttask', isAllowedInternalAPIHandler, validate( eyeTesttaskvalidation ), taskController.eyeTesttask )
|
|
37
|
-
.
|
|
38
|
-
.
|
|
37
|
+
.get( '/getcoustemer', taskController.customertrial )
|
|
38
|
+
.post( '/updateAssign', isAllowedSessionHandler, taskController.updateAssign );
|
|
39
39
|
|
|
40
40
|
|