tango-app-api-task 3.2.1-beta-19 → 3.2.1-beta-21
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 +3 -3
- package/src/controllers/task.controller.js +545 -144
- package/src/controllers/taskActionCenter.controllers.js +27 -6
- package/src/controllers/taskDashboard.controllers.js +42 -14
- package/src/routes/task.routes.js +3 -0
- package/src/routes/taskDashboard.routes.js +4 -4
- package/src/service/cluster.service.js +1 -0
- package/src/service/taskAssign.service.js +1 -1
- package/src/service/teams.service copy.js +30 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-task",
|
|
3
|
-
"version": "3.2.1-beta-
|
|
3
|
+
"version": "3.2.1-beta-21",
|
|
4
4
|
"description": "Task",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"mongodb": "^6.10.0",
|
|
25
25
|
"nodemon": "^3.1.7",
|
|
26
26
|
"npm": "^10.9.2",
|
|
27
|
-
"tango-api-schema": "^2.2.
|
|
28
|
-
"tango-app-api-middleware": "^3.1.
|
|
27
|
+
"tango-api-schema": "^2.2.52",
|
|
28
|
+
"tango-app-api-middleware": "^3.1.58",
|
|
29
29
|
"winston": "^3.17.0",
|
|
30
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
31
31
|
},
|
|
@@ -8,7 +8,9 @@ import * as storeService from '../service/store.service.js';
|
|
|
8
8
|
import * as traxApprover from '../service/approver.service.js';
|
|
9
9
|
import * as processedChecklist from '../service/processedChecklist.service.js';
|
|
10
10
|
import * as checklistassignconfigModel from '../service/checklistAssign.service.js';
|
|
11
|
-
import * as
|
|
11
|
+
import * as clusterServices from '../service/cluster.service.js';
|
|
12
|
+
import * as teamsServices from '../service/teams.service.js';
|
|
13
|
+
// import * as clusterModel from '../service/cluster.service.js';
|
|
12
14
|
// import * as domainService from '../service/domain.service.js';
|
|
13
15
|
import mongoose from 'mongoose';
|
|
14
16
|
const ObjectId = mongoose.Types.ObjectId;
|
|
@@ -125,38 +127,6 @@ export async function createUpdateTask( req, res ) {
|
|
|
125
127
|
} );
|
|
126
128
|
} );
|
|
127
129
|
|
|
128
|
-
for ( let [ index, question ] of section.questions.entries() ) {
|
|
129
|
-
await processNested( index, question );
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function processNested( qIdx, question, nestedIndex = -1 ) {
|
|
133
|
-
if ( question?.answers?.length ) {
|
|
134
|
-
for ( let [ index, answer ] of question?.answers?.entries() ) {
|
|
135
|
-
if ( !section.questions[qIdx].answers[index]?.nestedQuestion && nestedIndex == -1 ) {
|
|
136
|
-
section.questions[qIdx].answers[index].nestedQuestion = [];
|
|
137
|
-
}
|
|
138
|
-
if ( answer.showLinked ) {
|
|
139
|
-
if ( nestedIndex != -1 ) {
|
|
140
|
-
section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
|
|
141
|
-
} else {
|
|
142
|
-
section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
|
|
143
|
-
}
|
|
144
|
-
let nestedLinkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
145
|
-
if ( nestedLinkedQuestion ) {
|
|
146
|
-
let findNestedAnswers = nestedLinkedQuestion.answers.find( ( item ) => item.showLinked );
|
|
147
|
-
if ( findNestedAnswers ) {
|
|
148
|
-
if ( nestedIndex != -1 ) {
|
|
149
|
-
await processNested( qIdx, nestedLinkedQuestion, nestedIndex );
|
|
150
|
-
} else {
|
|
151
|
-
await processNested( qIdx, nestedLinkedQuestion, index );
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
130
|
sectionList.push( {
|
|
161
131
|
section: section?.name || 'Section 1',
|
|
162
132
|
createdBy: req.user._id,
|
|
@@ -294,9 +264,9 @@ export async function taskDetails( req, res ) {
|
|
|
294
264
|
}
|
|
295
265
|
if ( storechecklistdetails ) {
|
|
296
266
|
result.checkListDetails = { ...storechecklistdetails._doc };
|
|
297
|
-
let
|
|
298
|
-
|
|
299
|
-
result.checkListDetails = { ...result.checkListDetails, ...{ sections: sectionList }, ...{
|
|
267
|
+
let assignedusers = await taskAssignService.find( { checkListId: storechecklistdetails._id }, { _id: 1 } );
|
|
268
|
+
assignedusers = assignedusers?.map( ( item ) => item._id );
|
|
269
|
+
result.checkListDetails = { ...result.checkListDetails, ...{ sections: sectionList }, ...{ assignedusers: assignedusers } };
|
|
300
270
|
}
|
|
301
271
|
return res.sendSuccess( result );
|
|
302
272
|
} catch ( e ) {
|
|
@@ -595,11 +565,8 @@ export async function userDetails( req, res ) {
|
|
|
595
565
|
if ( !req.query.taskId ) {
|
|
596
566
|
return res.sendError( { message: 'Task Id is required' }, 400 );
|
|
597
567
|
}
|
|
598
|
-
let limit = parseInt( req.query.limit ) || 5;
|
|
599
|
-
let page = parseInt( req.query.offset ) || 0;
|
|
600
|
-
let skip = limit * page;
|
|
601
568
|
|
|
602
|
-
let query = [ { $match: { checkListId: new ObjectId( req.query.taskId ) } } ];
|
|
569
|
+
let query = [ { $match: { checkListId: new ObjectId( req.query.taskId ), ...( req.query.coverage ) ? { coverage: req.query.coverage } : {}, isdeleted: false } } ];
|
|
603
570
|
if ( req.query?.search?.trim() && req.query?.search?.trim() != '' ) {
|
|
604
571
|
let searchValue = req.query.search;
|
|
605
572
|
searchValue = searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
|
|
@@ -611,17 +578,6 @@ export async function userDetails( req, res ) {
|
|
|
611
578
|
}
|
|
612
579
|
}
|
|
613
580
|
|
|
614
|
-
query.push( {
|
|
615
|
-
$facet: {
|
|
616
|
-
data: [
|
|
617
|
-
{ $skip: skip }, { $limit: limit },
|
|
618
|
-
],
|
|
619
|
-
count: [
|
|
620
|
-
{ $count: 'total' },
|
|
621
|
-
],
|
|
622
|
-
},
|
|
623
|
-
} );
|
|
624
|
-
|
|
625
581
|
let taskDetails = await taskAssignService.aggregate( query );
|
|
626
582
|
|
|
627
583
|
if ( !taskDetails[0].data.length ) {
|
|
@@ -629,19 +585,70 @@ export async function userDetails( req, res ) {
|
|
|
629
585
|
}
|
|
630
586
|
|
|
631
587
|
let userDetails = [];
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
588
|
+
let storeList = [];
|
|
589
|
+
let userList = [];
|
|
590
|
+
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
|
+
if ( ele?.clusterName ) {
|
|
598
|
+
let clusterDetails = await clusterServices.findOneCluster( { _id: ele.assignId }, { stores: 1 } );
|
|
599
|
+
if ( clusterDetails ) {
|
|
600
|
+
let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) } } );
|
|
601
|
+
storeDetails.forEach( ( item ) => {
|
|
602
|
+
userDetails.push( {
|
|
603
|
+
id: ele._id,
|
|
604
|
+
userName: item.spocDetails?.[0]?.name,
|
|
605
|
+
userEmail: item.spocDetails?.[0]?.email,
|
|
606
|
+
store_id: item?.storeId,
|
|
607
|
+
storeName: item?.storeName,
|
|
608
|
+
userPhone: item.spocDetails?.[0]?.phone,
|
|
609
|
+
city: ele?.city,
|
|
610
|
+
checkFlag: ele.checkFlag,
|
|
611
|
+
clusterName: ele?.clusterName || '',
|
|
612
|
+
teamName: ele?.teamName || '',
|
|
613
|
+
} );
|
|
614
|
+
} );
|
|
615
|
+
}
|
|
616
|
+
} else if ( ele?.teamName ) {
|
|
617
|
+
let teamDetails = await teamsServices.findOneTeams( { _id: ele.assignId }, { users: 1, teamName: 1 } );
|
|
618
|
+
if ( teamDetails ) {
|
|
619
|
+
let teamUserDetails = await userService.find( { _id: { $in: teamDetails.users.map( ( item ) => item.userId ) } } );
|
|
620
|
+
teamUserDetails.forEach( ( item ) => {
|
|
621
|
+
userDetails.push( {
|
|
622
|
+
id: ele._id,
|
|
623
|
+
userName: item.userName,
|
|
624
|
+
userEmail: item.email,
|
|
625
|
+
store_id: ele?.storeId,
|
|
626
|
+
storeName: ele?.storeName,
|
|
627
|
+
userPhone: item?.mobileNumber,
|
|
628
|
+
city: ele?.city,
|
|
629
|
+
checkFlag: ele.checkFlag,
|
|
630
|
+
clusterName: ele?.clusterName || '',
|
|
631
|
+
teamName: ele?.teamName || '',
|
|
632
|
+
} );
|
|
633
|
+
} );
|
|
634
|
+
}
|
|
635
|
+
} else {
|
|
636
|
+
userDetails.push( {
|
|
637
|
+
id: ele._id,
|
|
638
|
+
userName: ele.userName,
|
|
639
|
+
userEmail: ele.userEmail,
|
|
640
|
+
store_id: ele?.store_id,
|
|
641
|
+
storeName: ele?.storeName,
|
|
642
|
+
userPhone: ele.userPhone,
|
|
643
|
+
city: ele.city,
|
|
644
|
+
checkFlag: ele.checkFlag,
|
|
645
|
+
clusterName: ele?.clusterName || '',
|
|
646
|
+
teamName: ele?.teamName || '',
|
|
647
|
+
} );
|
|
648
|
+
}
|
|
649
|
+
} ) );
|
|
650
|
+
|
|
651
|
+
return res.sendSuccess( { count: userDetails.length, storeList, userList, users: limitedData } );
|
|
645
652
|
} catch ( e ) {
|
|
646
653
|
logger.error( { functionName: 'userDetails', error: e, message: req.body } );
|
|
647
654
|
return res.sendError( e, 500 );
|
|
@@ -651,8 +658,6 @@ export async function userDetails( req, res ) {
|
|
|
651
658
|
export async function taskConfig( req, res ) {
|
|
652
659
|
try {
|
|
653
660
|
let inputBody = req.body;
|
|
654
|
-
let storeCount = 0;
|
|
655
|
-
let locationCount = 0;
|
|
656
661
|
let checklistDetails;
|
|
657
662
|
inputBody.client_id = inputBody.clientId;
|
|
658
663
|
if ( !inputBody._id ) {
|
|
@@ -682,7 +687,7 @@ export async function taskConfig( req, res ) {
|
|
|
682
687
|
};
|
|
683
688
|
await checklistLogs.create( logInsertData );
|
|
684
689
|
|
|
685
|
-
checklistDetails = await taskService.findOne( { _id: inputBody._id, isdeleted: false } );
|
|
690
|
+
checklistDetails = await taskService.findOne( { _id: inputBody._id, isdeleted: false, client_id: inputBody.clientId } );
|
|
686
691
|
|
|
687
692
|
if ( !checklistDetails ) {
|
|
688
693
|
return res.sendError( 'No data found', 204 );
|
|
@@ -720,39 +725,20 @@ export async function taskConfig( req, res ) {
|
|
|
720
725
|
await traxApprover.insertMany( data );
|
|
721
726
|
}
|
|
722
727
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
await
|
|
728
|
+
if ( inputBody.assignedUsers.length ) {
|
|
729
|
+
await taskAssignService.deleteMany( { checkListId: inputBody._id } );
|
|
730
|
+
await Promise.all( inputBody.assignedUsers.map( async ( user ) => {
|
|
731
|
+
let data = {
|
|
732
|
+
...user,
|
|
733
|
+
clientId: req.body.clientId,
|
|
734
|
+
checkListName: checklistDetails.checkListName,
|
|
735
|
+
checklistId: checklistDetails._id,
|
|
736
|
+
coverage: inputBody.coverage,
|
|
737
|
+
};
|
|
738
|
+
await assignUsers( data );
|
|
739
|
+
} ) );
|
|
726
740
|
}
|
|
727
741
|
let storeConfigDetails = await taskAssignService.find( { checkListId: inputBody._id, checkFlag: true }, { _id: 0, store_id: 1, userEmail: 1, storeName: 1 } );
|
|
728
|
-
let storeList = storeConfigDetails.map( ( store ) => store.store_id );
|
|
729
|
-
|
|
730
|
-
storeCount = storeList.length;
|
|
731
|
-
if ( storeList.length ) {
|
|
732
|
-
let query = [
|
|
733
|
-
{
|
|
734
|
-
$match: {
|
|
735
|
-
client_id: inputBody.client_id,
|
|
736
|
-
id: { $in: storeList },
|
|
737
|
-
city: { $exists: true },
|
|
738
|
-
},
|
|
739
|
-
},
|
|
740
|
-
{
|
|
741
|
-
$group: {
|
|
742
|
-
_id: '$city',
|
|
743
|
-
},
|
|
744
|
-
},
|
|
745
|
-
{
|
|
746
|
-
$project: {
|
|
747
|
-
_id: 0,
|
|
748
|
-
city: '$_id',
|
|
749
|
-
},
|
|
750
|
-
},
|
|
751
|
-
];
|
|
752
|
-
let storeDetails = await storeService.aggregate( query );
|
|
753
|
-
locationCount = storeDetails.length;
|
|
754
|
-
}
|
|
755
|
-
await taskService.updateOne( { _id: inputBody._id }, { storeCount, locationCount } );
|
|
756
742
|
if ( inputBody.submitType == 'publish' ) {
|
|
757
743
|
let taskName = checklistDetails.checkListName;
|
|
758
744
|
let dueDate = dayjs( configDetails.scheduleEndTimeISO ).format( 'YYYY-MM-DD hh:mm A' );
|
|
@@ -910,7 +896,6 @@ export async function insertSingleProcessData( checklistId ) {
|
|
|
910
896
|
await taskProcessedConfigService.updateOne( { _id: checklistDetails._id }, insertDataPerDay );
|
|
911
897
|
updatedchecklist = checklistDetails;
|
|
912
898
|
}
|
|
913
|
-
|
|
914
899
|
if ( updatedchecklist ) {
|
|
915
900
|
await insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, dateVal, startTimeIso, endTimeIso, insertdata );
|
|
916
901
|
}
|
|
@@ -938,7 +923,80 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
|
|
|
938
923
|
|
|
939
924
|
if ( allQuestion ) {
|
|
940
925
|
let userIdList = [];
|
|
941
|
-
|
|
926
|
+
let assignList = [];
|
|
927
|
+
let assignUserList = [];
|
|
928
|
+
if ( getCLconfig.coverage == 'store' ) {
|
|
929
|
+
let clusterList = allQuestion.filter( ( ele ) => ele?.clusterName ).map( ( item ) => item.assignId );
|
|
930
|
+
if ( clusterList.length ) {
|
|
931
|
+
let clusterDetails = await clusterServices.findcluster( { _id: { $in: clusterList } } );
|
|
932
|
+
if ( clusterDetails.length ) {
|
|
933
|
+
let idList = clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) );
|
|
934
|
+
let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
|
|
935
|
+
if ( getStoreDetails.length ) {
|
|
936
|
+
assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
|
|
937
|
+
let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
|
|
938
|
+
if ( !userDetails ) {
|
|
939
|
+
let data = {
|
|
940
|
+
clientId: store.clientId,
|
|
941
|
+
userName: store.spocDetails?.[0]?.name,
|
|
942
|
+
mobileNumber: store.spocDetails?.[0]?.phone || '',
|
|
943
|
+
email: store.spocDetails[0].email,
|
|
944
|
+
};
|
|
945
|
+
userDetails = await createUser( data );
|
|
946
|
+
}
|
|
947
|
+
let data = {
|
|
948
|
+
store_id: store?.storeId,
|
|
949
|
+
storeName: store?.storeName,
|
|
950
|
+
userId: userDetails._id,
|
|
951
|
+
userName: userDetails.userName,
|
|
952
|
+
userEmail: userDetails.email,
|
|
953
|
+
userPhone: userDetails?.mobileNumber,
|
|
954
|
+
city: store?.storeProfile?.city,
|
|
955
|
+
country: store?.storeProfile?.country,
|
|
956
|
+
checkFlag: true,
|
|
957
|
+
checkListId: getCLconfig._id,
|
|
958
|
+
checkListName: getCLconfig.checkListName,
|
|
959
|
+
client_id: getCLconfig.client_id,
|
|
960
|
+
};
|
|
961
|
+
return data;
|
|
962
|
+
} ) );
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
allQuestion = allQuestion.filter( ( ele ) => !clusterList.includes( ele.assignId ) );
|
|
967
|
+
}
|
|
968
|
+
if ( getCLconfig.coverage == 'user' ) {
|
|
969
|
+
let teamsList = allQuestion.filter( ( ele ) => ele?.teamName ).map( ( item ) => item.assignId );
|
|
970
|
+
if ( teamsList.length ) {
|
|
971
|
+
let teamDetails = await teamsServices.findteams( { _id: { $in: teamsList } } );
|
|
972
|
+
if ( teamDetails.length ) {
|
|
973
|
+
let idList = teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) );
|
|
974
|
+
let getUserDetails = await userService.find( { _id: { $in: idList } } );
|
|
975
|
+
if ( getUserDetails.length ) {
|
|
976
|
+
assignList = getUserDetails.map( ( user ) => {
|
|
977
|
+
let data = {
|
|
978
|
+
store_id: '',
|
|
979
|
+
storeName: '',
|
|
980
|
+
userId: user._id,
|
|
981
|
+
userName: user.userName,
|
|
982
|
+
userEmail: user.email,
|
|
983
|
+
userPhone: user?.mobileNumber,
|
|
984
|
+
city: '',
|
|
985
|
+
country: '',
|
|
986
|
+
checkFlag: true,
|
|
987
|
+
checkListId: getCLconfig._id,
|
|
988
|
+
checkListName: getCLconfig.checkListName,
|
|
989
|
+
client_id: getCLconfig.client_id,
|
|
990
|
+
};
|
|
991
|
+
return data;
|
|
992
|
+
} );
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
allQuestion = allQuestion.filter( ( ele ) => !teamsList.includes( ele.assignId ) );
|
|
997
|
+
}
|
|
998
|
+
allQuestion = [ ...allQuestion, ...assignList ];
|
|
999
|
+
await Promise.all( allQuestion.map( async ( element4 ) => {
|
|
942
1000
|
let query;
|
|
943
1001
|
query = {
|
|
944
1002
|
date_string: dayjs( date ).format( 'YYYY-MM-DD' ),
|
|
@@ -954,38 +1012,39 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
|
|
|
954
1012
|
let getsubmitDetails = await taskProcessedService.find( query );
|
|
955
1013
|
if ( getsubmitDetails.length ) {
|
|
956
1014
|
userIdList.push( element4._id );
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1015
|
+
} else {
|
|
1016
|
+
delete element4._id;
|
|
1017
|
+
delete element4.checkFlag;
|
|
1018
|
+
delete element4.isdeleted;
|
|
1019
|
+
delete element4.createdAt;
|
|
1020
|
+
delete element4.updatedAt;
|
|
1021
|
+
element4.checkListId = updatedchecklist._id;
|
|
1022
|
+
element4.checkListName = getCLconfig.checkListName;
|
|
1023
|
+
element4.checkListDescription = getCLconfig.checkListDescription;
|
|
1024
|
+
element4.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
1025
|
+
element4.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
|
|
1026
|
+
element4.allowedOverTime = false;
|
|
1027
|
+
element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
|
|
1028
|
+
element4.scheduleStartTime = '12:00 AM';
|
|
1029
|
+
element4.scheduleStartTime_iso = startTimeIso.format();
|
|
1030
|
+
element4.scheduleEndTime = getCLconfig.scheduleEndTime;
|
|
1031
|
+
element4.scheduleEndTime_iso = endTimeIso.format();
|
|
1032
|
+
element4.createdBy = new ObjectId( getCLconfig.createdBy );
|
|
1033
|
+
element4.createdByName = getCLconfig.createdByName;
|
|
1034
|
+
element4.sourceCheckList_id = getCLconfig._id;
|
|
1035
|
+
element4.checkListType = getCLconfig.checkListType;
|
|
1036
|
+
element4.storeCount = getCLconfig.storeCount;
|
|
1037
|
+
element4.questionCount = getCLconfig.questionCount;
|
|
1038
|
+
element4.publishDate = getCLconfig.publishDate;
|
|
1039
|
+
element4.locationCount = getCLconfig.locationCount;
|
|
1040
|
+
element4.scheduleRepeatedType = 'daily';
|
|
1041
|
+
element4.approvalEnable = getCLconfig.approver.length ? true : false;
|
|
1042
|
+
element4.priorityType = getCLconfig.priorityType;
|
|
1043
|
+
element4.remainder = getCLconfig?.remainder || [];
|
|
1044
|
+
element4.restrictAttendance = getCLconfig?.restrictAttendance;
|
|
1045
|
+
assignUserList.push( element4 );
|
|
1046
|
+
}
|
|
1047
|
+
} ) );
|
|
989
1048
|
if ( userIdList.length ) {
|
|
990
1049
|
allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
|
|
991
1050
|
}
|
|
@@ -1361,16 +1420,17 @@ export async function createChecklistTask( req, res ) {
|
|
|
1361
1420
|
client_id: inputBody.clientId,
|
|
1362
1421
|
};
|
|
1363
1422
|
await taskQuestionService.create( question );
|
|
1364
|
-
let storeDetails
|
|
1365
|
-
if (
|
|
1366
|
-
|
|
1423
|
+
let storeDetails;
|
|
1424
|
+
if ( inputBody?.storeName ) {
|
|
1425
|
+
storeDetails = await storeService.findOne( { storeName: inputBody.storeName, status: 'active' }, { storeId: 1, storeProfile: 1 } );
|
|
1367
1426
|
}
|
|
1427
|
+
|
|
1368
1428
|
let userDetails = {
|
|
1369
1429
|
userName: inputBody.userName,
|
|
1370
1430
|
userEmail: inputBody.userEmail,
|
|
1371
|
-
store_id: storeDetails.storeId,
|
|
1372
|
-
storeName: inputBody
|
|
1373
|
-
city: storeDetails?.storeProfile?.city,
|
|
1431
|
+
store_id: storeDetails?.storeId?storeDetails.storeId:'',
|
|
1432
|
+
storeName: inputBody?.storeName?inputBody?.storeName:'',
|
|
1433
|
+
city: storeDetails?.storeProfile?.city?storeDetails?.storeProfile?.city:'',
|
|
1374
1434
|
checkFlag: true,
|
|
1375
1435
|
checkListId: response?._id,
|
|
1376
1436
|
checkListName: data.checkListName,
|
|
@@ -1389,8 +1449,9 @@ export async function createChecklistTask( req, res ) {
|
|
|
1389
1449
|
if ( sectionIndex == -1 ) {
|
|
1390
1450
|
return res.sendError( 'section is not found', 400 );
|
|
1391
1451
|
}
|
|
1392
|
-
let
|
|
1452
|
+
let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele?.parentQuestion ? ele.qno == req.body.qno && ele.parentQuestion == req.body.parentQuestion : ele.qno == req.body.qno );
|
|
1393
1453
|
|
|
1454
|
+
let data = { ...question[sectionIndex].questions[findQuestion], taskId: response?._id, task: true };
|
|
1394
1455
|
question[sectionIndex].questions[req.body.qno - 1] = data;
|
|
1395
1456
|
taskDetails.questionAnswers = question;
|
|
1396
1457
|
let updateData = {
|
|
@@ -1403,6 +1464,7 @@ export async function createChecklistTask( req, res ) {
|
|
|
1403
1464
|
_id: inputBody.processedChecklistId,
|
|
1404
1465
|
section_id: inputBody.sectionId,
|
|
1405
1466
|
qno: inputBody.qno,
|
|
1467
|
+
parentQuestion: inputBody.parentQuestion,
|
|
1406
1468
|
},
|
|
1407
1469
|
'upsert': {
|
|
1408
1470
|
taskId: String( response?._id ),
|
|
@@ -1539,6 +1601,7 @@ export async function redoTask( req, res ) {
|
|
|
1539
1601
|
};
|
|
1540
1602
|
|
|
1541
1603
|
let response = await taskProcessedService.updateOne( { _id: req.body.payload._id }, updateData );
|
|
1604
|
+
console.log( response );
|
|
1542
1605
|
if ( response.modifiedCount || response.matchedCount ) {
|
|
1543
1606
|
let storeTimeZone = await storeService.findOne( { storeName: taskDetails.storeName }, { 'storeProfile.timeZone': 1 } );
|
|
1544
1607
|
let currentDateTime;
|
|
@@ -1555,8 +1618,8 @@ export async function redoTask( req, res ) {
|
|
|
1555
1618
|
sectionName: question[sectionIndex].sectionName,
|
|
1556
1619
|
questionName: question[sectionIndex].questions[req.body.payload.qno - 1].qname,
|
|
1557
1620
|
action: 'redo',
|
|
1558
|
-
store_id: taskDetails
|
|
1559
|
-
storeName: taskDetails.storeName,
|
|
1621
|
+
store_id: taskDetails?.store_id?taskDetails?.store_id:'',
|
|
1622
|
+
storeName: taskDetails.storeName?taskDetails.storeName:'',
|
|
1560
1623
|
client_id: taskDetails.client_id,
|
|
1561
1624
|
processedChecklistId: taskDetails._id,
|
|
1562
1625
|
type: taskDetails.checkListType,
|
|
@@ -1578,6 +1641,7 @@ export async function redoTask( req, res ) {
|
|
|
1578
1641
|
};
|
|
1579
1642
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
1580
1643
|
let searchResponse = await fetch( url.redoTask, requestOptions );
|
|
1644
|
+
console.log( searchResponse.ok );
|
|
1581
1645
|
if ( searchResponse.ok ) {
|
|
1582
1646
|
return res.sendSuccess( 'Question redo successfully' );
|
|
1583
1647
|
} else {
|
|
@@ -1674,6 +1738,7 @@ export const taskDropdown = async ( req, res ) => {
|
|
|
1674
1738
|
scheduleRepeatedType: 1,
|
|
1675
1739
|
scheduleStartTime: 1,
|
|
1676
1740
|
scheduleEndTime: 1,
|
|
1741
|
+
coverage: 1,
|
|
1677
1742
|
},
|
|
1678
1743
|
} );
|
|
1679
1744
|
|
|
@@ -1688,6 +1753,7 @@ export const taskDropdown = async ( req, res ) => {
|
|
|
1688
1753
|
scheduleRepeatedType: { $last: '$scheduleRepeatedType' },
|
|
1689
1754
|
scheduleStartTime: { $last: '$scheduleStartTime' },
|
|
1690
1755
|
scheduleEndTime: { $last: '$scheduleEndTime' },
|
|
1756
|
+
coverage: { $last: '$coverage' },
|
|
1691
1757
|
},
|
|
1692
1758
|
} );
|
|
1693
1759
|
|
|
@@ -1726,6 +1792,7 @@ export const taskDropdown = async ( req, res ) => {
|
|
|
1726
1792
|
scheduleRepeatedType: 1,
|
|
1727
1793
|
scheduleStartTime: 1,
|
|
1728
1794
|
scheduleEndTime: 1,
|
|
1795
|
+
coverage: 1,
|
|
1729
1796
|
checkListDescription: '$checklistconfigs.checkListDescription',
|
|
1730
1797
|
publish: '$checklistconfigs.publish',
|
|
1731
1798
|
},
|
|
@@ -2161,13 +2228,13 @@ export async function clusterMigrations( req, res ) {
|
|
|
2161
2228
|
if ( userexits ) {
|
|
2162
2229
|
let findStore = await storeService.findOne( { storeName: user.FacilityCode } );
|
|
2163
2230
|
if ( findStore ) {
|
|
2164
|
-
let clusterExists = await
|
|
2231
|
+
let clusterExists = await clusterServices.findOneCluster( { clusterName: user.AomName } );
|
|
2165
2232
|
if ( clusterExists ) {
|
|
2166
2233
|
let data = {
|
|
2167
2234
|
storeId: findStore.storeId,
|
|
2168
2235
|
store: findStore._id,
|
|
2169
2236
|
};
|
|
2170
|
-
let updatecluster = await
|
|
2237
|
+
let updatecluster = await clusterServices.updateCluster( { clusterName: user.AomName }, { $push: { stores: data } } );
|
|
2171
2238
|
console.log( updatecluster );
|
|
2172
2239
|
} else {
|
|
2173
2240
|
let payload = {
|
|
@@ -2189,7 +2256,7 @@ export async function clusterMigrations( req, res ) {
|
|
|
2189
2256
|
],
|
|
2190
2257
|
'users': [],
|
|
2191
2258
|
};
|
|
2192
|
-
let createcluster = await
|
|
2259
|
+
let createcluster = await clusterServices.createclusterModel( payload );
|
|
2193
2260
|
console.log( createcluster );
|
|
2194
2261
|
}
|
|
2195
2262
|
}
|
|
@@ -3261,6 +3328,340 @@ export async function uploadmultiImage( images ) {
|
|
|
3261
3328
|
}
|
|
3262
3329
|
};
|
|
3263
3330
|
|
|
3331
|
+
export async function taskAssign( req, res ) {
|
|
3332
|
+
try {
|
|
3333
|
+
if ( !req.body.taskId ) {
|
|
3334
|
+
return res.sendError( 'Checklist id is required', 400 );
|
|
3335
|
+
}
|
|
3336
|
+
if ( !req.body.coverage ) {
|
|
3337
|
+
return res.sendError( 'Coverage is required', 400 );
|
|
3338
|
+
}
|
|
3339
|
+
if ( !req.body.idList ) {
|
|
3340
|
+
return res.sendError( 'Id is required', 400 );
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
let taskDetails = await taskService.findOne( { _id: req.body.taskId } );
|
|
3344
|
+
if ( !taskDetails ) {
|
|
3345
|
+
return res.sendError( 'No data found', 204 );
|
|
3346
|
+
}
|
|
3347
|
+
let idList;
|
|
3348
|
+
let assignList;
|
|
3349
|
+
if ( req.body.coverage == 'store' ) {
|
|
3350
|
+
let clusterDetails = await clusterServices.findcluster( { _id: { $in: req.body.idList } }, { stores: 1, clusterName: 1 } );
|
|
3351
|
+
if ( clusterDetails.length ) {
|
|
3352
|
+
let clusterList = clusterDetails.map( ( item ) => item._id.toString() );
|
|
3353
|
+
idList = [
|
|
3354
|
+
...clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) ),
|
|
3355
|
+
...req.body.idList.filter( ( ele ) => !clusterList.includes( ele ) ),
|
|
3356
|
+
];
|
|
3357
|
+
} else {
|
|
3358
|
+
idList = req.body.idList;
|
|
3359
|
+
}
|
|
3360
|
+
let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
|
|
3361
|
+
if ( !getStoreDetails.length ) {
|
|
3362
|
+
return res.sendError( 'No data found', 204 );
|
|
3363
|
+
}
|
|
3364
|
+
assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
|
|
3365
|
+
let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
|
|
3366
|
+
if ( !userDetails ) {
|
|
3367
|
+
let data = {
|
|
3368
|
+
clientId: store.clientId,
|
|
3369
|
+
userName: store.spocDetails?.[0]?.name,
|
|
3370
|
+
mobileNumber: store.spocDetails?.[0]?.phone || '',
|
|
3371
|
+
email: store.spocDetails[0].email,
|
|
3372
|
+
};
|
|
3373
|
+
userDetails = await createUser( data );
|
|
3374
|
+
}
|
|
3375
|
+
let data = {
|
|
3376
|
+
store_id: store.storeId,
|
|
3377
|
+
storeName: store.storeName,
|
|
3378
|
+
userId: userDetails._id,
|
|
3379
|
+
userName: userDetails.userName,
|
|
3380
|
+
userEmail: userDetails.email,
|
|
3381
|
+
userPhone: userDetails?.mobileNumber,
|
|
3382
|
+
clusterName: clusterDetails?.clusterName,
|
|
3383
|
+
};
|
|
3384
|
+
return data;
|
|
3385
|
+
} ) );
|
|
3386
|
+
} else {
|
|
3387
|
+
let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
|
|
3388
|
+
if ( teamDetails.length ) {
|
|
3389
|
+
let teamList = teamDetails.map( ( ele ) => ele._id.toString() );
|
|
3390
|
+
idList = [
|
|
3391
|
+
...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
|
|
3392
|
+
...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
|
|
3393
|
+
];
|
|
3394
|
+
} else {
|
|
3395
|
+
idList = req.body.idList;
|
|
3396
|
+
}
|
|
3397
|
+
let userDetails = await userService.find( { _id: { $in: idList } } );
|
|
3398
|
+
if ( !userDetails.length ) {
|
|
3399
|
+
return res.sendError( 'No data found', 204 );
|
|
3400
|
+
}
|
|
3401
|
+
assignList = [];
|
|
3402
|
+
userDetails.forEach( ( user ) => {
|
|
3403
|
+
assignList.push( {
|
|
3404
|
+
userId: user._id,
|
|
3405
|
+
userName: user.userName,
|
|
3406
|
+
userEmail: user.email,
|
|
3407
|
+
userPhone: user?.mobileNumber,
|
|
3408
|
+
teamName: teamDetails?.teamName,
|
|
3409
|
+
} );
|
|
3410
|
+
} );
|
|
3411
|
+
}
|
|
3412
|
+
return res.sendSuccess( { count: assignList.length, assignList } );
|
|
3413
|
+
} catch ( e ) {
|
|
3414
|
+
logger.error( { functionName: 'checklistAssign', error: e } );
|
|
3415
|
+
return res.sendError( e, 500 );
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
|
|
3419
|
+
async function assignUsers( data ) {
|
|
3420
|
+
let assignedData;
|
|
3421
|
+
if ( data.coverage == 'store' ) {
|
|
3422
|
+
if ( data?.type == 'cluster' ) {
|
|
3423
|
+
let query = [
|
|
3424
|
+
{
|
|
3425
|
+
$addFields: {
|
|
3426
|
+
cluster: { $toLower: '$clusterName' },
|
|
3427
|
+
},
|
|
3428
|
+
},
|
|
3429
|
+
{
|
|
3430
|
+
$match: {
|
|
3431
|
+
clientId: data.clientId,
|
|
3432
|
+
...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
|
|
3433
|
+
},
|
|
3434
|
+
},
|
|
3435
|
+
{
|
|
3436
|
+
$project: {
|
|
3437
|
+
stores: 1,
|
|
3438
|
+
clusterName: 1,
|
|
3439
|
+
},
|
|
3440
|
+
},
|
|
3441
|
+
];
|
|
3442
|
+
let clusterDetails = await clusterServices.aggregateCluster( query );
|
|
3443
|
+
console.log( clusterDetails );
|
|
3444
|
+
if ( clusterDetails.length ) {
|
|
3445
|
+
if ( !data.upload ) {
|
|
3446
|
+
assignedData = {
|
|
3447
|
+
checkFlag: true,
|
|
3448
|
+
checkListId: data.checklistId,
|
|
3449
|
+
checkListName: data.checkListName,
|
|
3450
|
+
client_id: data?.clientId,
|
|
3451
|
+
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3452
|
+
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3453
|
+
coverage: 'store',
|
|
3454
|
+
};
|
|
3455
|
+
} else {
|
|
3456
|
+
let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
|
|
3457
|
+
let storeDetails = await storeService.find( { _id: clusterList } );
|
|
3458
|
+
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3459
|
+
let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
|
|
3460
|
+
if ( !userDetails ) {
|
|
3461
|
+
let userData = {
|
|
3462
|
+
userName: store.spocDetails?.[0]?.name,
|
|
3463
|
+
email: store.spocDetails[0].email,
|
|
3464
|
+
mobileNumber: store.spocDetails?.[0]?.phone,
|
|
3465
|
+
clientId: data.clientId,
|
|
3466
|
+
};
|
|
3467
|
+
userDetails = await createUser( userData );
|
|
3468
|
+
}
|
|
3469
|
+
let userData = {
|
|
3470
|
+
userId: userDetails?._id,
|
|
3471
|
+
userName: userDetails?.userName,
|
|
3472
|
+
userEmail: userDetails?.email,
|
|
3473
|
+
userPhone: userDetails?.mobileNumber,
|
|
3474
|
+
checkFlag: true,
|
|
3475
|
+
checkListId: data.checklistId,
|
|
3476
|
+
checkListName: data.checkListName,
|
|
3477
|
+
client_id: data.clientId,
|
|
3478
|
+
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3479
|
+
coverage: 'store',
|
|
3480
|
+
teamName: clusterDetails?.[0]?.clusterName,
|
|
3481
|
+
};
|
|
3482
|
+
return userData;
|
|
3483
|
+
} ) );
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
} else {
|
|
3487
|
+
let query = [
|
|
3488
|
+
{
|
|
3489
|
+
$addFields: {
|
|
3490
|
+
store: { $toLower: '$storeName' },
|
|
3491
|
+
},
|
|
3492
|
+
},
|
|
3493
|
+
{
|
|
3494
|
+
$match: {
|
|
3495
|
+
clientId: data.clientId,
|
|
3496
|
+
...( !data.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
|
|
3497
|
+
},
|
|
3498
|
+
},
|
|
3499
|
+
];
|
|
3500
|
+
let storeDetails = await storeService.aggregate( query );
|
|
3501
|
+
if ( storeDetails.length ) {
|
|
3502
|
+
let email = data?.upload ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
|
|
3503
|
+
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3504
|
+
if ( !userDetails ) {
|
|
3505
|
+
let userData = {
|
|
3506
|
+
userName: storeDetails?.[0]?.spocDetails?.[0]?.name,
|
|
3507
|
+
email: storeDetails?.[0]?.spocDetails[0].email,
|
|
3508
|
+
mobileNumber: storeDetails?.[0]?.spocDetails?.[0]?.phone,
|
|
3509
|
+
clientId: data.clientId,
|
|
3510
|
+
};
|
|
3511
|
+
userDetails = await createUser( userData );
|
|
3512
|
+
}
|
|
3513
|
+
assignedData = {
|
|
3514
|
+
store_id: storeDetails?.[0]?.storeId,
|
|
3515
|
+
storeName: storeDetails?.[0]?.storeName,
|
|
3516
|
+
userId: userDetails._id,
|
|
3517
|
+
userName: userDetails.userName,
|
|
3518
|
+
userEmail: userDetails.email,
|
|
3519
|
+
userPhone: userDetails?.mobileNumber,
|
|
3520
|
+
city: storeDetails?.[0]?.storeProfile?.city,
|
|
3521
|
+
country: storeDetails?.[0]?.storeProfile?.country,
|
|
3522
|
+
checkFlag: true,
|
|
3523
|
+
checkListId: data.checklistId,
|
|
3524
|
+
checkListName: data.checkListName,
|
|
3525
|
+
client_id: data.clientId,
|
|
3526
|
+
assignId: data?.id || storeDetails?.[0]?._id,
|
|
3527
|
+
coverage: 'store',
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
} else {
|
|
3532
|
+
if ( data.type == 'teams' ) {
|
|
3533
|
+
let query = [
|
|
3534
|
+
{
|
|
3535
|
+
$addFields: {
|
|
3536
|
+
team: { $toLower: '$teamName' },
|
|
3537
|
+
},
|
|
3538
|
+
},
|
|
3539
|
+
{
|
|
3540
|
+
$match: {
|
|
3541
|
+
clientId: data.clientId,
|
|
3542
|
+
...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
|
|
3543
|
+
},
|
|
3544
|
+
},
|
|
3545
|
+
];
|
|
3546
|
+
let teamDetails = await teamsServices.aggregateTeams( query );
|
|
3547
|
+
if ( teamDetails.length ) {
|
|
3548
|
+
if ( !data.upload ) {
|
|
3549
|
+
assignedData = {
|
|
3550
|
+
checkFlag: true,
|
|
3551
|
+
checkListId: data.checklistId,
|
|
3552
|
+
checkListName: data.checkListName,
|
|
3553
|
+
client_id: data.clientId,
|
|
3554
|
+
teamName: teamDetails?.[0]?.teamName,
|
|
3555
|
+
assignId: data?.id || teamDetails?.[0]?._id,
|
|
3556
|
+
coverage: 'user',
|
|
3557
|
+
};
|
|
3558
|
+
} else {
|
|
3559
|
+
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3560
|
+
let userDetails = await userService.find( { _id: userIdList } );
|
|
3561
|
+
assignedData = userDetails.map( ( user ) => {
|
|
3562
|
+
let userData = {
|
|
3563
|
+
userId: user._id,
|
|
3564
|
+
userName: user.userName,
|
|
3565
|
+
userEmail: user.email,
|
|
3566
|
+
userPhone: user.mobileNumber,
|
|
3567
|
+
checkFlag: true,
|
|
3568
|
+
checkListId: data.checklistId,
|
|
3569
|
+
checkListName: data.checkListName,
|
|
3570
|
+
client_id: data.clientId,
|
|
3571
|
+
assignId: data?.id || teamDetails?.[0]?._id,
|
|
3572
|
+
coverage: 'user',
|
|
3573
|
+
teamName: teamDetails?.[0]?.teamName,
|
|
3574
|
+
};
|
|
3575
|
+
return userData;
|
|
3576
|
+
} );
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
} else {
|
|
3580
|
+
let query = [
|
|
3581
|
+
{
|
|
3582
|
+
$addFields: {
|
|
3583
|
+
userEmail: { $toLower: '$email' },
|
|
3584
|
+
},
|
|
3585
|
+
},
|
|
3586
|
+
{
|
|
3587
|
+
$match: {
|
|
3588
|
+
clientId: data.clientId,
|
|
3589
|
+
...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
|
|
3590
|
+
},
|
|
3591
|
+
},
|
|
3592
|
+
];
|
|
3593
|
+
let userDetails = await userService.aggregate( query );
|
|
3594
|
+
if ( !userDetails.length ) {
|
|
3595
|
+
let userData = {
|
|
3596
|
+
userName: data.userEmail.split( '@' )[0],
|
|
3597
|
+
email: data.userEmail,
|
|
3598
|
+
clientId: data.clientId,
|
|
3599
|
+
};
|
|
3600
|
+
let details = await createUser( userData );
|
|
3601
|
+
userDetails = [ details ];
|
|
3602
|
+
}
|
|
3603
|
+
if ( userDetails.length ) {
|
|
3604
|
+
assignedData = {
|
|
3605
|
+
userId: userDetails?.[0]?._id,
|
|
3606
|
+
userName: userDetails?.[0]?.userName,
|
|
3607
|
+
userEmail: userDetails?.[0]?.email,
|
|
3608
|
+
userPhone: userDetails?.[0]?.mobileNumber,
|
|
3609
|
+
checkFlag: true,
|
|
3610
|
+
checkListId: data.checklistId,
|
|
3611
|
+
checkListName: data.checkListName,
|
|
3612
|
+
client_id: data.clientId,
|
|
3613
|
+
assignId: data?.id || userDetails?.[0]?._id,
|
|
3614
|
+
coverage: 'user',
|
|
3615
|
+
};
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
if ( assignedData && !data.upload ) {
|
|
3620
|
+
await taskAssignService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
|
|
3621
|
+
} else {
|
|
3622
|
+
return assignedData;
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
|
|
3626
|
+
export async function assignTaskUser( req, res ) {
|
|
3627
|
+
try {
|
|
3628
|
+
let inputBody = req.body;
|
|
3629
|
+
let assignDetails = inputBody.assignUsers;
|
|
3630
|
+
let newUsers = inputBody.newUsers;
|
|
3631
|
+
let taskDetails = await taskService.findOne( { _id: inputBody.taskId } );
|
|
3632
|
+
if ( !taskDetails ) {
|
|
3633
|
+
return res.sendError( 'No data found', 204 );
|
|
3634
|
+
}
|
|
3635
|
+
await Promise.all( newUsers.map( async ( user ) => {
|
|
3636
|
+
let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
|
|
3637
|
+
let userData = {
|
|
3638
|
+
userName: getUser.userName,
|
|
3639
|
+
email: user,
|
|
3640
|
+
mobileNumber: getUser?.phone,
|
|
3641
|
+
clientId: inputBody.clientId,
|
|
3642
|
+
};
|
|
3643
|
+
await createUser( userData );
|
|
3644
|
+
} ) );
|
|
3645
|
+
let assignData = [];
|
|
3646
|
+
await Promise.all( assignDetails.map( async ( assign ) => {
|
|
3647
|
+
assign.checklistId = inputBody.taskId;
|
|
3648
|
+
assign.checkListName = taskDetails.checkListName;
|
|
3649
|
+
assign.coverage = inputBody.coverage;
|
|
3650
|
+
assign.clientId = inputBody.clientId;
|
|
3651
|
+
assign.upload = inputBody.type;
|
|
3652
|
+
let uploadData = await assignUsers( assign );
|
|
3653
|
+
if ( Array.isArray( uploadData ) ) {
|
|
3654
|
+
assignData.push( ...uploadData );
|
|
3655
|
+
} else {
|
|
3656
|
+
assignData.push( uploadData );
|
|
3657
|
+
}
|
|
3658
|
+
} ) );
|
|
3659
|
+
return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => item.assignId ) ) ], assignData } );
|
|
3660
|
+
} catch ( e ) {
|
|
3661
|
+
logger.error( { functionName: 'assignTaskUser', error: e } );
|
|
3662
|
+
return res.sendError( e, 500 );
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3264
3665
|
|
|
3265
3666
|
export async function customertrial( params ) {
|
|
3266
3667
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as traxApprover from '../service/approver.service.js';
|
|
2
2
|
import * as processedTask from '../service/processedTaskList.service.js';
|
|
3
|
-
import { logger } from 'tango-app-api-middleware';
|
|
3
|
+
import { logger, getChecklistUsers } from 'tango-app-api-middleware';
|
|
4
4
|
import * as processedChecklist from '../service/processedChecklist.service.js';
|
|
5
5
|
import * as checklistLog from '../service/checklistLog.service.js';
|
|
6
6
|
import mongoose from 'mongoose';
|
|
@@ -46,14 +46,21 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
let requestData = req.body;
|
|
50
|
+
// Get User Based Checklist //
|
|
51
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
52
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
53
|
+
// End: Get User Based Checklist////
|
|
54
|
+
|
|
49
55
|
let taskQuery = [
|
|
50
56
|
{
|
|
51
57
|
$match: {
|
|
52
58
|
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
53
59
|
sourceCheckList_id: { $in: taskIdList },
|
|
54
60
|
checklistStatus: 'submit',
|
|
55
|
-
...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
56
61
|
approvalStatus: false,
|
|
62
|
+
// ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
63
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ],
|
|
57
64
|
},
|
|
58
65
|
},
|
|
59
66
|
{ ...groupQuery },
|
|
@@ -65,8 +72,9 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
65
72
|
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
66
73
|
sourceCheckList_id: { $in: checklistIdList },
|
|
67
74
|
checklistStatus: 'submit',
|
|
68
|
-
...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
69
75
|
approvalStatus: false,
|
|
76
|
+
// ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
77
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ],
|
|
70
78
|
},
|
|
71
79
|
},
|
|
72
80
|
{ ...groupQuery },
|
|
@@ -180,13 +188,20 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
180
188
|
|
|
181
189
|
const promises = [];
|
|
182
190
|
|
|
191
|
+
let requestData = req.body;
|
|
192
|
+
// Get User Based Checklist //
|
|
193
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
194
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
195
|
+
// End: Get User Based Checklist////
|
|
196
|
+
|
|
183
197
|
if ( [ 'task', 'all' ].includes( req.body.type ) ) {
|
|
184
198
|
query = [
|
|
185
199
|
{
|
|
186
200
|
$match: {
|
|
187
201
|
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
188
202
|
sourceCheckList_id: { $in: taskIdList },
|
|
189
|
-
...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
203
|
+
// ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
204
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ],
|
|
190
205
|
},
|
|
191
206
|
},
|
|
192
207
|
...groupQuery,
|
|
@@ -217,7 +232,8 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
217
232
|
$match: {
|
|
218
233
|
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
219
234
|
sourceCheckList_id: { $in: checklistIdList },
|
|
220
|
-
...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
|
|
235
|
+
// ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
|
|
236
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ],
|
|
221
237
|
},
|
|
222
238
|
},
|
|
223
239
|
...groupQuery,
|
|
@@ -281,11 +297,16 @@ export const activityLogV1 = async ( req, res ) => {
|
|
|
281
297
|
let findQuery = [];
|
|
282
298
|
let findAndQuery = [];
|
|
283
299
|
|
|
300
|
+
// Get User Based Checklist //
|
|
301
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
302
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
303
|
+
// End: Get User Based Checklist////
|
|
284
304
|
|
|
285
305
|
findAndQuery.push(
|
|
286
306
|
{ client_id: requestData.clientId },
|
|
287
|
-
{ store_id: { $in: requestData.storeId } },
|
|
288
307
|
{ action: { $in: [ 'submitted', 'started' ] } },
|
|
308
|
+
// { store_id: { $in: requestData.storeId } },
|
|
309
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ] },
|
|
289
310
|
);
|
|
290
311
|
|
|
291
312
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as taskService from '../service/task.service.js';
|
|
2
2
|
import * as processedTaskService from '../service/processedTaskList.service.js';
|
|
3
|
-
import { logger, download } from 'tango-app-api-middleware';
|
|
3
|
+
import { logger, download, getChecklistUsers } from 'tango-app-api-middleware';
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import mongoose from 'mongoose';
|
|
6
6
|
// const ObjectId = mongoose.Types.ObjectId;
|
|
@@ -57,10 +57,16 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
57
57
|
let findQuery = [];
|
|
58
58
|
let findAndQuery = [];
|
|
59
59
|
|
|
60
|
+
// Get User Based Checklist //
|
|
61
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
62
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
63
|
+
// End: Get User Based Checklist////
|
|
64
|
+
|
|
60
65
|
findAndQuery.push(
|
|
61
66
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
62
67
|
{ client_id: requestData.clientId },
|
|
63
|
-
{ store_id: { $in: requestData.storeId } },
|
|
68
|
+
// { store_id: { $in: requestData.storeId } },
|
|
69
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ] },
|
|
64
70
|
);
|
|
65
71
|
|
|
66
72
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -228,11 +234,17 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
228
234
|
let findQuery = [];
|
|
229
235
|
let findAndQuery = [];
|
|
230
236
|
|
|
237
|
+
// Get User Based Checklist //
|
|
238
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
239
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
240
|
+
// End: Get User Based Checklist////
|
|
241
|
+
|
|
231
242
|
findAndQuery.push(
|
|
232
243
|
{ date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
|
|
233
244
|
{ client_id: requestData.clientId },
|
|
234
|
-
{ store_id: { $in: requestData.storeId } },
|
|
235
245
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
|
|
246
|
+
// { store_id: { $in: requestData.storeId } },
|
|
247
|
+
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ] },
|
|
236
248
|
);
|
|
237
249
|
if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
|
|
238
250
|
if ( requestData.checklistStatus == 'redo' ) {
|
|
@@ -966,6 +978,12 @@ export async function taskDetails( req, res ) {
|
|
|
966
978
|
return res.sendError( 'clientId is required', 400 );
|
|
967
979
|
}
|
|
968
980
|
|
|
981
|
+
let requestData = req.body;
|
|
982
|
+
// Get User Based Checklist //
|
|
983
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
984
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
985
|
+
// End: Get User Based Checklist////
|
|
986
|
+
|
|
969
987
|
let toDate = new Date( req.body.toDate );
|
|
970
988
|
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
971
989
|
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
@@ -990,23 +1008,33 @@ export async function taskDetails( req, res ) {
|
|
|
990
1008
|
$match: {
|
|
991
1009
|
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
992
1010
|
client_id: req.body.clientId,
|
|
993
|
-
store_id: { $in: req.body.storeId },
|
|
994
1011
|
...( idList.length ) ? { sourceCheckList_id: { $in: idList } } : {},
|
|
1012
|
+
// store_id: { $in: req.body.storeId },
|
|
1013
|
+
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: getUserEmails } } ],
|
|
995
1014
|
},
|
|
996
1015
|
},
|
|
997
1016
|
{ $sort: { date_iso: -1 } },
|
|
998
1017
|
{
|
|
999
1018
|
$group: {
|
|
1000
|
-
_id: '$sourceCheckList_id',
|
|
1001
|
-
checkListName: { $first: '$checkListName' },
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1019
|
+
'_id': '$sourceCheckList_id',
|
|
1020
|
+
'checkListName': { $first: '$checkListName' },
|
|
1021
|
+
'coverage': {
|
|
1022
|
+
'$first': {
|
|
1023
|
+
'$cond': {
|
|
1024
|
+
'if': { '$gt': [ { '$ifNull': [ '$referenceCheckListId', '' ] }, '' ] },
|
|
1025
|
+
'then': 'checklist',
|
|
1026
|
+
'else': '$coverage',
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
},
|
|
1030
|
+
'publishDate': { $first: '$publishDate' },
|
|
1031
|
+
'priorityType': { $first: '$priorityType' },
|
|
1032
|
+
// storeCount: { $first: '$storeCount' },
|
|
1033
|
+
'storeCount': { $sum: 1 },
|
|
1034
|
+
'submitCount': { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
|
|
1035
|
+
'redoCount': { $sum: { $cond: [ { $and: [ { $eq: [ '$redoStatus', true ] }, { $ne: [ '$checklistStatus', 'submit' ] } ] }, 1, 0 ] } },
|
|
1036
|
+
'scheduleEndTime_iso': { $first: '$scheduleEndTime_iso' },
|
|
1037
|
+
'checkListChar': { $first: { $toUpper: { $substr: [ '$createdByName', 0, 2 ] } } },
|
|
1010
1038
|
},
|
|
1011
1039
|
},
|
|
1012
1040
|
];
|
|
@@ -28,6 +28,9 @@ taskRouter
|
|
|
28
28
|
.get( '/teamMigrations', taskController.teamMigrations )
|
|
29
29
|
.get( '/clusterMigrations', taskController.clusterMigrations )
|
|
30
30
|
.post( '/createaiChecklist', isAllowedInternalAPIHandler, taskController.createAiChecklist )
|
|
31
|
+
.post( '/createaiTask', isAllowedInternalAPIHandler, taskController.createAiTask )
|
|
32
|
+
.post( '/assign', isAllowedSessionHandler, taskController.taskAssign )
|
|
33
|
+
.post( '/assignUpload', isAllowedSessionHandler, taskController.assignTaskUser )
|
|
31
34
|
.post( '/createaiTask', isAllowedInternalAPIHandler, validate( aitaskvalidation ), taskController.createAiTask )
|
|
32
35
|
.post( '/StoreHygienetask', isAllowedInternalAPIHandler, validate( StoreHygienetaskvalidation ), taskController.StoreHygienetask )
|
|
33
36
|
.post( '/eyeTesttask', isAllowedInternalAPIHandler, validate( eyeTesttaskvalidation ), taskController.eyeTesttask )
|
|
@@ -8,14 +8,14 @@ import {
|
|
|
8
8
|
|
|
9
9
|
taskDashboardRouter
|
|
10
10
|
.post( '/overallcards', isAllowedSessionHandler, overallCards )
|
|
11
|
-
.post( '/overallcardsV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), overallCardsV1 )
|
|
12
11
|
.post( '/taskTable', isAllowedSessionHandler, taskTable )
|
|
13
12
|
.post( '/taskTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskTableV1 )
|
|
14
13
|
.post( '/taskInfoTable', isAllowedSessionHandler, taskInfoTable )
|
|
15
|
-
.post( '/taskInfoTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskInfoTableV1 )
|
|
16
14
|
.post( '/taskDropdownList', isAllowedSessionHandler, taskDropdownList )
|
|
17
|
-
.post( '/taskDropdownListV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskDropdownListV1 )
|
|
18
15
|
.post( '/taskDeleteV1', isAllowedSessionHandler, taskDeleteV1 )
|
|
19
|
-
.post( '/
|
|
16
|
+
.post( '/taskDropdownListV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskDropdownListV1 )
|
|
17
|
+
.post( '/overallcardsV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), overallCardsV1 )
|
|
18
|
+
.post( '/taskDetails', isAllowedSessionHandler, taskDetails )
|
|
19
|
+
.post( '/taskInfoTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskInfoTableV1 );
|
|
20
20
|
|
|
21
21
|
export default taskDashboardRouter;
|
|
@@ -26,6 +26,7 @@ export async function createclusterModel( data ) {
|
|
|
26
26
|
export async function findcluster( query, project ) {
|
|
27
27
|
return await clusterModel.find( query, project );
|
|
28
28
|
};
|
|
29
|
+
|
|
29
30
|
export function countDocumentsClusters( query ) {
|
|
30
31
|
return clusterModel.countDocuments( query );
|
|
31
32
|
}
|
|
@@ -13,7 +13,7 @@ export const updateMany = async ( query = {}, record={} ) => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export const updateOne = async ( query = {}, record={} ) => {
|
|
16
|
-
return model.taskAssignModel.updateOne( query, { $set: record } );
|
|
16
|
+
return model.taskAssignModel.updateOne( query, { $set: record }, { upsert: true } );
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export const insertMany = async ( data = [] ) => {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import teamsModel from 'tango-api-schema/schema/teams.model.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export async function createTeamsModel( data ) {
|
|
5
|
+
return await teamsModel.create( data );
|
|
6
|
+
};
|
|
7
|
+
export async function updateOneTeams( query, record ) {
|
|
8
|
+
return await teamsModel.updateOne( query, { $set: record }, { upsert: true } );
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function aggregateTeams( query ) {
|
|
12
|
+
return await teamsModel.aggregate( query );
|
|
13
|
+
};
|
|
14
|
+
export async function deleteTeams( query ={} ) {
|
|
15
|
+
return await teamsModel.deleteOne( query );
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function findOneTeams( query ={}, field={} ) {
|
|
19
|
+
return await teamsModel.findOne( query, field );
|
|
20
|
+
};
|
|
21
|
+
export async function findteams( query ={}, field={} ) {
|
|
22
|
+
return await teamsModel.find( query, field );
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export async function updateOneTeamModel( query, record ) {
|
|
26
|
+
return await teamsModel.updateOne( query, record );
|
|
27
|
+
}
|
|
28
|
+
export function countDocumentsTeams( query ) {
|
|
29
|
+
return teamsModel.countDocuments( query );
|
|
30
|
+
}
|