tango-app-api-task 3.2.1-beta-20 → 3.2.1-beta-22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -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-22",
|
|
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 }, { assignId: 1 } );
|
|
268
|
+
assignedusers = assignedusers?.map( ( item ) => item.assignId );
|
|
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,20 +658,22 @@ 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 ) {
|
|
659
664
|
return res.sendError( { message: 'Task Id is Required' }, 400 );
|
|
660
665
|
}
|
|
661
666
|
|
|
662
|
-
if ( inputBody.submitType == 'publish' ) {
|
|
663
|
-
|
|
664
|
-
if ( !checkUserAssigned ) {
|
|
665
|
-
return res.sendError( { message: 'Please assign a user' }, 400 );
|
|
666
|
-
}
|
|
667
|
+
if ( !inputBody.assignedUsers.length && inputBody.submitType == 'publish' ) {
|
|
668
|
+
return res.sendError( 'Please Assigned a user', 400 );
|
|
667
669
|
}
|
|
670
|
+
|
|
671
|
+
// if ( inputBody.submitType == 'publish' ) {
|
|
672
|
+
// let checkUserAssigned = await taskAssignService.findOne( { checkListId: inputBody._id, checkFlag: true } );
|
|
673
|
+
// if ( !checkUserAssigned ) {
|
|
674
|
+
// return res.sendError( { message: 'Please assign a user' }, 400 );
|
|
675
|
+
// }
|
|
676
|
+
// }
|
|
668
677
|
if ( !inputBody?.approver.length && inputBody.submitType == 'publish' ) {
|
|
669
678
|
return res.sendError( { message: 'Please assign approver' }, 400 );
|
|
670
679
|
}
|
|
@@ -682,7 +691,7 @@ export async function taskConfig( req, res ) {
|
|
|
682
691
|
};
|
|
683
692
|
await checklistLogs.create( logInsertData );
|
|
684
693
|
|
|
685
|
-
checklistDetails = await taskService.findOne( { _id: inputBody._id, isdeleted: false } );
|
|
694
|
+
checklistDetails = await taskService.findOne( { _id: inputBody._id, isdeleted: false, client_id: inputBody.clientId } );
|
|
686
695
|
|
|
687
696
|
if ( !checklistDetails ) {
|
|
688
697
|
return res.sendError( 'No data found', 204 );
|
|
@@ -720,39 +729,20 @@ export async function taskConfig( req, res ) {
|
|
|
720
729
|
await traxApprover.insertMany( data );
|
|
721
730
|
}
|
|
722
731
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
await
|
|
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
|
+
};
|
|
742
|
+
await assignUsers( data );
|
|
743
|
+
} ) );
|
|
726
744
|
}
|
|
727
745
|
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
746
|
if ( inputBody.submitType == 'publish' ) {
|
|
757
747
|
let taskName = checklistDetails.checkListName;
|
|
758
748
|
let dueDate = dayjs( configDetails.scheduleEndTimeISO ).format( 'YYYY-MM-DD hh:mm A' );
|
|
@@ -910,7 +900,6 @@ export async function insertSingleProcessData( checklistId ) {
|
|
|
910
900
|
await taskProcessedConfigService.updateOne( { _id: checklistDetails._id }, insertDataPerDay );
|
|
911
901
|
updatedchecklist = checklistDetails;
|
|
912
902
|
}
|
|
913
|
-
|
|
914
903
|
if ( updatedchecklist ) {
|
|
915
904
|
await insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, dateVal, startTimeIso, endTimeIso, insertdata );
|
|
916
905
|
}
|
|
@@ -938,7 +927,80 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
|
|
|
938
927
|
|
|
939
928
|
if ( allQuestion ) {
|
|
940
929
|
let userIdList = [];
|
|
941
|
-
|
|
930
|
+
let assignList = [];
|
|
931
|
+
let assignUserList = [];
|
|
932
|
+
if ( getCLconfig.coverage == 'store' ) {
|
|
933
|
+
let clusterList = allQuestion.filter( ( ele ) => ele?.clusterName ).map( ( item ) => item.assignId );
|
|
934
|
+
if ( clusterList.length ) {
|
|
935
|
+
let clusterDetails = await clusterServices.findcluster( { _id: { $in: clusterList } } );
|
|
936
|
+
if ( clusterDetails.length ) {
|
|
937
|
+
let idList = clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) );
|
|
938
|
+
let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
|
|
939
|
+
if ( getStoreDetails.length ) {
|
|
940
|
+
assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
|
|
941
|
+
let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
|
|
942
|
+
if ( !userDetails ) {
|
|
943
|
+
let data = {
|
|
944
|
+
clientId: store.clientId,
|
|
945
|
+
userName: store.spocDetails?.[0]?.name,
|
|
946
|
+
mobileNumber: store.spocDetails?.[0]?.phone || '',
|
|
947
|
+
email: store.spocDetails[0].email,
|
|
948
|
+
};
|
|
949
|
+
userDetails = await createUser( data );
|
|
950
|
+
}
|
|
951
|
+
let data = {
|
|
952
|
+
store_id: store?.storeId,
|
|
953
|
+
storeName: store?.storeName,
|
|
954
|
+
userId: userDetails._id,
|
|
955
|
+
userName: userDetails.userName,
|
|
956
|
+
userEmail: userDetails.email,
|
|
957
|
+
userPhone: userDetails?.mobileNumber,
|
|
958
|
+
city: store?.storeProfile?.city,
|
|
959
|
+
country: store?.storeProfile?.country,
|
|
960
|
+
checkFlag: true,
|
|
961
|
+
checkListId: getCLconfig._id,
|
|
962
|
+
checkListName: getCLconfig.checkListName,
|
|
963
|
+
client_id: getCLconfig.client_id,
|
|
964
|
+
};
|
|
965
|
+
return data;
|
|
966
|
+
} ) );
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
allQuestion = allQuestion.filter( ( ele ) => !clusterList.includes( ele.assignId ) );
|
|
971
|
+
}
|
|
972
|
+
if ( getCLconfig.coverage == 'user' ) {
|
|
973
|
+
let teamsList = allQuestion.filter( ( ele ) => ele?.teamName ).map( ( item ) => item.assignId );
|
|
974
|
+
if ( teamsList.length ) {
|
|
975
|
+
let teamDetails = await teamsServices.findteams( { _id: { $in: teamsList } } );
|
|
976
|
+
if ( teamDetails.length ) {
|
|
977
|
+
let idList = teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) );
|
|
978
|
+
let getUserDetails = await userService.find( { _id: { $in: idList } } );
|
|
979
|
+
if ( getUserDetails.length ) {
|
|
980
|
+
assignList = getUserDetails.map( ( user ) => {
|
|
981
|
+
let data = {
|
|
982
|
+
store_id: '',
|
|
983
|
+
storeName: '',
|
|
984
|
+
userId: user._id,
|
|
985
|
+
userName: user.userName,
|
|
986
|
+
userEmail: user.email,
|
|
987
|
+
userPhone: user?.mobileNumber,
|
|
988
|
+
city: '',
|
|
989
|
+
country: '',
|
|
990
|
+
checkFlag: true,
|
|
991
|
+
checkListId: getCLconfig._id,
|
|
992
|
+
checkListName: getCLconfig.checkListName,
|
|
993
|
+
client_id: getCLconfig.client_id,
|
|
994
|
+
};
|
|
995
|
+
return data;
|
|
996
|
+
} );
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
allQuestion = allQuestion.filter( ( ele ) => !teamsList.includes( ele.assignId ) );
|
|
1001
|
+
}
|
|
1002
|
+
allQuestion = [ ...allQuestion, ...assignList ];
|
|
1003
|
+
await Promise.all( allQuestion.map( async ( element4 ) => {
|
|
942
1004
|
let query;
|
|
943
1005
|
query = {
|
|
944
1006
|
date_string: dayjs( date ).format( 'YYYY-MM-DD' ),
|
|
@@ -954,38 +1016,39 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
|
|
|
954
1016
|
let getsubmitDetails = await taskProcessedService.find( query );
|
|
955
1017
|
if ( getsubmitDetails.length ) {
|
|
956
1018
|
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
|
-
|
|
1019
|
+
} else {
|
|
1020
|
+
delete element4._id;
|
|
1021
|
+
delete element4.checkFlag;
|
|
1022
|
+
delete element4.isdeleted;
|
|
1023
|
+
delete element4.createdAt;
|
|
1024
|
+
delete element4.updatedAt;
|
|
1025
|
+
element4.checkListId = updatedchecklist._id;
|
|
1026
|
+
element4.checkListName = getCLconfig.checkListName;
|
|
1027
|
+
element4.checkListDescription = getCLconfig.checkListDescription;
|
|
1028
|
+
element4.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
1029
|
+
element4.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
|
|
1030
|
+
element4.allowedOverTime = false;
|
|
1031
|
+
element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
|
|
1032
|
+
element4.scheduleStartTime = '12:00 AM';
|
|
1033
|
+
element4.scheduleStartTime_iso = startTimeIso.format();
|
|
1034
|
+
element4.scheduleEndTime = getCLconfig.scheduleEndTime;
|
|
1035
|
+
element4.scheduleEndTime_iso = endTimeIso.format();
|
|
1036
|
+
element4.createdBy = new ObjectId( getCLconfig.createdBy );
|
|
1037
|
+
element4.createdByName = getCLconfig.createdByName;
|
|
1038
|
+
element4.sourceCheckList_id = getCLconfig._id;
|
|
1039
|
+
element4.checkListType = getCLconfig.checkListType;
|
|
1040
|
+
element4.storeCount = getCLconfig.storeCount;
|
|
1041
|
+
element4.questionCount = getCLconfig.questionCount;
|
|
1042
|
+
element4.publishDate = getCLconfig.publishDate;
|
|
1043
|
+
element4.locationCount = getCLconfig.locationCount;
|
|
1044
|
+
element4.scheduleRepeatedType = 'daily';
|
|
1045
|
+
element4.approvalEnable = getCLconfig.approver.length ? true : false;
|
|
1046
|
+
element4.priorityType = getCLconfig.priorityType;
|
|
1047
|
+
element4.remainder = getCLconfig?.remainder || [];
|
|
1048
|
+
element4.restrictAttendance = getCLconfig?.restrictAttendance;
|
|
1049
|
+
assignUserList.push( element4 );
|
|
1050
|
+
}
|
|
1051
|
+
} ) );
|
|
989
1052
|
if ( userIdList.length ) {
|
|
990
1053
|
allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
|
|
991
1054
|
}
|
|
@@ -1390,8 +1453,9 @@ export async function createChecklistTask( req, res ) {
|
|
|
1390
1453
|
if ( sectionIndex == -1 ) {
|
|
1391
1454
|
return res.sendError( 'section is not found', 400 );
|
|
1392
1455
|
}
|
|
1393
|
-
let
|
|
1456
|
+
let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele?.parentQuestion ? ele.qno == req.body.qno && ele.parentQuestion == req.body.parentQuestion : ele.qno == req.body.qno );
|
|
1394
1457
|
|
|
1458
|
+
let data = { ...question[sectionIndex].questions[findQuestion], taskId: response?._id, task: true };
|
|
1395
1459
|
question[sectionIndex].questions[req.body.qno - 1] = data;
|
|
1396
1460
|
taskDetails.questionAnswers = question;
|
|
1397
1461
|
let updateData = {
|
|
@@ -1464,6 +1528,7 @@ export async function approveTask( req, res ) {
|
|
|
1464
1528
|
sourceCheckList_id: req.body.sourceCheckList_id,
|
|
1465
1529
|
fromDate: req.body.fromDate,
|
|
1466
1530
|
toDate: req.body.toDate,
|
|
1531
|
+
filtertype: req.body.filtertype,
|
|
1467
1532
|
store_id: inputstores,
|
|
1468
1533
|
},
|
|
1469
1534
|
'upsert': {
|
|
@@ -2168,13 +2233,13 @@ export async function clusterMigrations( req, res ) {
|
|
|
2168
2233
|
if ( userexits ) {
|
|
2169
2234
|
let findStore = await storeService.findOne( { storeName: user.FacilityCode } );
|
|
2170
2235
|
if ( findStore ) {
|
|
2171
|
-
let clusterExists = await
|
|
2236
|
+
let clusterExists = await clusterServices.findOneCluster( { clusterName: user.AomName } );
|
|
2172
2237
|
if ( clusterExists ) {
|
|
2173
2238
|
let data = {
|
|
2174
2239
|
storeId: findStore.storeId,
|
|
2175
2240
|
store: findStore._id,
|
|
2176
2241
|
};
|
|
2177
|
-
let updatecluster = await
|
|
2242
|
+
let updatecluster = await clusterServices.updateCluster( { clusterName: user.AomName }, { $push: { stores: data } } );
|
|
2178
2243
|
console.log( updatecluster );
|
|
2179
2244
|
} else {
|
|
2180
2245
|
let payload = {
|
|
@@ -2196,7 +2261,7 @@ export async function clusterMigrations( req, res ) {
|
|
|
2196
2261
|
],
|
|
2197
2262
|
'users': [],
|
|
2198
2263
|
};
|
|
2199
|
-
let createcluster = await
|
|
2264
|
+
let createcluster = await clusterServices.createclusterModel( payload );
|
|
2200
2265
|
console.log( createcluster );
|
|
2201
2266
|
}
|
|
2202
2267
|
}
|
|
@@ -2584,6 +2649,7 @@ export async function StoreHygienetask( req, res ) {
|
|
|
2584
2649
|
export async function eyeTesttask( req, res ) {
|
|
2585
2650
|
try {
|
|
2586
2651
|
let inputBody = req.body;
|
|
2652
|
+
console.log( inputBody );
|
|
2587
2653
|
inputBody.clientId = 11;
|
|
2588
2654
|
inputBody.taskDescription = '';
|
|
2589
2655
|
let userId;
|
|
@@ -2594,7 +2660,9 @@ export async function eyeTesttask( req, res ) {
|
|
|
2594
2660
|
|
|
2595
2661
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
2596
2662
|
let checklistId = url.dailystoreChecklistId;
|
|
2663
|
+
console.log( checklistId );
|
|
2597
2664
|
let finduser = await checklistassignconfigModel.findOne( { checkListId: new mongoose.Types.ObjectId( checklistId ), store_id: storeDetails.storeId } );
|
|
2665
|
+
console.log( finduser );
|
|
2598
2666
|
|
|
2599
2667
|
if ( !finduser ) {
|
|
2600
2668
|
return res.sendError( 'No user Found For this store', 500 );
|
|
@@ -2753,8 +2821,10 @@ export async function eyeTesttask( req, res ) {
|
|
|
2753
2821
|
}
|
|
2754
2822
|
question[0].questionReferenceImage = images;
|
|
2755
2823
|
} else {
|
|
2824
|
+
console.log( req.file );
|
|
2756
2825
|
let images = [];
|
|
2757
2826
|
let uplaodedImage = await uploadmultiImage( req.files.referenceImage );
|
|
2827
|
+
console.log( uplaodedImage );
|
|
2758
2828
|
let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
|
|
2759
2829
|
let url = imgUrl.split( '/' );
|
|
2760
2830
|
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
@@ -3268,6 +3338,339 @@ export async function uploadmultiImage( images ) {
|
|
|
3268
3338
|
}
|
|
3269
3339
|
};
|
|
3270
3340
|
|
|
3341
|
+
export async function taskAssign( req, res ) {
|
|
3342
|
+
try {
|
|
3343
|
+
if ( !req.body.taskId ) {
|
|
3344
|
+
return res.sendError( 'Checklist id is required', 400 );
|
|
3345
|
+
}
|
|
3346
|
+
if ( !req.body.coverage ) {
|
|
3347
|
+
return res.sendError( 'Coverage is required', 400 );
|
|
3348
|
+
}
|
|
3349
|
+
if ( !req.body.idList ) {
|
|
3350
|
+
return res.sendError( 'Id is required', 400 );
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
let taskDetails = await taskService.findOne( { _id: req.body.taskId } );
|
|
3354
|
+
if ( !taskDetails ) {
|
|
3355
|
+
return res.sendError( 'No data found', 204 );
|
|
3356
|
+
}
|
|
3357
|
+
let idList;
|
|
3358
|
+
let assignList;
|
|
3359
|
+
if ( req.body.coverage == 'store' ) {
|
|
3360
|
+
let clusterDetails = await clusterServices.findcluster( { _id: { $in: req.body.idList } }, { stores: 1, clusterName: 1 } );
|
|
3361
|
+
if ( clusterDetails.length ) {
|
|
3362
|
+
let clusterList = clusterDetails.map( ( item ) => item._id.toString() );
|
|
3363
|
+
idList = [
|
|
3364
|
+
...clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) ),
|
|
3365
|
+
...req.body.idList.filter( ( ele ) => !clusterList.includes( ele ) ),
|
|
3366
|
+
];
|
|
3367
|
+
} else {
|
|
3368
|
+
idList = req.body.idList;
|
|
3369
|
+
}
|
|
3370
|
+
let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
|
|
3371
|
+
if ( !getStoreDetails.length ) {
|
|
3372
|
+
return res.sendError( 'No data found', 204 );
|
|
3373
|
+
}
|
|
3374
|
+
assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
|
|
3375
|
+
let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
|
|
3376
|
+
if ( !userDetails ) {
|
|
3377
|
+
let data = {
|
|
3378
|
+
clientId: store.clientId,
|
|
3379
|
+
userName: store.spocDetails?.[0]?.name,
|
|
3380
|
+
mobileNumber: store.spocDetails?.[0]?.phone || '',
|
|
3381
|
+
email: store.spocDetails[0].email,
|
|
3382
|
+
};
|
|
3383
|
+
userDetails = await createUser( data );
|
|
3384
|
+
}
|
|
3385
|
+
let data = {
|
|
3386
|
+
store_id: store.storeId,
|
|
3387
|
+
storeName: store.storeName,
|
|
3388
|
+
userId: userDetails._id,
|
|
3389
|
+
userName: userDetails.userName,
|
|
3390
|
+
userEmail: userDetails.email,
|
|
3391
|
+
userPhone: userDetails?.mobileNumber,
|
|
3392
|
+
clusterName: clusterDetails?.clusterName,
|
|
3393
|
+
};
|
|
3394
|
+
return data;
|
|
3395
|
+
} ) );
|
|
3396
|
+
} else {
|
|
3397
|
+
let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
|
|
3398
|
+
if ( teamDetails.length ) {
|
|
3399
|
+
let teamList = teamDetails.map( ( ele ) => ele._id.toString() );
|
|
3400
|
+
idList = [
|
|
3401
|
+
...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
|
|
3402
|
+
...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
|
|
3403
|
+
];
|
|
3404
|
+
} else {
|
|
3405
|
+
idList = req.body.idList;
|
|
3406
|
+
}
|
|
3407
|
+
let userDetails = await userService.find( { _id: { $in: idList } } );
|
|
3408
|
+
if ( !userDetails.length ) {
|
|
3409
|
+
return res.sendError( 'No data found', 204 );
|
|
3410
|
+
}
|
|
3411
|
+
assignList = [];
|
|
3412
|
+
userDetails.forEach( ( user ) => {
|
|
3413
|
+
assignList.push( {
|
|
3414
|
+
userId: user._id,
|
|
3415
|
+
userName: user.userName,
|
|
3416
|
+
userEmail: user.email,
|
|
3417
|
+
userPhone: user?.mobileNumber,
|
|
3418
|
+
teamName: teamDetails?.teamName,
|
|
3419
|
+
} );
|
|
3420
|
+
} );
|
|
3421
|
+
}
|
|
3422
|
+
return res.sendSuccess( { count: assignList.length, assignList } );
|
|
3423
|
+
} catch ( e ) {
|
|
3424
|
+
logger.error( { functionName: 'checklistAssign', error: e } );
|
|
3425
|
+
return res.sendError( e, 500 );
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
async function assignUsers( data ) {
|
|
3430
|
+
let assignedData;
|
|
3431
|
+
if ( data.coverage == 'store' ) {
|
|
3432
|
+
if ( data?.type == 'cluster' ) {
|
|
3433
|
+
let query = [
|
|
3434
|
+
{
|
|
3435
|
+
$addFields: {
|
|
3436
|
+
cluster: { $toLower: '$clusterName' },
|
|
3437
|
+
},
|
|
3438
|
+
},
|
|
3439
|
+
{
|
|
3440
|
+
$match: {
|
|
3441
|
+
clientId: data.clientId,
|
|
3442
|
+
...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
|
|
3443
|
+
},
|
|
3444
|
+
},
|
|
3445
|
+
{
|
|
3446
|
+
$project: {
|
|
3447
|
+
stores: 1,
|
|
3448
|
+
clusterName: 1,
|
|
3449
|
+
},
|
|
3450
|
+
},
|
|
3451
|
+
];
|
|
3452
|
+
let clusterDetails = await clusterServices.aggregateCluster( query );
|
|
3453
|
+
if ( clusterDetails.length ) {
|
|
3454
|
+
if ( !data.upload ) {
|
|
3455
|
+
assignedData = {
|
|
3456
|
+
checkFlag: true,
|
|
3457
|
+
checkListId: data.checklistId,
|
|
3458
|
+
checkListName: data.checkListName,
|
|
3459
|
+
client_id: data?.clientId,
|
|
3460
|
+
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3461
|
+
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3462
|
+
coverage: 'store',
|
|
3463
|
+
};
|
|
3464
|
+
} else {
|
|
3465
|
+
let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
|
|
3466
|
+
let storeDetails = await storeService.find( { _id: clusterList } );
|
|
3467
|
+
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3468
|
+
let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
|
|
3469
|
+
if ( !userDetails ) {
|
|
3470
|
+
let userData = {
|
|
3471
|
+
userName: store.spocDetails?.[0]?.name,
|
|
3472
|
+
email: store.spocDetails[0].email,
|
|
3473
|
+
mobileNumber: store.spocDetails?.[0]?.phone,
|
|
3474
|
+
clientId: data.clientId,
|
|
3475
|
+
};
|
|
3476
|
+
userDetails = await createUser( userData );
|
|
3477
|
+
}
|
|
3478
|
+
let userData = {
|
|
3479
|
+
userId: userDetails?._id,
|
|
3480
|
+
userName: userDetails?.userName,
|
|
3481
|
+
userEmail: userDetails?.email,
|
|
3482
|
+
userPhone: userDetails?.mobileNumber,
|
|
3483
|
+
checkFlag: true,
|
|
3484
|
+
checkListId: data.checklistId,
|
|
3485
|
+
checkListName: data.checkListName,
|
|
3486
|
+
client_id: data.clientId,
|
|
3487
|
+
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3488
|
+
coverage: 'store',
|
|
3489
|
+
teamName: clusterDetails?.[0]?.clusterName,
|
|
3490
|
+
};
|
|
3491
|
+
return userData;
|
|
3492
|
+
} ) );
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
} else {
|
|
3496
|
+
let query = [
|
|
3497
|
+
{
|
|
3498
|
+
$addFields: {
|
|
3499
|
+
store: { $toLower: '$storeName' },
|
|
3500
|
+
},
|
|
3501
|
+
},
|
|
3502
|
+
{
|
|
3503
|
+
$match: {
|
|
3504
|
+
clientId: data.clientId,
|
|
3505
|
+
...( !data.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
|
|
3506
|
+
},
|
|
3507
|
+
},
|
|
3508
|
+
];
|
|
3509
|
+
let storeDetails = await storeService.aggregate( query );
|
|
3510
|
+
if ( storeDetails.length ) {
|
|
3511
|
+
let email = data?.upload ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
|
|
3512
|
+
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3513
|
+
if ( !userDetails ) {
|
|
3514
|
+
let userData = {
|
|
3515
|
+
userName: storeDetails?.[0]?.spocDetails?.[0]?.name,
|
|
3516
|
+
email: storeDetails?.[0]?.spocDetails[0].email,
|
|
3517
|
+
mobileNumber: storeDetails?.[0]?.spocDetails?.[0]?.phone,
|
|
3518
|
+
clientId: data.clientId,
|
|
3519
|
+
};
|
|
3520
|
+
userDetails = await createUser( userData );
|
|
3521
|
+
}
|
|
3522
|
+
assignedData = {
|
|
3523
|
+
store_id: storeDetails?.[0]?.storeId,
|
|
3524
|
+
storeName: storeDetails?.[0]?.storeName,
|
|
3525
|
+
userId: userDetails._id,
|
|
3526
|
+
userName: userDetails.userName,
|
|
3527
|
+
userEmail: userDetails.email,
|
|
3528
|
+
userPhone: userDetails?.mobileNumber,
|
|
3529
|
+
city: storeDetails?.[0]?.storeProfile?.city,
|
|
3530
|
+
country: storeDetails?.[0]?.storeProfile?.country,
|
|
3531
|
+
checkFlag: true,
|
|
3532
|
+
checkListId: data.checklistId,
|
|
3533
|
+
checkListName: data.checkListName,
|
|
3534
|
+
client_id: data.clientId,
|
|
3535
|
+
assignId: data?.id || storeDetails?.[0]?._id,
|
|
3536
|
+
coverage: 'store',
|
|
3537
|
+
};
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
} else {
|
|
3541
|
+
if ( data.type == 'teams' ) {
|
|
3542
|
+
let query = [
|
|
3543
|
+
{
|
|
3544
|
+
$addFields: {
|
|
3545
|
+
team: { $toLower: '$teamName' },
|
|
3546
|
+
},
|
|
3547
|
+
},
|
|
3548
|
+
{
|
|
3549
|
+
$match: {
|
|
3550
|
+
clientId: data.clientId,
|
|
3551
|
+
...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
|
|
3552
|
+
},
|
|
3553
|
+
},
|
|
3554
|
+
];
|
|
3555
|
+
let teamDetails = await teamsServices.aggregateTeams( query );
|
|
3556
|
+
if ( teamDetails.length ) {
|
|
3557
|
+
if ( !data.upload ) {
|
|
3558
|
+
assignedData = {
|
|
3559
|
+
checkFlag: true,
|
|
3560
|
+
checkListId: data.checklistId,
|
|
3561
|
+
checkListName: data.checkListName,
|
|
3562
|
+
client_id: data.clientId,
|
|
3563
|
+
teamName: teamDetails?.[0]?.teamName,
|
|
3564
|
+
assignId: data?.id || teamDetails?.[0]?._id,
|
|
3565
|
+
coverage: 'user',
|
|
3566
|
+
};
|
|
3567
|
+
} else {
|
|
3568
|
+
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3569
|
+
let userDetails = await userService.find( { _id: userIdList } );
|
|
3570
|
+
assignedData = userDetails.map( ( user ) => {
|
|
3571
|
+
let userData = {
|
|
3572
|
+
userId: user._id,
|
|
3573
|
+
userName: user.userName,
|
|
3574
|
+
userEmail: user.email,
|
|
3575
|
+
userPhone: user.mobileNumber,
|
|
3576
|
+
checkFlag: true,
|
|
3577
|
+
checkListId: data.checklistId,
|
|
3578
|
+
checkListName: data.checkListName,
|
|
3579
|
+
client_id: data.clientId,
|
|
3580
|
+
assignId: data?.id || teamDetails?.[0]?._id,
|
|
3581
|
+
coverage: 'user',
|
|
3582
|
+
teamName: teamDetails?.[0]?.teamName,
|
|
3583
|
+
};
|
|
3584
|
+
return userData;
|
|
3585
|
+
} );
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
} else {
|
|
3589
|
+
let query = [
|
|
3590
|
+
{
|
|
3591
|
+
$addFields: {
|
|
3592
|
+
userEmail: { $toLower: '$email' },
|
|
3593
|
+
},
|
|
3594
|
+
},
|
|
3595
|
+
{
|
|
3596
|
+
$match: {
|
|
3597
|
+
clientId: data.clientId,
|
|
3598
|
+
...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
|
|
3599
|
+
},
|
|
3600
|
+
},
|
|
3601
|
+
];
|
|
3602
|
+
let userDetails = await userService.aggregate( query );
|
|
3603
|
+
if ( !userDetails.length ) {
|
|
3604
|
+
let userData = {
|
|
3605
|
+
userName: data.userEmail.split( '@' )[0],
|
|
3606
|
+
email: data.userEmail,
|
|
3607
|
+
clientId: data.clientId,
|
|
3608
|
+
};
|
|
3609
|
+
let details = await createUser( userData );
|
|
3610
|
+
userDetails = [ details ];
|
|
3611
|
+
}
|
|
3612
|
+
if ( userDetails.length ) {
|
|
3613
|
+
assignedData = {
|
|
3614
|
+
userId: userDetails?.[0]?._id,
|
|
3615
|
+
userName: userDetails?.[0]?.userName,
|
|
3616
|
+
userEmail: userDetails?.[0]?.email,
|
|
3617
|
+
userPhone: userDetails?.[0]?.mobileNumber,
|
|
3618
|
+
checkFlag: true,
|
|
3619
|
+
checkListId: data.checklistId,
|
|
3620
|
+
checkListName: data.checkListName,
|
|
3621
|
+
client_id: data.clientId,
|
|
3622
|
+
assignId: data?.id || userDetails?.[0]?._id,
|
|
3623
|
+
coverage: 'user',
|
|
3624
|
+
};
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
if ( assignedData && !data.upload ) {
|
|
3629
|
+
await taskAssignService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
|
|
3630
|
+
} else {
|
|
3631
|
+
return assignedData;
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
|
|
3635
|
+
export async function assignTaskUser( req, res ) {
|
|
3636
|
+
try {
|
|
3637
|
+
let inputBody = req.body;
|
|
3638
|
+
let assignDetails = inputBody.assignUsers;
|
|
3639
|
+
let newUsers = inputBody.newUsers;
|
|
3640
|
+
let taskDetails = await taskService.findOne( { _id: inputBody.taskId } );
|
|
3641
|
+
if ( !taskDetails ) {
|
|
3642
|
+
return res.sendError( 'No data found', 204 );
|
|
3643
|
+
}
|
|
3644
|
+
await Promise.all( newUsers.map( async ( user ) => {
|
|
3645
|
+
let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
|
|
3646
|
+
let userData = {
|
|
3647
|
+
userName: getUser.userName,
|
|
3648
|
+
email: user,
|
|
3649
|
+
mobileNumber: getUser?.phone,
|
|
3650
|
+
clientId: inputBody.clientId,
|
|
3651
|
+
};
|
|
3652
|
+
await createUser( userData );
|
|
3653
|
+
} ) );
|
|
3654
|
+
let assignData = [];
|
|
3655
|
+
await Promise.all( assignDetails.map( async ( assign ) => {
|
|
3656
|
+
assign.checklistId = inputBody.taskId;
|
|
3657
|
+
assign.checkListName = taskDetails.checkListName;
|
|
3658
|
+
assign.coverage = inputBody.coverage;
|
|
3659
|
+
assign.clientId = inputBody.clientId;
|
|
3660
|
+
assign.upload = inputBody.type;
|
|
3661
|
+
let uploadData = await assignUsers( assign );
|
|
3662
|
+
if ( Array.isArray( uploadData ) ) {
|
|
3663
|
+
assignData.push( ...uploadData );
|
|
3664
|
+
} else {
|
|
3665
|
+
assignData.push( uploadData );
|
|
3666
|
+
}
|
|
3667
|
+
} ) );
|
|
3668
|
+
return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => item.assignId ) ) ], assignData } );
|
|
3669
|
+
} catch ( e ) {
|
|
3670
|
+
logger.error( { functionName: 'assignTaskUser', error: e } );
|
|
3671
|
+
return res.sendError( e, 500 );
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3271
3674
|
|
|
3272
3675
|
export async function customertrial( params ) {
|
|
3273
3676
|
try {
|
|
@@ -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 )
|
|
@@ -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
|
+
}
|