tango-app-api-task 1.0.0-alpha.9 → 1.0.0-beta.2
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 -2
- package/src/controllers/internalAPI.controller.js +12 -9
- package/src/controllers/task.controller.js +441 -51
- package/src/controllers/taskActionCenter.controllers.js +21 -2
- package/src/controllers/taskDashboard.controllers.js +248 -11
- package/src/routes/task.routes.js +5 -1
- package/src/routes/taskDashboard.routes.js +12 -10
- package/src/service/user.service.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-task",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "Task",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"handlebars": "^4.7.8",
|
|
24
24
|
"mongodb": "^6.10.0",
|
|
25
25
|
"nodemon": "^3.1.7",
|
|
26
|
-
"
|
|
26
|
+
"npm": "^10.9.2",
|
|
27
|
+
"tango-api-schema": "^2.1.99",
|
|
27
28
|
"tango-app-api-middleware": "^3.1.43-alpha.10",
|
|
28
29
|
"winston": "^3.17.0",
|
|
29
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -133,21 +133,22 @@ async function insertData( requestData ) {
|
|
|
133
133
|
for ( let [ index2, element2 ] of resultchecklist.entries() ) {
|
|
134
134
|
let getCLconfig = await taskService.findOne( { _id: element2 } );
|
|
135
135
|
if ( getCLconfig ) {
|
|
136
|
-
if ( dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) != dayjs( date ).format( 'YYYY-MM-DD' ) ) {
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
console.log( getCLconfig.scheduleEndTime );
|
|
140
|
-
|
|
136
|
+
// if ( dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) != dayjs( date ).format( 'YYYY-MM-DD' ) ) {
|
|
137
|
+
// getCLconfig.scheduleEndTime = '11:59 PM';
|
|
138
|
+
// }
|
|
139
|
+
// console.log( getCLconfig.scheduleEndTime );
|
|
140
|
+
let sTime = dayjs.utc( getCLconfig.publishDate ).format( 'hh:mm A' );
|
|
141
141
|
let startTimeIso; let endTimeIso;
|
|
142
|
-
startTimeIso = dayjs.utc( `${currentdate}
|
|
143
|
-
endTimeIso = dayjs.utc(
|
|
142
|
+
startTimeIso = dayjs.utc( `${currentdate} ${sTime}`, 'YYYY-MM-DD hh:mm A' );
|
|
143
|
+
endTimeIso = dayjs.utc( getCLconfig.scheduleEndTimeISO );
|
|
144
144
|
console.log( endTimeIso );
|
|
145
145
|
|
|
146
146
|
let insertdata = {};
|
|
147
|
-
insertdata.date_iso =
|
|
147
|
+
insertdata.date_iso = new Date( dayjs( currentdate, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
148
148
|
insertdata.date_string = currentdate;
|
|
149
149
|
insertdata.sourceCheckList_id = getCLconfig._id;
|
|
150
150
|
insertdata.checkListName = getCLconfig.checkListName;
|
|
151
|
+
insertdata.checkListDescription = getCLconfig.checkListDescription;
|
|
151
152
|
insertdata.publish = getCLconfig.publish;
|
|
152
153
|
insertdata.scheduleStartTime = startTimeIso.format();
|
|
153
154
|
insertdata.scheduleStartTime_iso = startTimeIso.format();
|
|
@@ -209,7 +210,7 @@ async function insertData( requestData ) {
|
|
|
209
210
|
checkListId: element2,
|
|
210
211
|
checkFlag: true,
|
|
211
212
|
isdeleted: false,
|
|
212
|
-
...( getCLconfig?.reinitiate ) ? { reinitiate: true } : {},
|
|
213
|
+
// ...( getCLconfig?.reinitiate ) ? { reinitiate: true } : {},
|
|
213
214
|
},
|
|
214
215
|
} );
|
|
215
216
|
let allQuestion = await taskAssignService.aggregate( getquestionQuery );
|
|
@@ -244,6 +245,7 @@ async function insertData( requestData ) {
|
|
|
244
245
|
delete element4.updatedAt;
|
|
245
246
|
element4.checkListId = updatedchecklist._id;
|
|
246
247
|
element4.checkListName = getCLconfig.checkListName;
|
|
248
|
+
element4.checkListDescription = getCLconfig.checkListDescription;
|
|
247
249
|
element4.date_iso = new Date( currentdate );
|
|
248
250
|
element4.date_string = currentdate;
|
|
249
251
|
element4.allowedOverTime = false;
|
|
@@ -261,6 +263,7 @@ async function insertData( requestData ) {
|
|
|
261
263
|
element4.publishDate = getCLconfig.publishDate;
|
|
262
264
|
element4.locationCount = getCLconfig.locationCount;
|
|
263
265
|
element4.scheduleRepeatedType = 'daily';
|
|
266
|
+
element4.priorityType = getCLconfig.priorityType;
|
|
264
267
|
element4.approvalEnable = getCLconfig.approver.length ? true : false;
|
|
265
268
|
}
|
|
266
269
|
if ( userIdList.length ) {
|
|
@@ -17,6 +17,7 @@ dayjs.extend( utc );
|
|
|
17
17
|
dayjs.extend( customParseFormat );
|
|
18
18
|
import * as taskProcessedConfigService from '../service/processedTaskConfig.service.js';
|
|
19
19
|
import * as taskProcessedService from '../service/processedTaskList.service.js';
|
|
20
|
+
import * as ApproverModel from '../service/approver.service.js';
|
|
20
21
|
async function LamdaServiceCall( url, data ) {
|
|
21
22
|
try {
|
|
22
23
|
const requestOptions = {
|
|
@@ -107,11 +108,13 @@ export async function createUpdateTask( req, res ) {
|
|
|
107
108
|
section.questionReferenceImage = image;
|
|
108
109
|
}
|
|
109
110
|
section.answers.forEach( ( answer ) => {
|
|
110
|
-
if ( answer.referenceImage
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
if ( answer.referenceImage.length ) {
|
|
112
|
+
answer.referenceImage = answer.referenceImage.map( ( value ) => {
|
|
113
|
+
let imgUrl = decodeURIComponent( value?.split( '?' )[0] );
|
|
114
|
+
let url = imgUrl.split( '/' );
|
|
115
|
+
url.splice( 0, 3 );
|
|
116
|
+
return url.join( '/' );
|
|
117
|
+
} );
|
|
115
118
|
}
|
|
116
119
|
} );
|
|
117
120
|
} );
|
|
@@ -120,7 +123,7 @@ export async function createUpdateTask( req, res ) {
|
|
|
120
123
|
await processNested( index, question );
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
async function processNested( qIdx, question, nestedIndex
|
|
126
|
+
async function processNested( qIdx, question, nestedIndex = -1 ) {
|
|
124
127
|
if ( question?.answers?.length ) {
|
|
125
128
|
for ( let [ index, answer ] of question?.answers?.entries() ) {
|
|
126
129
|
if ( !section.questions[qIdx].answers[index]?.nestedQuestion && nestedIndex == -1 ) {
|
|
@@ -161,6 +164,7 @@ export async function createUpdateTask( req, res ) {
|
|
|
161
164
|
|
|
162
165
|
if ( req.body._id ) {
|
|
163
166
|
await taskQuestionService.deleteMany( { checkListId: checkListId } );
|
|
167
|
+
await taskAssignService.updateMany( { checkListId: req.body._id }, { checkListName: inputBody.checklistName } );
|
|
164
168
|
}
|
|
165
169
|
await taskQuestionService.insertMany( sectionList );
|
|
166
170
|
let message = req.body?._id ? 'Task Updated Successfully' : 'Task Created Successfully';
|
|
@@ -174,7 +178,7 @@ export async function createUpdateTask( req, res ) {
|
|
|
174
178
|
return res.sendError( { message: 'something went wrong' }, 500 );
|
|
175
179
|
}
|
|
176
180
|
} catch ( e ) {
|
|
177
|
-
logger.error( { functionName: 'createTask', error: e } );
|
|
181
|
+
logger.error( { functionName: 'createTask', error: e, message: req.body } );
|
|
178
182
|
return res.sendError( e, 500 );
|
|
179
183
|
}
|
|
180
184
|
}
|
|
@@ -235,7 +239,7 @@ export async function taskDetails( req, res ) {
|
|
|
235
239
|
let bucket = JSON.parse( process.env.BUCKET );
|
|
236
240
|
questionDetails.forEach( ( item ) => {
|
|
237
241
|
item.question.forEach( async ( question ) => {
|
|
238
|
-
if ( question.questionReferenceImage && question.questionReferenceImage !='' && typeof question.questionReferenceImage == 'string' ) {
|
|
242
|
+
if ( question.questionReferenceImage && question.questionReferenceImage != '' && typeof question.questionReferenceImage == 'string' ) {
|
|
239
243
|
let inputData = {
|
|
240
244
|
Bucket: bucket.sop,
|
|
241
245
|
file_path: decodeURIComponent( question.questionReferenceImage ),
|
|
@@ -255,12 +259,16 @@ export async function taskDetails( req, res ) {
|
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
261
|
question.answers.forEach( async ( answer ) => {
|
|
258
|
-
if ( answer.referenceImage
|
|
259
|
-
let
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
if ( answer.referenceImage.length > 0 ) {
|
|
263
|
+
let updatedImages = [];
|
|
264
|
+
for ( let refImage of answer.referenceImage ) {
|
|
265
|
+
let inputData = {
|
|
266
|
+
Bucket: bucket.sop,
|
|
267
|
+
file_path: decodeURIComponent( refImage ),
|
|
268
|
+
};
|
|
269
|
+
updatedImages.push( await signedUrl( inputData ) );
|
|
270
|
+
}
|
|
271
|
+
answer.referenceImage = updatedImages;
|
|
264
272
|
}
|
|
265
273
|
} );
|
|
266
274
|
} );
|
|
@@ -558,7 +566,7 @@ async function uploadUser( req, res ) {
|
|
|
558
566
|
}
|
|
559
567
|
}
|
|
560
568
|
} catch ( e ) {
|
|
561
|
-
logger.error( { functionName: 'upload User', error: e } );
|
|
569
|
+
logger.error( { functionName: 'upload User', error: e, message: req.body } );
|
|
562
570
|
return res.sendError( e, 500 );
|
|
563
571
|
}
|
|
564
572
|
}
|
|
@@ -616,7 +624,7 @@ export async function userDetails( req, res ) {
|
|
|
616
624
|
} );
|
|
617
625
|
return res.sendSuccess( { users: userDetails, count: taskDetails[0].count[0].total } );
|
|
618
626
|
} catch ( e ) {
|
|
619
|
-
logger.error( { functionName: 'userDetails', error: e } );
|
|
627
|
+
logger.error( { functionName: 'userDetails', error: e, message: req.body } );
|
|
620
628
|
return res.sendError( e, 500 );
|
|
621
629
|
}
|
|
622
630
|
};
|
|
@@ -638,9 +646,12 @@ export async function taskConfig( req, res ) {
|
|
|
638
646
|
return res.sendError( { message: 'Please assign a user' }, 400 );
|
|
639
647
|
}
|
|
640
648
|
}
|
|
649
|
+
if ( !inputBody?.approver.length && inputBody.submitType == 'publish' ) {
|
|
650
|
+
return res.sendError( { message: 'Please assign approver' }, 400 );
|
|
651
|
+
}
|
|
641
652
|
|
|
642
653
|
let logInsertData = {
|
|
643
|
-
action: inputBody.submitType == 'publish' ? '
|
|
654
|
+
action: inputBody.submitType == 'publish' ? 'taskPublishUsingConfigPage' : 'taskConfigDraft',
|
|
644
655
|
checklistId: inputBody._id,
|
|
645
656
|
checkListName: inputBody?.checkListName,
|
|
646
657
|
createdBy: req.user._id,
|
|
@@ -656,13 +667,17 @@ export async function taskConfig( req, res ) {
|
|
|
656
667
|
}
|
|
657
668
|
|
|
658
669
|
let configDetails = { ...req.body };
|
|
659
|
-
configDetails.
|
|
660
|
-
|
|
670
|
+
configDetails.approver = configDetails.approver.length ? configDetails.approver.map( ( item ) => {
|
|
671
|
+
return { name: item.name, value: item.value };
|
|
672
|
+
} ) : [];
|
|
673
|
+
let endDate = dayjs.utc( configDetails?.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + configDetails.scheduleEndTime;
|
|
674
|
+
configDetails.scheduleEndTimeISO = dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format();
|
|
675
|
+
configDetails.publishDate = dayjs.utc( dayjs().format( 'hh:mm A' ), 'hh:mm A' ).format();
|
|
661
676
|
|
|
662
677
|
let response = await taskService.updateOne( { _id: inputBody._id }, configDetails );
|
|
663
678
|
if ( inputBody?.approver.length ) {
|
|
664
679
|
let data = [];
|
|
665
|
-
let existEmail = await traxApprover.find( { checkListId: inputBody._id,
|
|
680
|
+
let existEmail = await traxApprover.find( { checkListId: inputBody._id, isdeleted: false } );
|
|
666
681
|
let mailList = existEmail.map( ( item ) => item.userEmail );
|
|
667
682
|
existEmail = inputBody?.approver.filter( ( item ) => mailList.includes( item.value ) ).map( ( item ) => item.value );
|
|
668
683
|
let userMailList = inputBody?.approver.map( ( ele ) => ele.value );
|
|
@@ -677,7 +692,7 @@ export async function taskConfig( req, res ) {
|
|
|
677
692
|
}
|
|
678
693
|
} );
|
|
679
694
|
|
|
680
|
-
await traxApprover.updateMany( { checkListId: inputBody._id, userEmail: { $nin: userMailList } }, {
|
|
695
|
+
await traxApprover.updateMany( { checkListId: inputBody._id, userEmail: { $nin: userMailList } }, { isdeleted: true } );
|
|
681
696
|
if ( data.length ) {
|
|
682
697
|
await traxApprover.insertMany( data );
|
|
683
698
|
}
|
|
@@ -716,10 +731,9 @@ export async function taskConfig( req, res ) {
|
|
|
716
731
|
}
|
|
717
732
|
await taskService.updateOne( { _id: inputBody._id }, { storeCount, locationCount } );
|
|
718
733
|
if ( inputBody.submitType == 'publish' ) {
|
|
719
|
-
let
|
|
720
|
-
let
|
|
721
|
-
|
|
722
|
-
if ( updatedscheduleEndTimeISO >= currentDate ) {
|
|
734
|
+
let tDate = dayjs().format( 'YYYY-MM-DD' ) + ' ' + dayjs().format( 'hh:mm A' );
|
|
735
|
+
let currentDate = dayjs( tDate, 'YYYY-MM-DD hh:mm A' ).format();
|
|
736
|
+
if ( configDetails.scheduleEndTimeISO >= currentDate ) {
|
|
723
737
|
let deleteQuery = {
|
|
724
738
|
$and: [
|
|
725
739
|
{ date_string: dayjs().format( 'YYYY-MM-DD' ) },
|
|
@@ -745,7 +759,7 @@ export async function taskConfig( req, res ) {
|
|
|
745
759
|
}
|
|
746
760
|
}
|
|
747
761
|
} catch ( e ) {
|
|
748
|
-
logger.error( { functionName: '
|
|
762
|
+
logger.error( { functionName: 'taskConfig =>', error: e, message: req.body } );
|
|
749
763
|
return res.sendError( e, 500 );
|
|
750
764
|
}
|
|
751
765
|
}
|
|
@@ -760,20 +774,21 @@ export async function insertSingleProcessData( checklistId ) {
|
|
|
760
774
|
let endDate = dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + getCLconfig.scheduleEndTime;
|
|
761
775
|
endDate = dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format();
|
|
762
776
|
if ( endDate >= date ) {
|
|
763
|
-
if ( dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) != dayjs( currentdate ).format( 'YYYY-MM-DD' ) ) {
|
|
764
|
-
|
|
765
|
-
}
|
|
777
|
+
// if ( dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) != dayjs( currentdate ).format( 'YYYY-MM-DD' ) ) {
|
|
778
|
+
// getCLconfig.scheduleEndTime = '11:59 PM';
|
|
779
|
+
// }
|
|
766
780
|
} else {
|
|
767
781
|
return false;
|
|
768
782
|
}
|
|
769
|
-
|
|
770
|
-
startTimeIso = dayjs.utc(
|
|
771
|
-
endTimeIso = dayjs.utc( getCLconfig.
|
|
783
|
+
let sTime = dayjs.utc( getCLconfig.publishDate ).format( 'hh:mm A' );
|
|
784
|
+
startTimeIso = dayjs.utc( sTime, 'hh:mm A' );
|
|
785
|
+
endTimeIso = dayjs.utc( getCLconfig.scheduleEndTimeISO );
|
|
772
786
|
let insertdata = {};
|
|
773
|
-
insertdata.date_iso =
|
|
787
|
+
insertdata.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
774
788
|
insertdata.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
|
|
775
789
|
insertdata.sourceCheckList_id = getCLconfig._id;
|
|
776
790
|
insertdata.checkListName = getCLconfig.checkListName;
|
|
791
|
+
insertdata.checkListDescription = getCLconfig.checkListDescription;
|
|
777
792
|
insertdata.publish = getCLconfig.publish;
|
|
778
793
|
insertdata.scheduleStartTime = '12:00 AM';
|
|
779
794
|
insertdata.scheduleStartTime_iso = startTimeIso.format();
|
|
@@ -832,7 +847,7 @@ export async function insertSingleProcessData( checklistId ) {
|
|
|
832
847
|
}
|
|
833
848
|
return true;
|
|
834
849
|
} catch ( error ) {
|
|
835
|
-
logger.error( 'PCLchecklistCreationValidator error =>', error );
|
|
850
|
+
logger.error( { function: 'PCLchecklistCreationValidator error =>', error: error } );
|
|
836
851
|
return false;
|
|
837
852
|
}
|
|
838
853
|
};
|
|
@@ -844,10 +859,11 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
|
|
|
844
859
|
checkListId: new ObjectId( checklistId ),
|
|
845
860
|
checkFlag: true,
|
|
846
861
|
isdeleted: false,
|
|
847
|
-
...( getCLconfig?.reinitiate ) ? { reinitiate: true } : {},
|
|
862
|
+
// ...( getCLconfig?.reinitiate ) ? { reinitiate: true } : {},
|
|
848
863
|
},
|
|
849
864
|
} );
|
|
850
865
|
let allQuestion = await taskAssignService.aggregate( getquestionQuery );
|
|
866
|
+
|
|
851
867
|
if ( allQuestion ) {
|
|
852
868
|
let userIdList = [];
|
|
853
869
|
for ( let element4 of allQuestion ) {
|
|
@@ -856,7 +872,8 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
|
|
|
856
872
|
date_string: date,
|
|
857
873
|
sourceCheckList_id: getCLconfig._id,
|
|
858
874
|
$or: [ {
|
|
859
|
-
checklistStatus: { $in: [ 'submit' ] }
|
|
875
|
+
checklistStatus: { $in: [ 'submit' ] },
|
|
876
|
+
},
|
|
860
877
|
{ submitTime: { $exists: true } },
|
|
861
878
|
],
|
|
862
879
|
userId: element4.userId,
|
|
@@ -874,7 +891,8 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
|
|
|
874
891
|
delete element4.updatedAt;
|
|
875
892
|
element4.checkListId = updatedchecklist._id;
|
|
876
893
|
element4.checkListName = getCLconfig.checkListName;
|
|
877
|
-
element4.
|
|
894
|
+
element4.checkListDescription = getCLconfig.checkListDescription;
|
|
895
|
+
element4.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
878
896
|
element4.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
|
|
879
897
|
element4.allowedOverTime = false;
|
|
880
898
|
element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
|
|
@@ -892,6 +910,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
|
|
|
892
910
|
element4.locationCount = getCLconfig.locationCount;
|
|
893
911
|
element4.scheduleRepeatedType = 'daily';
|
|
894
912
|
element4.approvalEnable = getCLconfig.approver.length ? true : false;
|
|
913
|
+
element4.priorityType = getCLconfig.priorityType;
|
|
895
914
|
}
|
|
896
915
|
if ( userIdList.length ) {
|
|
897
916
|
allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
|
|
@@ -901,7 +920,6 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
|
|
|
901
920
|
assigndeletequery.date_string = insertdata.date_string;
|
|
902
921
|
assigndeletequery.date_iso = insertdata.date_iso;
|
|
903
922
|
assigndeletequery.client_id = insertdata.client_id;
|
|
904
|
-
assigndeletequery.brandId = insertdata.brandId;
|
|
905
923
|
assigndeletequery.checkListId = updatedchecklist._id;
|
|
906
924
|
assigndeletequery.checklistStatus = { $nin: [ 'submit' ] };
|
|
907
925
|
await taskProcessedService.deleteMany( assigndeletequery );
|
|
@@ -985,7 +1003,7 @@ async function createUser( data ) {
|
|
|
985
1003
|
|
|
986
1004
|
export async function reinitiateTask( req, res ) {
|
|
987
1005
|
try {
|
|
988
|
-
let taskDetails = await taskService.findOne( { _id: req.body.taskId,
|
|
1006
|
+
let taskDetails = await taskService.findOne( { _id: req.body.taskId, isdeleted: false } );
|
|
989
1007
|
if ( !taskDetails ) {
|
|
990
1008
|
return res.sendError( 'no data found', 204 );
|
|
991
1009
|
}
|
|
@@ -1001,7 +1019,7 @@ export async function reinitiateTask( req, res ) {
|
|
|
1001
1019
|
|
|
1002
1020
|
if ( req.body?.approver.length ) {
|
|
1003
1021
|
let data = [];
|
|
1004
|
-
let existEmail = await traxApprover.find( { checkListId: req.body.taskId,
|
|
1022
|
+
let existEmail = await traxApprover.find( { checkListId: req.body.taskId, isdeleted: false } );
|
|
1005
1023
|
let mailList = existEmail.map( ( item ) => item.userEmail );
|
|
1006
1024
|
existEmail = req.body?.approver.filter( ( item ) => mailList.includes( item.value ) ).map( ( item ) => item.value );
|
|
1007
1025
|
let userMailList = req.body?.approver.map( ( ele ) => ele.value );
|
|
@@ -1016,7 +1034,7 @@ export async function reinitiateTask( req, res ) {
|
|
|
1016
1034
|
}
|
|
1017
1035
|
} );
|
|
1018
1036
|
|
|
1019
|
-
await traxApprover.updateMany( { checkListId: req.body.taskId, userEmail: { $nin: userMailList } }, {
|
|
1037
|
+
await traxApprover.updateMany( { checkListId: req.body.taskId, userEmail: { $nin: userMailList } }, { isdeleted: true } );
|
|
1020
1038
|
if ( data.length ) {
|
|
1021
1039
|
await traxApprover.insertMany( data );
|
|
1022
1040
|
}
|
|
@@ -1066,10 +1084,39 @@ export async function createChecklistTask( req, res ) {
|
|
|
1066
1084
|
checkListType: inputBody.checkListType,
|
|
1067
1085
|
publishDate: new Date(),
|
|
1068
1086
|
locationCount: 1,
|
|
1069
|
-
referenceCheckListId: inputBody?.checkListId
|
|
1087
|
+
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
1070
1088
|
};
|
|
1071
1089
|
|
|
1090
|
+
if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.user.role ) ) ) {
|
|
1091
|
+
let userList = await userService.findOne( { clientId: inputBody.clientId, role: 'superadmin' }, { userName: 1, email: 1 } );
|
|
1092
|
+
if ( userList ) {
|
|
1093
|
+
data['approver'] = { name: userList.userName, value: userList.email };
|
|
1094
|
+
}
|
|
1095
|
+
} else {
|
|
1096
|
+
data['approver'] = { name: req.user.userName, value: req.user.email };
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
let taskNameDetails = await taskService.find( { checkListName: { $regex: data.checkListName, $options: 'i' }, client_id: data.client_id, isdeleted: false } );
|
|
1100
|
+
if ( taskNameDetails.length ) {
|
|
1101
|
+
let nameLength = taskNameDetails.length;
|
|
1102
|
+
data.checkListName = data.checkListName.split( '(' )[0] + '(' + nameLength +')';
|
|
1103
|
+
} else {
|
|
1104
|
+
data.checkListName = data.checkListName;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1072
1107
|
let response = await taskService.create( data );
|
|
1108
|
+
if ( response?.approver.length ) {
|
|
1109
|
+
let data = [];
|
|
1110
|
+
response?.approver.forEach( ( ele ) => {
|
|
1111
|
+
data.push( {
|
|
1112
|
+
userEmail: ele.value,
|
|
1113
|
+
checkListId: response._id,
|
|
1114
|
+
type: 'task',
|
|
1115
|
+
client_id: inputBody.clientId,
|
|
1116
|
+
} );
|
|
1117
|
+
} );
|
|
1118
|
+
await traxApprover.insertMany( data );
|
|
1119
|
+
}
|
|
1073
1120
|
|
|
1074
1121
|
if ( response?._id ) {
|
|
1075
1122
|
if ( inputBody.question[0].questionReferenceImage.length ) {
|
|
@@ -1082,11 +1129,23 @@ export async function createChecklistTask( req, res ) {
|
|
|
1082
1129
|
} );
|
|
1083
1130
|
inputBody.question[0].questionReferenceImage = images;
|
|
1084
1131
|
}
|
|
1132
|
+
if ( inputBody.question[0].answers[0].referenceImage.length ) {
|
|
1133
|
+
let images = [];
|
|
1134
|
+
inputBody.question[0].answers[0].referenceImage.forEach( ( ele ) => {
|
|
1135
|
+
let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
|
|
1136
|
+
let url = imgUrl.split( '/' );
|
|
1137
|
+
if ( url.includes( 'https' ) || url.includes( 'http' ) ) {
|
|
1138
|
+
url.splice( 0, 3 );
|
|
1139
|
+
}
|
|
1140
|
+
images.push( url.join( '/' ) );
|
|
1141
|
+
} );
|
|
1142
|
+
inputBody.question[0].answers[0].referenceImage = images;
|
|
1143
|
+
}
|
|
1085
1144
|
let question = {
|
|
1086
1145
|
checkListId: response?._id,
|
|
1087
1146
|
question: inputBody.question,
|
|
1088
1147
|
section: 'Section 1',
|
|
1089
|
-
checkList:
|
|
1148
|
+
checkList: data.checkListName,
|
|
1090
1149
|
client_id: inputBody.clientId,
|
|
1091
1150
|
};
|
|
1092
1151
|
await taskQuestionService.create( question );
|
|
@@ -1102,7 +1161,7 @@ export async function createChecklistTask( req, res ) {
|
|
|
1102
1161
|
city: storeDetails?.storeProfile?.city,
|
|
1103
1162
|
checkFlag: true,
|
|
1104
1163
|
checkListId: response?._id,
|
|
1105
|
-
checkListName:
|
|
1164
|
+
checkListName: data.checkListName,
|
|
1106
1165
|
client_id: inputBody.clientId,
|
|
1107
1166
|
userId: userId,
|
|
1108
1167
|
};
|
|
@@ -1154,7 +1213,7 @@ export async function createChecklistTask( req, res ) {
|
|
|
1154
1213
|
return res.sendSuccess( 'Task created successfully' );
|
|
1155
1214
|
}
|
|
1156
1215
|
} catch ( e ) {
|
|
1157
|
-
logger.error( { functionName: 'createChecklistTask', error: e } );
|
|
1216
|
+
logger.error( { functionName: 'createChecklistTask', error: e, message: req.body } );
|
|
1158
1217
|
return res.sendError( e, 500 );
|
|
1159
1218
|
}
|
|
1160
1219
|
}
|
|
@@ -1194,7 +1253,9 @@ export async function approveTask( req, res ) {
|
|
|
1194
1253
|
},
|
|
1195
1254
|
body: JSON.stringify( params ),
|
|
1196
1255
|
};
|
|
1197
|
-
let
|
|
1256
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
1257
|
+
|
|
1258
|
+
let searchResponse = await fetch( url.approveTask, requestOptions );
|
|
1198
1259
|
if ( searchResponse.ok ) {
|
|
1199
1260
|
return res.sendSuccess( 'Task Approved successfully' );
|
|
1200
1261
|
} else {
|
|
@@ -1202,7 +1263,7 @@ export async function approveTask( req, res ) {
|
|
|
1202
1263
|
}
|
|
1203
1264
|
}
|
|
1204
1265
|
} catch ( e ) {
|
|
1205
|
-
logger.error( { function: 'approveTask', error: e } );
|
|
1266
|
+
logger.error( { function: 'approveTask', error: e, message: req.body } );
|
|
1206
1267
|
return res.sendError( e, 500 );
|
|
1207
1268
|
}
|
|
1208
1269
|
}
|
|
@@ -1219,7 +1280,7 @@ export async function redoTask( req, res ) {
|
|
|
1219
1280
|
return res.sendError( 'Question number is Required', 400 );
|
|
1220
1281
|
}
|
|
1221
1282
|
|
|
1222
|
-
let taskDetails = await taskProcessedService.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1 } );
|
|
1283
|
+
let taskDetails = await taskProcessedService.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1 } );
|
|
1223
1284
|
if ( !taskDetails ) {
|
|
1224
1285
|
return res.sendError( 'No data found', 204 );
|
|
1225
1286
|
}
|
|
@@ -1244,6 +1305,7 @@ export async function redoTask( req, res ) {
|
|
|
1244
1305
|
data = {
|
|
1245
1306
|
checklistId: taskDetails.sourceCheckList_id,
|
|
1246
1307
|
checkListName: taskDetails.checkListName,
|
|
1308
|
+
checklistDescription: req.body.payload.checklistDescription,
|
|
1247
1309
|
sectionId: req.body.payload.section_id,
|
|
1248
1310
|
sectionName: question[sectionIndex].sectionName,
|
|
1249
1311
|
questionName: question[sectionIndex].questions[req.body.payload.qno - 1].qname,
|
|
@@ -1254,6 +1316,11 @@ export async function redoTask( req, res ) {
|
|
|
1254
1316
|
processedChecklistId: taskDetails._id,
|
|
1255
1317
|
type: taskDetails.checkListType,
|
|
1256
1318
|
userAnswer: userAnswer,
|
|
1319
|
+
initiatedBy: req.user.userName,
|
|
1320
|
+
initiatedTime: dayjs().format(),
|
|
1321
|
+
answerType: question[sectionIndex].questions[req.body.payload.qno - 1].answerType,
|
|
1322
|
+
submitedBy: taskDetails.userName,
|
|
1323
|
+
submitTime: taskDetails.submitTime,
|
|
1257
1324
|
};
|
|
1258
1325
|
await checklistLogs.create( data );
|
|
1259
1326
|
const requestOptions = {
|
|
@@ -1263,7 +1330,8 @@ export async function redoTask( req, res ) {
|
|
|
1263
1330
|
},
|
|
1264
1331
|
body: JSON.stringify( req.body ),
|
|
1265
1332
|
};
|
|
1266
|
-
let
|
|
1333
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
1334
|
+
let searchResponse = await fetch( url.redoTask, requestOptions );
|
|
1267
1335
|
if ( searchResponse.ok ) {
|
|
1268
1336
|
return res.sendSuccess( 'Question redo successfully' );
|
|
1269
1337
|
} else {
|
|
@@ -1273,7 +1341,7 @@ export async function redoTask( req, res ) {
|
|
|
1273
1341
|
return res.sendError( 'Something went wrong', 500 );
|
|
1274
1342
|
}
|
|
1275
1343
|
} catch ( e ) {
|
|
1276
|
-
logger.error( { function: 'redoChecklist', error: e } );
|
|
1344
|
+
logger.error( { function: 'redoChecklist', error: e, message: req.body } );
|
|
1277
1345
|
return res.sendError( e, 500 );
|
|
1278
1346
|
}
|
|
1279
1347
|
}
|
|
@@ -1422,7 +1490,7 @@ export const taskDropdown = async ( req, res ) => {
|
|
|
1422
1490
|
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
1423
1491
|
}
|
|
1424
1492
|
|
|
1425
|
-
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
1493
|
+
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy != '' ) {
|
|
1426
1494
|
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
1427
1495
|
} else {
|
|
1428
1496
|
findQuery.push( { $sort: { ['checkListName']: -1 } } );
|
|
@@ -1436,3 +1504,325 @@ export const taskDropdown = async ( req, res ) => {
|
|
|
1436
1504
|
return res.sendError( { error: error }, 500 );
|
|
1437
1505
|
}
|
|
1438
1506
|
};
|
|
1507
|
+
export async function approvalstatus( req, res ) {
|
|
1508
|
+
try {
|
|
1509
|
+
let Approver = await ApproverModel.find( { checkListId: req.body.checklistId } );
|
|
1510
|
+
if ( Approver.length === 0 ) {
|
|
1511
|
+
return res.sendSuccess( 'suceess' );
|
|
1512
|
+
}
|
|
1513
|
+
let filterApprover = Approver.filter( ( data ) => data.userEmail=== req.user.email );
|
|
1514
|
+
if ( filterApprover.length === 0 ) {
|
|
1515
|
+
return res.sendSuccess( 'suceess' );
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
|
|
1519
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
1520
|
+
let resultData = await LamdaServiceCall( url.approvalstatus, req.body );
|
|
1521
|
+
console.log( resultData );
|
|
1522
|
+
if ( resultData ) {
|
|
1523
|
+
if ( resultData.status_code == '200' ) {
|
|
1524
|
+
return res.sendSuccess( resultData );
|
|
1525
|
+
} else {
|
|
1526
|
+
return res.sendError( 'No Content', 204 );
|
|
1527
|
+
}
|
|
1528
|
+
} else {
|
|
1529
|
+
return res.sendError( 'No Content', 204 );
|
|
1530
|
+
}
|
|
1531
|
+
} catch ( error ) {
|
|
1532
|
+
logger.error( error, 'approvalstatus' );
|
|
1533
|
+
return res.sendError( error, 500 );
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
export const taskList = async ( req, res ) => {
|
|
1538
|
+
try {
|
|
1539
|
+
let limit = parseInt( req.query.limit ) || 10;
|
|
1540
|
+
let offset = parseInt( req.query.offset - 1 ) || 0;
|
|
1541
|
+
let page = offset * limit;
|
|
1542
|
+
let query = [];
|
|
1543
|
+
query.push(
|
|
1544
|
+
{
|
|
1545
|
+
$match: {
|
|
1546
|
+
checkListType: { $in: [ 'task', 'checklistTask', 'cctv' ] },
|
|
1547
|
+
client_id: req.query.clientId,
|
|
1548
|
+
isdeleted: false,
|
|
1549
|
+
},
|
|
1550
|
+
},
|
|
1551
|
+
);
|
|
1552
|
+
|
|
1553
|
+
if ( req.query.search && req.query.search != '' ) {
|
|
1554
|
+
req.query.search = req.query.search.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1' );
|
|
1555
|
+
query.push( {
|
|
1556
|
+
$match: {
|
|
1557
|
+
checkListName: { $regex: new RegExp( req.query.search, 'i' ) },
|
|
1558
|
+
},
|
|
1559
|
+
} );
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
query.push(
|
|
1563
|
+
{
|
|
1564
|
+
$project: {
|
|
1565
|
+
checkList: { $toLower: '$checkListName' },
|
|
1566
|
+
checkListName: 1,
|
|
1567
|
+
createdBy: 1,
|
|
1568
|
+
userName: { $toLower: '$createdByName' },
|
|
1569
|
+
createdByName: 1,
|
|
1570
|
+
storeCount: 1,
|
|
1571
|
+
createdAt: 1,
|
|
1572
|
+
publish: 1,
|
|
1573
|
+
checkListType: 1,
|
|
1574
|
+
questionCount: 1,
|
|
1575
|
+
checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
|
|
1576
|
+
priorityType: 1,
|
|
1577
|
+
scheduleEndTimeISO: 1,
|
|
1578
|
+
},
|
|
1579
|
+
},
|
|
1580
|
+
);
|
|
1581
|
+
|
|
1582
|
+
if ( req.query.sortColumnName && req.query.sortColumnName != '' && req.query.sortBy != '' ) {
|
|
1583
|
+
if ( req.query.sortColumnName == 'status' ) {
|
|
1584
|
+
req.query.sortColumnName = 'publish';
|
|
1585
|
+
}
|
|
1586
|
+
if ( req.query.sortColumnName != 'publish' ) {
|
|
1587
|
+
query.push( {
|
|
1588
|
+
$addFields: { lowerName: { $toLower: `$${req.query.sortColumnName}` } },
|
|
1589
|
+
} );
|
|
1590
|
+
query.push( {
|
|
1591
|
+
$sort: { lowerName: parseInt( req.query.sortBy ) },
|
|
1592
|
+
} );
|
|
1593
|
+
} else {
|
|
1594
|
+
query.push( {
|
|
1595
|
+
$sort: { publish: parseInt( req.query.sortBy ) },
|
|
1596
|
+
} );
|
|
1597
|
+
}
|
|
1598
|
+
} else {
|
|
1599
|
+
query.push(
|
|
1600
|
+
{ $sort: { createdAt: -1 } },
|
|
1601
|
+
);
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
query.push( {
|
|
1605
|
+
$facet: {
|
|
1606
|
+
data: [
|
|
1607
|
+
{ $skip: page },
|
|
1608
|
+
{ $limit: limit },
|
|
1609
|
+
],
|
|
1610
|
+
count: [
|
|
1611
|
+
{ $count: 'totalCount' },
|
|
1612
|
+
],
|
|
1613
|
+
},
|
|
1614
|
+
} );
|
|
1615
|
+
|
|
1616
|
+
let checkList = await taskService.aggregate( query );
|
|
1617
|
+
if ( !checkList[0].data.length ) {
|
|
1618
|
+
return res.sendError( 'no data found', 204 );
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
checkList[0].data.forEach( ( item ) => {
|
|
1622
|
+
if ( item.storeCount > 0 && item.storeCount <= 9 ) {
|
|
1623
|
+
item.storeCount = '0' + item.storeCount;
|
|
1624
|
+
}
|
|
1625
|
+
if ( item.questionCount > 0 && item.questionCount <= 9 ) {
|
|
1626
|
+
item.questionCount = '0' + item.questionCount;
|
|
1627
|
+
}
|
|
1628
|
+
item.createdAt = dayjs( item.createdAt ).format( 'DD MMM, YYYY' );
|
|
1629
|
+
} );
|
|
1630
|
+
|
|
1631
|
+
return res.sendSuccess( { result: checkList[0].data, count: checkList[0].count[0].totalCount } );
|
|
1632
|
+
} catch ( e ) {
|
|
1633
|
+
logger.error( 'taskList', e );
|
|
1634
|
+
return res.sendError( e, 500 );
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
|
|
1638
|
+
export const updatePublish = async ( req, res ) => {
|
|
1639
|
+
try {
|
|
1640
|
+
if ( typeof req?.body?.checklistId == 'undefined' && typeof req.body.type == 'undefined' ) {
|
|
1641
|
+
return res.sendError( { message: 'checklistId or type is required' }, 400 );
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
if ( typeof req?.body?.publish == 'undefined' ) {
|
|
1645
|
+
return res.sendError( { message: 'publish is required' }, 400 );
|
|
1646
|
+
}
|
|
1647
|
+
let getCheckDetails;
|
|
1648
|
+
let query;
|
|
1649
|
+
|
|
1650
|
+
if ( req.body.checklistId ) {
|
|
1651
|
+
query = { _id: req.body.checklistId };
|
|
1652
|
+
getCheckDetails = await taskService.findOne( { _id: req.body.checklistId, client_id: req.body.clientId } );
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
if ( !getCheckDetails ) {
|
|
1656
|
+
return res.sendError( 'No data found', 204 );
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
if ( getCheckDetails?.publishDate ) {
|
|
1660
|
+
let date = dayjs();
|
|
1661
|
+
let diff = date.diff( dayjs.utc( getCheckDetails?.publishDate ), 'minutes' );
|
|
1662
|
+
if ( diff < 5 ) {
|
|
1663
|
+
let mins = ( 5 - diff ) > 1 ? 'minutes' : 'minute';
|
|
1664
|
+
return res.sendError( `Please try after ${5 - diff} ${mins}`, 400 );
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
getCheckDetails.publish = req.body.publish;
|
|
1669
|
+
getCheckDetails.publishDate = req.body.publish ? new Date() : getCheckDetails?.publishDate;
|
|
1670
|
+
let currentDate = dayjs();
|
|
1671
|
+
if ( !req.body.publish ) {
|
|
1672
|
+
await taskProcessedConfigService.deleteMany( { date_string: { $gt: currentDate.format( 'YYYY-MM-DD' ) }, date_iso: { $gt: currentDate.format( '' ) }, sourceCheckList_id: req.body.checklistId } );
|
|
1673
|
+
await taskProcessedService.deleteMany( { date_string: { $gt: currentDate.format( 'YYYY-MM-DD' ) }, date_iso: { $gt: currentDate.format( '' ) }, sourceCheckList_id: req.body.checklistId, checklistStatus: { $ne: 'submit' } } );
|
|
1674
|
+
logger.info( { function: 'updatePublish', query: { date_string: { $gt: currentDate.format( 'YYYY-MM-DD' ) }, date_iso: { $gt: currentDate.format( '' ) }, sourceCheckList_id: req.body.checklistId, checklistStatus: { $ne: 'submit' } } } );
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
await taskService.updateOne( query, getCheckDetails );
|
|
1679
|
+
if ( true ) {
|
|
1680
|
+
let currentDate = dayjs.utc().format();
|
|
1681
|
+
let updatedscheduleEndTimeISO = dayjs.utc( getCheckDetails.scheduleEndTimeISO ).format( 'HH:mm:ss' );
|
|
1682
|
+
let newUpdatedDate = dayjs.utc( updatedscheduleEndTimeISO, 'HH:mm:ss' ).format();
|
|
1683
|
+
|
|
1684
|
+
if ( req.body.publish && req.body.publish == true ) {
|
|
1685
|
+
if ( newUpdatedDate > currentDate ) {
|
|
1686
|
+
let deleteQuery = {
|
|
1687
|
+
$and: [
|
|
1688
|
+
{ date_string: dayjs().format( 'YYYY-MM-DD' ) },
|
|
1689
|
+
{ sourceCheckList_id: new ObjectId( req.body.checklistId ) },
|
|
1690
|
+
{ scheduleEndTime_iso: { $gt: currentDate } },
|
|
1691
|
+
],
|
|
1692
|
+
};
|
|
1693
|
+
deleteQuery.$and.push( { checklistStatus: { $ne: 'submit' } } );
|
|
1694
|
+
let PClicklist = await taskProcessedService.deleteMany( deleteQuery );
|
|
1695
|
+
logger.info( { function: 'updatePublish', query: deleteQuery } );
|
|
1696
|
+
logger.info( `Deleted Checklist Before Insert => Checklist Name: ${getCheckDetails.checkListName}, PChecklist Count: ${PClicklist.deletedCount}` );
|
|
1697
|
+
if ( PClicklist.acknowledged ) {
|
|
1698
|
+
await insertSingleProcessData( req.body.checklistId );
|
|
1699
|
+
} else {
|
|
1700
|
+
res.sendError( 'something went wrong, please try again', 500 );
|
|
1701
|
+
}
|
|
1702
|
+
} else {
|
|
1703
|
+
logger.info( `Schudled End Time Breached Checklist publish true => Checklist Name: ${getCheckDetails.checkListName}` );
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
futureDaysDataRemove( currentDate, req.body.checklistId, getCheckDetails.checkListName, '111' );
|
|
1707
|
+
} else {
|
|
1708
|
+
if ( newUpdatedDate > currentDate ) {
|
|
1709
|
+
let deleteQuery = {
|
|
1710
|
+
$and: [
|
|
1711
|
+
{ date_string: dayjs().format( 'YYYY-MM-DD' ) },
|
|
1712
|
+
{ sourceCheckList_id: new ObjectId( req.body.checklistId ) },
|
|
1713
|
+
{ scheduleEndTime_iso: { $gt: currentDate } },
|
|
1714
|
+
],
|
|
1715
|
+
};
|
|
1716
|
+
await taskProcessedConfigService.deleteMany( deleteQuery );
|
|
1717
|
+
deleteQuery.$and.push( { checklistStatus: { $ne: 'submit' } } );
|
|
1718
|
+
await taskProcessedService.deleteMany( deleteQuery );
|
|
1719
|
+
logger.info( { function: 'updatePublish', query: deleteQuery } );
|
|
1720
|
+
|
|
1721
|
+
let checklistLogQuery = {};
|
|
1722
|
+
checklistLogQuery.checkListName = getCheckDetails.checkListName;
|
|
1723
|
+
checklistLogQuery.createdAt = { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) };
|
|
1724
|
+
await checklistLogs.deleteMany( checklistLogQuery );
|
|
1725
|
+
|
|
1726
|
+
let checklistDetectionsQuery = {};
|
|
1727
|
+
checklistDetectionsQuery.sourceChecklist_id = new ObjectId( req.body.checklistId );
|
|
1728
|
+
checklistDetectionsQuery.date_iso = { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) };
|
|
1729
|
+
// await processeddetections.deleteMany( checklistDetectionsQuery );
|
|
1730
|
+
logger.info( { function: 'updatePublish', query: checklistDetectionsQuery } );
|
|
1731
|
+
} else {
|
|
1732
|
+
logger.info( `Schudled End Time Breached Checklist Unpublish false => Checklist Name: ${getCheckDetails.checkListName}` );
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// //Delete Future Data////
|
|
1736
|
+
futureDaysDataRemove( currentDate, req.body.checklistId, getCheckDetails.checkListName, '222' );
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
let logInsertData = {
|
|
1740
|
+
action: req.body.publish ? 'publishTask' : 'unPublishTask',
|
|
1741
|
+
checklistId: req.body?.checklistId,
|
|
1742
|
+
checkListName: getCheckDetails.checkListName,
|
|
1743
|
+
createdBy: req.user._id,
|
|
1744
|
+
createdByName: req.user.userName,
|
|
1745
|
+
client_id: req.body.clientId,
|
|
1746
|
+
};
|
|
1747
|
+
await checklistLogs.create( logInsertData );
|
|
1748
|
+
return res.sendSuccess( { checklistName: getCheckDetails.checkListName, message: 'Updated Successfully' } );
|
|
1749
|
+
} catch ( e ) {
|
|
1750
|
+
logger.error( 'updatePublish task erroe =>', e );
|
|
1751
|
+
return res.sendError( e, 500 );
|
|
1752
|
+
}
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
export const duplicateChecklist = async ( req, res ) => {
|
|
1756
|
+
try {
|
|
1757
|
+
if ( !req.params.checklistId ) {
|
|
1758
|
+
return res.sendError( { message: 'Task id is required' }, 400 );
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
let checkDetails = await taskService.findOne( { _id: req.params.checklistId, client_id: req.query.clientId, isdeleted: false } );
|
|
1762
|
+
|
|
1763
|
+
if ( !checkDetails ) {
|
|
1764
|
+
return res.sendError( 'No data found', 204 );
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
let dupDetails = { ...checkDetails._doc };
|
|
1768
|
+
let name = `^${dupDetails.checkListName.split( '(' )[0]}\\(.*\\)$`;
|
|
1769
|
+
let checkListNameDetails = await taskService.find( { checkListName: { $regex: name }, client_id: req.query.clientId, isdeleted: false } );
|
|
1770
|
+
if ( checkListNameDetails.length ) {
|
|
1771
|
+
let nameLength = checkListNameDetails.length + 1;
|
|
1772
|
+
dupDetails.checkListName = dupDetails.checkListName.split( '(' )[0] + '(' + nameLength +')';
|
|
1773
|
+
} else {
|
|
1774
|
+
dupDetails.checkListName = dupDetails.checkListName + '(1)';
|
|
1775
|
+
}
|
|
1776
|
+
dupDetails.publish = false;
|
|
1777
|
+
dupDetails.reinitiate = false;
|
|
1778
|
+
dupDetails.createdAt = new Date();
|
|
1779
|
+
dupDetails.updatedAt = new Date();
|
|
1780
|
+
dupDetails.publishDate = '';
|
|
1781
|
+
delete dupDetails._id;
|
|
1782
|
+
let logInsertData = {
|
|
1783
|
+
action: 'duplicateTask',
|
|
1784
|
+
checklistId: req.params.checklistId,
|
|
1785
|
+
checkListName: checkDetails.checkListName,
|
|
1786
|
+
createdBy: req.user._id,
|
|
1787
|
+
createdByName: req.user.userName,
|
|
1788
|
+
client_id: req.query.clientId,
|
|
1789
|
+
};
|
|
1790
|
+
await checklistLogs.create( logInsertData );
|
|
1791
|
+
taskService.create( dupDetails ).then( async ( data ) => {
|
|
1792
|
+
let userList = await taskAssignService.find( { checkListId: checkDetails._id, client_id: req.query.clientId } );
|
|
1793
|
+
if ( userList.length ) {
|
|
1794
|
+
let users = [];
|
|
1795
|
+
for ( let i = 0; i < userList.length; i++ ) {
|
|
1796
|
+
let userDetails = { ...userList[i]._doc };
|
|
1797
|
+
userDetails.checkListId = data._id;
|
|
1798
|
+
userDetails.checkListName = data.checkListName;
|
|
1799
|
+
delete userDetails['_id'];
|
|
1800
|
+
users.push( userDetails );
|
|
1801
|
+
}
|
|
1802
|
+
await taskAssignService.insertMany( users );
|
|
1803
|
+
}
|
|
1804
|
+
let sectionList = await taskQuestionService.find( { checkListId: checkDetails._id, client_id: req.query.clientId, isdeleted: false } );
|
|
1805
|
+
if ( sectionList.length ) {
|
|
1806
|
+
let sections= [];
|
|
1807
|
+
for ( let i = 0; i < sectionList.length; i++ ) {
|
|
1808
|
+
let sectionDetails = { ...sectionList[i]._doc };
|
|
1809
|
+
sectionDetails.checkListId = data._id;
|
|
1810
|
+
sectionDetails.checkList = dupDetails.checkListName;
|
|
1811
|
+
sectionDetails.createdAt = new Date();
|
|
1812
|
+
sectionDetails.updatedAt = new Date();
|
|
1813
|
+
delete sectionDetails['_id'];
|
|
1814
|
+
sections.push( sectionDetails );
|
|
1815
|
+
}
|
|
1816
|
+
await taskQuestionService.insertMany( sections );
|
|
1817
|
+
return res.sendSuccess( { message: 'Task Duplicated Successfully' } );
|
|
1818
|
+
} else {
|
|
1819
|
+
return res.sendSuccess( { message: 'Duplicated Successfully' } );
|
|
1820
|
+
}
|
|
1821
|
+
} ).catch( ( e ) => {
|
|
1822
|
+
return res.sendError( e, 500 );
|
|
1823
|
+
} );
|
|
1824
|
+
} catch ( e ) {
|
|
1825
|
+
logger.error( 'duplicateTask =>', e );
|
|
1826
|
+
return res.sendError( e, 500 );
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
@@ -51,6 +51,7 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
51
51
|
$match: {
|
|
52
52
|
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
53
53
|
sourceCheckList_id: { $in: taskIdList },
|
|
54
|
+
checklistStatus: 'submit',
|
|
54
55
|
...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
55
56
|
approvalStatus: false,
|
|
56
57
|
},
|
|
@@ -63,6 +64,7 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
63
64
|
$match: {
|
|
64
65
|
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
65
66
|
sourceCheckList_id: { $in: checklistIdList },
|
|
67
|
+
checklistStatus: 'submit',
|
|
66
68
|
...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
67
69
|
approvalStatus: false,
|
|
68
70
|
},
|
|
@@ -121,6 +123,10 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
121
123
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
122
124
|
|
|
123
125
|
let groupQuery = [ {
|
|
126
|
+
$sort: {
|
|
127
|
+
checkListName: 1,
|
|
128
|
+
},
|
|
129
|
+
}, {
|
|
124
130
|
$group: {
|
|
125
131
|
_id: { checklistId: '$sourceCheckList_id', redoType: '$redoStatus' },
|
|
126
132
|
checkListName: { $first: '$checkListName' },
|
|
@@ -132,6 +138,7 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
132
138
|
$cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ],
|
|
133
139
|
},
|
|
134
140
|
},
|
|
141
|
+
storeName: { $first: '$storeName' },
|
|
135
142
|
publishDate: { $first: '$publishDate' },
|
|
136
143
|
priorityType: { $first: '$priorityType' },
|
|
137
144
|
approveCount: { $sum: {
|
|
@@ -160,9 +167,16 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
160
167
|
priorityType: 1,
|
|
161
168
|
approveCount: 1,
|
|
162
169
|
unApproveCount: 1,
|
|
170
|
+
storeName: 1,
|
|
163
171
|
redo: '$_id.redoType',
|
|
164
172
|
},
|
|
165
|
-
}
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
$match: {
|
|
176
|
+
submitCount: { $gte: 1 },
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
];
|
|
166
180
|
|
|
167
181
|
const promises = [];
|
|
168
182
|
|
|
@@ -282,8 +296,13 @@ export const activityLogV1 = async ( req, res ) => {
|
|
|
282
296
|
storeName: 1,
|
|
283
297
|
action: 1,
|
|
284
298
|
createdAt: 1,
|
|
299
|
+
type: 1,
|
|
300
|
+
store_id: 1,
|
|
301
|
+
checklistId: 1,
|
|
302
|
+
redoStatus: 1,
|
|
285
303
|
},
|
|
286
304
|
} );
|
|
305
|
+
findQuery.push( { $sort: { ['_id']: -1 } } );
|
|
287
306
|
let limit = parseInt( requestData?.limit ) || 10;
|
|
288
307
|
let skip = limit * ( requestData?.offset -1 ) || 0;
|
|
289
308
|
|
|
@@ -302,7 +321,7 @@ export const activityLogV1 = async ( req, res ) => {
|
|
|
302
321
|
|
|
303
322
|
let activityLogData = await checklistLog.aggregate( findQuery );
|
|
304
323
|
|
|
305
|
-
if ( activityLogData && activityLogData
|
|
324
|
+
if ( activityLogData && activityLogData?.[0]?.count?.length > 0 ) {
|
|
306
325
|
return res.sendSuccess( activityLogData );
|
|
307
326
|
} else {
|
|
308
327
|
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
@@ -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 } from 'tango-app-api-middleware';
|
|
3
|
+
import { logger, download } from 'tango-app-api-middleware';
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import mongoose from 'mongoose';
|
|
6
6
|
// const ObjectId = mongoose.Types.ObjectId;
|
|
@@ -218,25 +218,31 @@ export const taskTableV1 = async ( req, res ) => {
|
|
|
218
218
|
export const taskInfoTableV1 = async ( req, res ) => {
|
|
219
219
|
try {
|
|
220
220
|
let requestData = req.body;
|
|
221
|
-
let fromDate = new Date( requestData.fromDate );
|
|
222
|
-
let toDate = new Date( requestData.toDate );
|
|
223
|
-
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
224
|
-
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
225
|
-
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
221
|
+
// let fromDate = new Date( requestData.fromDate );
|
|
222
|
+
// let toDate = new Date( requestData.toDate );
|
|
223
|
+
// let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
224
|
+
// toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
225
|
+
// toDate.setUTCHours( 23, 59, 59, 59 );
|
|
226
226
|
let result = {};
|
|
227
227
|
|
|
228
228
|
let findQuery = [];
|
|
229
229
|
let findAndQuery = [];
|
|
230
230
|
|
|
231
231
|
findAndQuery.push(
|
|
232
|
-
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
232
|
+
// { date_iso: { $gte: fromDate, $lte: toDate } },
|
|
233
233
|
{ client_id: requestData.clientId },
|
|
234
234
|
{ store_id: { $in: requestData.storeId } },
|
|
235
235
|
// { checkListType: { $eq: 'task' } },
|
|
236
236
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
|
|
237
237
|
);
|
|
238
238
|
if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
|
|
239
|
-
|
|
239
|
+
if ( requestData.checklistStatus == 'redo' ) {
|
|
240
|
+
findAndQuery.push(
|
|
241
|
+
{ redoStatus: true },
|
|
242
|
+
{ checklistStatus: { $ne: 'submit' } } );
|
|
243
|
+
} else {
|
|
244
|
+
findAndQuery.push( { checklistStatus: requestData.checklistStatus } );
|
|
245
|
+
}
|
|
240
246
|
}
|
|
241
247
|
|
|
242
248
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
@@ -677,11 +683,25 @@ export const taskDropdownListV1 = async ( req, res ) => {
|
|
|
677
683
|
findAndQuery.push(
|
|
678
684
|
{ client_id: requestData.clientId },
|
|
679
685
|
// { checkListType: 'task' },
|
|
680
|
-
{ isdeleted: false },
|
|
686
|
+
// { isdeleted: false },
|
|
687
|
+
);
|
|
688
|
+
findQuery.push( { $match: { $and: findAndQuery } }, { $sort: { date_iso: -1 } } );
|
|
689
|
+
findQuery.push(
|
|
690
|
+
{
|
|
691
|
+
$group: {
|
|
692
|
+
_id: '$sourceCheckList_id',
|
|
693
|
+
checkListName: { $first: '$checkListName' },
|
|
694
|
+
checkListType: { $first: '$checkListType' },
|
|
695
|
+
createdByName: { $first: '$createdByName' },
|
|
696
|
+
storeCount: { $first: '$storeCount' },
|
|
697
|
+
scheduleEndTimeISO: { $first: '$scheduleEndTime_iso' },
|
|
698
|
+
submitTime_string: { $first: '$submitTime_string' },
|
|
699
|
+
},
|
|
700
|
+
},
|
|
681
701
|
);
|
|
682
|
-
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
683
702
|
findQuery.push( {
|
|
684
703
|
$project: {
|
|
704
|
+
_id: 1,
|
|
685
705
|
sourceCheckList_id: '$_id',
|
|
686
706
|
checkListName: 1,
|
|
687
707
|
checkListNameLowercase: { $toLower: '$checkListName' },
|
|
@@ -697,7 +717,7 @@ export const taskDropdownListV1 = async ( req, res ) => {
|
|
|
697
717
|
} else {
|
|
698
718
|
findQuery.push( { $sort: { ['checkListNameLowercase']: 1 } } );
|
|
699
719
|
}
|
|
700
|
-
let getChecklistData = await
|
|
720
|
+
let getChecklistData = await processedTaskService.aggregate( findQuery );
|
|
701
721
|
if ( !getChecklistData.length ) {
|
|
702
722
|
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
703
723
|
}
|
|
@@ -713,6 +733,114 @@ export const taskDropdownListV1 = async ( req, res ) => {
|
|
|
713
733
|
return res.sendError( { error: error }, 500 );
|
|
714
734
|
}
|
|
715
735
|
};
|
|
736
|
+
export const taskDropdownListNew = async ( req, res ) => {
|
|
737
|
+
try {
|
|
738
|
+
let requestData = req.body;
|
|
739
|
+
let fromDate = new Date( requestData.fromDate );
|
|
740
|
+
let toDate = new Date( requestData.toDate );
|
|
741
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
742
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
743
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
744
|
+
let result = {};
|
|
745
|
+
|
|
746
|
+
let findQuery = [
|
|
747
|
+
{ $match: { $and: [
|
|
748
|
+
{ client_id: requestData.clientId },
|
|
749
|
+
{ store_id: { $in: requestData.storeId } },
|
|
750
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
751
|
+
{ checkListType: { $in: [ 'task', 'checklistTask', 'cctv' ] } },
|
|
752
|
+
] } },
|
|
753
|
+
{
|
|
754
|
+
$project: {
|
|
755
|
+
sourceCheckList_id: 1,
|
|
756
|
+
checkListName: 1,
|
|
757
|
+
},
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
$group: {
|
|
761
|
+
_id: '$sourceCheckList_id',
|
|
762
|
+
checkListName: { $last: '$checkListName' },
|
|
763
|
+
},
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
$project: {
|
|
767
|
+
_id: 0,
|
|
768
|
+
sourceCheckList_id: '$_id',
|
|
769
|
+
checkListName: 1,
|
|
770
|
+
},
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
$lookup: {
|
|
774
|
+
from: 'taskconfigs',
|
|
775
|
+
let: { sourceId: '$sourceCheckList_id' },
|
|
776
|
+
pipeline: [
|
|
777
|
+
{
|
|
778
|
+
$match: {
|
|
779
|
+
$expr: {
|
|
780
|
+
$and: [
|
|
781
|
+
{ $eq: [ '$_id', '$$sourceId' ] },
|
|
782
|
+
],
|
|
783
|
+
},
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
$project: {
|
|
788
|
+
_id: 1,
|
|
789
|
+
checkListName: 1,
|
|
790
|
+
checkListNameLowercase: { $toLower: '$checkListName' },
|
|
791
|
+
checkListType: 1,
|
|
792
|
+
createdByName: 1,
|
|
793
|
+
publish: 1,
|
|
794
|
+
scheduleEndTime: 1,
|
|
795
|
+
scheduleRepeatedType: 1,
|
|
796
|
+
scheduleStartTime: 1,
|
|
797
|
+
sourceCheckList_id: '$_id',
|
|
798
|
+
storeCount: 1,
|
|
799
|
+
submitTime_string: 1,
|
|
800
|
+
scheduleEndTimeISO: 1,
|
|
801
|
+
},
|
|
802
|
+
},
|
|
803
|
+
], as: 'checklistData',
|
|
804
|
+
},
|
|
805
|
+
},
|
|
806
|
+
{ $unwind: { path: '$checklistData', preserveNullAndEmptyArrays: true } },
|
|
807
|
+
{
|
|
808
|
+
$project: {
|
|
809
|
+
sourceCheckList_id: '$checklistData._id',
|
|
810
|
+
checkListName: '$checklistData.checkListName',
|
|
811
|
+
checkListNameLowercase: { $toLower: '$checkListName' },
|
|
812
|
+
checkListType: '$checklistData.checkListType',
|
|
813
|
+
createdByName: '$checklistData.createdByName',
|
|
814
|
+
storeCount: '$checklistData.storeCount',
|
|
815
|
+
scheduleEndTimeISO: '$checklistData.scheduleEndTimeISO',
|
|
816
|
+
submitTime_string: '$checklistData.submitTime_string',
|
|
817
|
+
_id: '$checklistData._id',
|
|
818
|
+
publish: '$checklistData.publish',
|
|
819
|
+
scheduleEndTime: '$checklistData.scheduleEndTime',
|
|
820
|
+
scheduleRepeatedType: '$checklistData.scheduleRepeatedType',
|
|
821
|
+
scheduleStartTime: '$checklistData.scheduleStartTime',
|
|
822
|
+
},
|
|
823
|
+
},
|
|
824
|
+
];
|
|
825
|
+
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
826
|
+
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
827
|
+
} else {
|
|
828
|
+
findQuery.push( { $sort: { ['checkListNameLowercase']: -1 } } );
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
let getChecklistData = await processedTaskService.aggregate( findQuery );
|
|
832
|
+
if ( !getChecklistData.length ) {
|
|
833
|
+
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
834
|
+
}
|
|
835
|
+
result.totalCount = getChecklistData.length;
|
|
836
|
+
result.taskDropdown = getChecklistData;
|
|
837
|
+
return res.sendSuccess( result );
|
|
838
|
+
} catch ( error ) {
|
|
839
|
+
console.log( 'error =>', error );
|
|
840
|
+
logger.error( { error: error, message: req.query, function: 'checklistDropdownV1' } );
|
|
841
|
+
return res.sendError( { error: error }, 500 );
|
|
842
|
+
}
|
|
843
|
+
};
|
|
716
844
|
export const taskInfoView = async ( req, res ) => {
|
|
717
845
|
try {
|
|
718
846
|
let requestData = req.body;
|
|
@@ -787,3 +915,112 @@ export const taskDeleteV1 = async ( req, res ) => {
|
|
|
787
915
|
};
|
|
788
916
|
|
|
789
917
|
|
|
918
|
+
export async function taskDetails( req, res ) {
|
|
919
|
+
try {
|
|
920
|
+
if ( !req.body.fromDate || !req.body.toDate ) {
|
|
921
|
+
return res.sendError( 'fromDate or toDate is missing', 400 );
|
|
922
|
+
}
|
|
923
|
+
if ( !req.body.clientId ) {
|
|
924
|
+
return res.sendError( 'clientId is required', 400 );
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
let toDate = new Date( req.body.toDate );
|
|
928
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
929
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
930
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
931
|
+
let limit = req.body?.limit || 10;
|
|
932
|
+
let page = req.body?.offset ? ( req.body.offset * req.body.limit ) : 0;
|
|
933
|
+
|
|
934
|
+
let query = [
|
|
935
|
+
{
|
|
936
|
+
$match: {
|
|
937
|
+
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
938
|
+
client_id: req.body.clientId,
|
|
939
|
+
...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
|
|
940
|
+
},
|
|
941
|
+
},
|
|
942
|
+
{ $sort: { date_iso: -1 } },
|
|
943
|
+
{
|
|
944
|
+
$group: {
|
|
945
|
+
_id: '$sourceCheckList_id',
|
|
946
|
+
checkListName: { $first: '$checkListName' },
|
|
947
|
+
createdByName: { $first: '$createdByName' },
|
|
948
|
+
publishDate: { $first: '$publishDate' },
|
|
949
|
+
priorityType: { $first: '$priorityType' },
|
|
950
|
+
storeCount: { $first: '$storeCount' },
|
|
951
|
+
submitCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
|
|
952
|
+
redoCount: { $sum: { $cond: [ { $and: [ { $eq: [ '$redoStatus', true ] }, { $ne: [ '$checklistStatus', 'submit' ] } ] }, 1, 0 ] } },
|
|
953
|
+
scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
|
|
954
|
+
checkListChar: { $first: { $toUpper: { $substr: [ '$createdByName', 0, 2 ] } } },
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
];
|
|
958
|
+
|
|
959
|
+
if ( req.body?.searchValue.trim().length ) {
|
|
960
|
+
query.push(
|
|
961
|
+
{
|
|
962
|
+
$match: {
|
|
963
|
+
checkListName: { $regex: req.body.searchValue, $options: 'i' },
|
|
964
|
+
},
|
|
965
|
+
},
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
if ( req.body.sortColumnName && req.body.sortBy ) {
|
|
970
|
+
query.push( {
|
|
971
|
+
$sort: { [req.body.sortColumnName]: req.body.sortBy },
|
|
972
|
+
} );
|
|
973
|
+
} else {
|
|
974
|
+
query.push( {
|
|
975
|
+
$sort: { checkListName: 1 },
|
|
976
|
+
} );
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
if ( req.body.filter.length ) {
|
|
980
|
+
query.push( {
|
|
981
|
+
$match: { priorityType: { $in: req.body.filter } },
|
|
982
|
+
} );
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
query.push( {
|
|
986
|
+
$facet: {
|
|
987
|
+
data: [
|
|
988
|
+
{ $skip: page }, { $limit: limit },
|
|
989
|
+
],
|
|
990
|
+
count: [
|
|
991
|
+
{ $count: 'total' },
|
|
992
|
+
],
|
|
993
|
+
},
|
|
994
|
+
} );
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
let taskDetails = await processedTaskService.aggregate( query );
|
|
998
|
+
|
|
999
|
+
if ( req.body.export ) {
|
|
1000
|
+
const exportResult = [];
|
|
1001
|
+
for ( let task of taskDetails[0].data ) {
|
|
1002
|
+
exportResult.push( {
|
|
1003
|
+
'Task Name': task?.checkListName ||'',
|
|
1004
|
+
'Created by': task?.createdByName ||'--',
|
|
1005
|
+
'Created On': dayjs.utc( task?.publishDate ).format( 'DD MMM, YYYY' ) || '',
|
|
1006
|
+
'Priority': task?.priorityType || '--',
|
|
1007
|
+
'Assigned To': task?.storeCount ||'--',
|
|
1008
|
+
'Submitted': task?.submitCount ||'--',
|
|
1009
|
+
'Redo': task?.redoCount ||'--',
|
|
1010
|
+
'Due on': dayjs.utc( task?.scheduleEndTime_iso ).format( 'DD MMM, YYYY' ) || '',
|
|
1011
|
+
} );
|
|
1012
|
+
}
|
|
1013
|
+
await download( exportResult, res );
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
if ( !taskDetails[0].data.length ) {
|
|
1018
|
+
return res.sendError( 'no date found', 204 );
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
return res.sendSuccess( { data: taskDetails?.[0]?.data || [], count: taskDetails?.[0]?.count?.[0]?.total || 0 } );
|
|
1022
|
+
} catch ( e ) {
|
|
1023
|
+
logger.error( { function: 'taskDetails', error: e, message: req.body } );
|
|
1024
|
+
return res.sendError( e, 500 );
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
@@ -20,6 +20,10 @@ taskRouter
|
|
|
20
20
|
.post( '/taskDropdown', isAllowedSessionHandler, taskController.taskDropdown )
|
|
21
21
|
.post( '/getQuestions', isAllowedSessionHandler, taskController.getQuestions )
|
|
22
22
|
.post( '/getAnswers', isAllowedSessionHandler, taskController.getAnswers )
|
|
23
|
-
.post( '/getAnswerCount', isAllowedSessionHandler, taskController.getAnswerCount )
|
|
23
|
+
.post( '/getAnswerCount', isAllowedSessionHandler, taskController.getAnswerCount )
|
|
24
|
+
.post( '/approvalstatus', isAllowedSessionHandler, taskController.approvalstatus )
|
|
25
|
+
.get( '/task-list', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ ] } ] } ), taskController.taskList )
|
|
26
|
+
.put( '/publish', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.updatePublish )
|
|
27
|
+
.get( '/duplicateTask/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.duplicateChecklist );
|
|
24
28
|
|
|
25
29
|
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
export const taskDashboardRouter = express.Router();
|
|
3
|
+
import { isAllowedSessionHandler, accessVerification, isAllowedClient } from 'tango-app-api-middleware';
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
|
-
overallCards, taskTable, taskInfoTable, taskDropdownList, taskTableV1, overallCardsV1, taskInfoTableV1, taskDropdownListV1, taskDeleteV1,
|
|
6
|
+
overallCards, taskTable, taskInfoTable, taskDropdownList, taskTableV1, overallCardsV1, taskInfoTableV1, taskDropdownListV1, taskDeleteV1, taskDetails,
|
|
6
7
|
} from '../controllers/taskDashboard.controllers.js';
|
|
7
8
|
|
|
8
9
|
taskDashboardRouter
|
|
9
|
-
.post( '/overallcards', overallCards )
|
|
10
|
-
.post( '/overallcardsV1', overallCardsV1 )
|
|
11
|
-
.post( '/taskTable', taskTable )
|
|
12
|
-
.post( '/taskTableV1', taskTableV1 )
|
|
13
|
-
.post( '/taskInfoTable', taskInfoTable )
|
|
14
|
-
.post( '/taskInfoTableV1', taskInfoTableV1 )
|
|
15
|
-
.post( '/taskDropdownList', taskDropdownList )
|
|
16
|
-
.post( '/taskDropdownListV1', taskDropdownListV1 )
|
|
17
|
-
.post( '/taskDeleteV1', taskDeleteV1 )
|
|
10
|
+
.post( '/overallcards', isAllowedSessionHandler, overallCards )
|
|
11
|
+
.post( '/overallcardsV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), overallCardsV1 )
|
|
12
|
+
.post( '/taskTable', isAllowedSessionHandler, taskTable )
|
|
13
|
+
.post( '/taskTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskTableV1 )
|
|
14
|
+
.post( '/taskInfoTable', isAllowedSessionHandler, taskInfoTable )
|
|
15
|
+
.post( '/taskInfoTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskInfoTableV1 )
|
|
16
|
+
.post( '/taskDropdownList', isAllowedSessionHandler, taskDropdownList )
|
|
17
|
+
.post( '/taskDropdownListV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskDropdownListV1 )
|
|
18
|
+
.post( '/taskDeleteV1', isAllowedSessionHandler, taskDeleteV1 )
|
|
19
|
+
.post( '/taskDetails', isAllowedSessionHandler, taskDetails );
|
|
18
20
|
|
|
19
21
|
export default taskDashboardRouter;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import model from 'tango-api-schema';
|
|
2
2
|
|
|
3
3
|
export const findOne = async ( query={}, field={} ) => {
|
|
4
|
-
return model.userModel.findOne( query, field );
|
|
4
|
+
return model.userModel.findOne( query, field ).sort( { userName: 1 } );
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export const find = async ( query={}, field={} ) => {
|