tango-app-api-trax 3.4.0-soplink2-0 → 3.4.1-activitylog-1
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/index.js +1 -0
- package/package.json +3 -3
- package/src/controllers/activityLog.controller.js +49 -27
- package/src/controllers/download.controller.js +117 -3
- package/src/controllers/gallery.controller.js +18 -14
- package/src/controllers/internalTrax.controller.js +675 -10
- package/src/controllers/mobileTrax.controller.js +38 -962
- package/src/controllers/teaxFlag.controller.js +61 -3
- package/src/controllers/trax.controller.js +541 -289
- package/src/controllers/traxDashboard.controllers.js +1 -2
- package/src/dtos/downloadValidation.dtos.js +1 -1
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/download.router.js +4 -0
- package/src/routes/internalTraxApi.router.js +3 -1
- package/src/routes/mobileTrax.routes.js +0 -3
- package/src/routes/trax.routes.js +5 -3
- package/src/routes/traxFlag.router.js +5 -1
- package/src/services/processedchecklistconfig.services.js +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fileUpload, chunkArray, logger, sendPushNotification, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
1
|
+
import { signedUrl, fileUpload, chunkArray, logger, sendPushNotification, sendTeamsNotification, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
2
2
|
import * as checklistService from '../services/checklist.service.js';
|
|
3
3
|
import * as questionService from '../services/checklistQuestion.service.js';
|
|
4
4
|
import * as assignedService from '../services/checklistAssign.service.js';
|
|
@@ -129,6 +129,7 @@ export const checklist = async ( req, res ) => {
|
|
|
129
129
|
|
|
130
130
|
export const create = async ( req, res ) => {
|
|
131
131
|
try {
|
|
132
|
+
console.log( 'create' );
|
|
132
133
|
let inputBody = req.body;
|
|
133
134
|
let checkNumber;
|
|
134
135
|
let questionCount = 0;
|
|
@@ -247,15 +248,14 @@ export const create = async ( req, res ) => {
|
|
|
247
248
|
section.questions[qIdx].answers[index].nestedQuestion = [];
|
|
248
249
|
}
|
|
249
250
|
if ( answer.showLinked ) {
|
|
250
|
-
// section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
|
|
251
251
|
if ( nestedIndex != -1 ) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
if ( !section.questions[qIdx].answers[nestedIndex].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
253
|
+
section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
|
|
254
|
+
}
|
|
255
255
|
} else {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
if ( !section.questions[qIdx].answers[index].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
257
|
+
section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
|
|
258
|
+
}
|
|
259
259
|
}
|
|
260
260
|
let nestedLinkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
261
261
|
if ( nestedLinkedQuestion ) {
|
|
@@ -272,30 +272,25 @@ export const create = async ( req, res ) => {
|
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
-
let checkNestedLevel = false;
|
|
276
|
-
section.questions.forEach( ( qns ) => {
|
|
277
|
-
qns.answers.forEach( ( answ ) => {
|
|
278
|
-
if ( answ.nestedQuestion.length > 20 ) {
|
|
279
|
-
checkNestedLevel = true;
|
|
280
|
-
}
|
|
281
|
-
} );
|
|
282
|
-
} );
|
|
283
|
-
|
|
284
|
-
if ( checkNestedLevel ) {
|
|
285
|
-
return res.sendError( { message: 'Unable to create more than 20 linked questions.' }, 400 );
|
|
286
|
-
}
|
|
287
275
|
|
|
288
276
|
let sectionList = {
|
|
289
277
|
section: section.name,
|
|
290
278
|
createdBy: req.user._id,
|
|
291
279
|
createdByName: req.user.userName,
|
|
292
|
-
client_id:
|
|
280
|
+
client_id: req.body.clientId,
|
|
293
281
|
checkListId: checkListId,
|
|
294
282
|
question: section.questions,
|
|
295
283
|
checkList: inputBody.checklistName,
|
|
296
284
|
};
|
|
297
285
|
await questionService.create( sectionList ).then( async ( data ) => {
|
|
298
286
|
if ( i == inputBody.sections.length - 1 ) {
|
|
287
|
+
let actionType = 'created';
|
|
288
|
+
let teamsMsg;
|
|
289
|
+
let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
290
|
+
actionType = 'Create';
|
|
291
|
+
teamsMsg = 'ClientId: '+ req.body.clientId + ', Action: '+ actionType + ', ChecklistId: '+ checkListId + ', Checklist Name: '+ inputBody.checklistName + ', UpDatedBy: '+ req.user.email;
|
|
292
|
+
sendTeamsNotification( teamsAlertUrls.checklist, teamsMsg );
|
|
293
|
+
|
|
299
294
|
let logObj = {
|
|
300
295
|
client_id: inputBody.clientId,
|
|
301
296
|
createAt: new Date(),
|
|
@@ -310,12 +305,36 @@ export const create = async ( req, res ) => {
|
|
|
310
305
|
createdBy: req.user.userName,
|
|
311
306
|
coverage: 'store',
|
|
312
307
|
logDetails: {},
|
|
308
|
+
userType: req.user.userType,
|
|
313
309
|
};
|
|
314
|
-
|
|
310
|
+
console.log( 'req.user', req.user );
|
|
311
|
+
console.log( 'logObj', logObj );
|
|
312
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
313
|
+
if ( inputBody.submitType == 'save' ) {
|
|
314
|
+
console.log( 'logObj', logObj );
|
|
315
|
+
let logObj = {
|
|
316
|
+
client_id: inputBody.clientId,
|
|
317
|
+
createAt: new Date(),
|
|
318
|
+
sourceCheckList_id: checkListId,
|
|
319
|
+
checkListName: inputBody.checklistName,
|
|
320
|
+
fromCheckListName: '',
|
|
321
|
+
type: 'checklist',
|
|
322
|
+
action: 'draft',
|
|
323
|
+
storeName: '',
|
|
324
|
+
store_id: '',
|
|
325
|
+
createdByEmail: req.user.email,
|
|
326
|
+
createdBy: req.user.userName,
|
|
327
|
+
coverage: 'store',
|
|
328
|
+
logDetails: {},
|
|
329
|
+
userType: req.user.userType,
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
333
|
+
}
|
|
334
|
+
|
|
315
335
|
return res.sendSuccess( { checklistId: checkListId, msg: 'CheckList Created Successfully' } );
|
|
316
336
|
}
|
|
317
337
|
} ).catch( ( e ) => {
|
|
318
|
-
console.log( e );
|
|
319
338
|
return res.sendError( e, 500 );
|
|
320
339
|
} );
|
|
321
340
|
}
|
|
@@ -325,11 +344,11 @@ export const create = async ( req, res ) => {
|
|
|
325
344
|
}
|
|
326
345
|
}
|
|
327
346
|
} ).catch( async ( e ) => {
|
|
328
|
-
console.log( e );
|
|
329
347
|
await checklistService.deleteOne( { _id: checkListId } );
|
|
330
348
|
return res.sendError( e, 500 );
|
|
331
349
|
} );
|
|
332
350
|
} catch ( e ) {
|
|
351
|
+
console.log( 'e', e );
|
|
333
352
|
logger.error( 'create =>', e );
|
|
334
353
|
return res.sendError( e, 500 );
|
|
335
354
|
}
|
|
@@ -389,23 +408,23 @@ export const getConfigDetails = async ( req, res ) => {
|
|
|
389
408
|
let questionDetails = await questionService.find( query );
|
|
390
409
|
if ( questionDetails.length ) {
|
|
391
410
|
let sections = [];
|
|
392
|
-
|
|
411
|
+
let bucket = JSON.parse( process.env.BUCKET );
|
|
393
412
|
questionDetails.forEach( ( item ) => {
|
|
394
413
|
item.question.forEach( async ( question ) => {
|
|
395
414
|
if ( question.questionReferenceImage && question.questionReferenceImage !='' ) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
question.questionReferenceImage =
|
|
415
|
+
let inputData = {
|
|
416
|
+
Bucket: bucket.sop,
|
|
417
|
+
file_path: decodeURIComponent( question.questionReferenceImage ),
|
|
418
|
+
};
|
|
419
|
+
question.questionReferenceImage = await signedUrl( inputData );
|
|
401
420
|
}
|
|
402
421
|
question.answers.forEach( async ( answer ) => {
|
|
403
422
|
if ( answer.referenceImage != '' ) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
answer.referenceImage =
|
|
423
|
+
let inputData = {
|
|
424
|
+
Bucket: bucket.sop,
|
|
425
|
+
file_path: decodeURIComponent( answer.referenceImage ),
|
|
426
|
+
};
|
|
427
|
+
answer.referenceImage = await signedUrl( inputData );
|
|
409
428
|
}
|
|
410
429
|
} );
|
|
411
430
|
} );
|
|
@@ -637,6 +656,30 @@ export const deleteChecklist = async ( req, res ) => {
|
|
|
637
656
|
await processedchecklist.deleteMany( { date_string: { $ne: date }, date_iso: { $gt: date }, sourceCheckList_id: req.params.checklistId, checklistStatus: { $ne: 'submit' } } );
|
|
638
657
|
logger.info( { function: 'deleteChecklist', query: { date_string: { $ne: date }, date_iso: { $gt: date }, sourceCheckList_id: req.params.checklistId, checklistStatus: { $ne: 'submit' } } } );
|
|
639
658
|
checklistDetails.save().then( () => {
|
|
659
|
+
let actionType = 'Deleted';
|
|
660
|
+
let teamsMsg;
|
|
661
|
+
let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
662
|
+
teamsMsg = 'ClientId: '+ checklistDetails.client_id + ', Action: '+ actionType + ', ChecklistId: '+ req.params.checklistId + ', Checklist Name: '+ checklistDetails.checkListName + ', UpDatedBy: '+ req.user.email;
|
|
663
|
+
sendTeamsNotification( teamsAlertUrls.checklist, teamsMsg );
|
|
664
|
+
|
|
665
|
+
let logObj = {
|
|
666
|
+
client_id: checklistDetails.client_id,
|
|
667
|
+
createAt: new Date(),
|
|
668
|
+
sourceCheckList_id: checklistDetails._id,
|
|
669
|
+
checkListName: checklistDetails.checkListName,
|
|
670
|
+
fromCheckListName: '',
|
|
671
|
+
type: 'checklist',
|
|
672
|
+
action: 'deleted',
|
|
673
|
+
storeName: '',
|
|
674
|
+
store_id: '',
|
|
675
|
+
createdByEmail: req.user.email,
|
|
676
|
+
createdBy: req.user.userName,
|
|
677
|
+
coverage: checklistDetails.coverage,
|
|
678
|
+
logDetails: {},
|
|
679
|
+
userType: req.user.userType,
|
|
680
|
+
};
|
|
681
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
682
|
+
|
|
640
683
|
return res.sendSuccess( { message: 'Checklist Deleted Successfully' } );
|
|
641
684
|
} ).catch( ( e ) => {
|
|
642
685
|
return res.sendError( e, 500 );
|
|
@@ -710,6 +753,29 @@ export const duplicateChecklist = async ( req, res ) => {
|
|
|
710
753
|
sections.push( sectionDetails );
|
|
711
754
|
}
|
|
712
755
|
await questionService.insertMany( sections );
|
|
756
|
+
let actionType = 'Duplicated';
|
|
757
|
+
let teamsMsg;
|
|
758
|
+
let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
759
|
+
teamsMsg = 'ClientId: '+ checkDetails.client_id + ', Action: '+ actionType + ', ChecklistId: '+ data._id + ', Checklist Name: '+ checkDetails.checkListName + ', UpDatedBy: '+ req.user.email;
|
|
760
|
+
sendTeamsNotification( teamsAlertUrls.checklist, teamsMsg );
|
|
761
|
+
|
|
762
|
+
let logObj = {
|
|
763
|
+
client_id: checkDetails.client_id,
|
|
764
|
+
createAt: new Date(),
|
|
765
|
+
sourceCheckList_id: checkDetails._id,
|
|
766
|
+
checkListName: checkDetails.checkListName,
|
|
767
|
+
fromCheckListName: '',
|
|
768
|
+
type: 'checklist',
|
|
769
|
+
action: 'duplicated',
|
|
770
|
+
storeName: '',
|
|
771
|
+
store_id: '',
|
|
772
|
+
createdByEmail: req.user.email,
|
|
773
|
+
createdBy: req.user.userName,
|
|
774
|
+
coverage: checkDetails.coverage,
|
|
775
|
+
logDetails: {},
|
|
776
|
+
userType: req.user.userType,
|
|
777
|
+
};
|
|
778
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
713
779
|
return res.sendSuccess( { message: 'CheckList Duplicated Successfully' } );
|
|
714
780
|
} else {
|
|
715
781
|
return res.sendSuccess( { message: 'duplicated Successfully' } );
|
|
@@ -758,13 +824,14 @@ export const update = async ( req, res ) => {
|
|
|
758
824
|
}
|
|
759
825
|
} );
|
|
760
826
|
|
|
827
|
+
|
|
761
828
|
let params = {
|
|
762
829
|
checkListName: inputBody.checklistName,
|
|
763
830
|
checkListDescription: inputBody.checklistDescription,
|
|
764
831
|
questionCount: questionCount,
|
|
765
832
|
};
|
|
766
833
|
|
|
767
|
-
|
|
834
|
+
await checklistService.updateOne( { _id: req.params.checklistId }, params );
|
|
768
835
|
let checkListId = req.params.checklistId;
|
|
769
836
|
let logInsertData = {
|
|
770
837
|
action: 'checklistUpdate',
|
|
@@ -809,15 +876,14 @@ export const update = async ( req, res ) => {
|
|
|
809
876
|
section.questions[qIdx].answers[index].nestedQuestion = [];
|
|
810
877
|
}
|
|
811
878
|
if ( answer.showLinked ) {
|
|
812
|
-
// section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
|
|
813
879
|
if ( nestedIndex != -1 ) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
880
|
+
if ( !section.questions[qIdx].answers[nestedIndex].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
881
|
+
section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
|
|
882
|
+
}
|
|
817
883
|
} else {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
884
|
+
if ( !section.questions[qIdx].answers[index].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
885
|
+
section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
|
|
886
|
+
}
|
|
821
887
|
}
|
|
822
888
|
let nestedLinkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
823
889
|
if ( nestedLinkedQuestion ) {
|
|
@@ -835,21 +901,6 @@ export const update = async ( req, res ) => {
|
|
|
835
901
|
}
|
|
836
902
|
}
|
|
837
903
|
|
|
838
|
-
let checkNestedLevel = false;
|
|
839
|
-
section.questions.forEach( ( qns ) => {
|
|
840
|
-
qns.answers.forEach( ( answ ) => {
|
|
841
|
-
if ( answ.nestedQuestion.length > 20 ) {
|
|
842
|
-
checkNestedLevel = true;
|
|
843
|
-
}
|
|
844
|
-
} );
|
|
845
|
-
} );
|
|
846
|
-
|
|
847
|
-
console.log( checkNestedLevel, 'lebej' );
|
|
848
|
-
|
|
849
|
-
if ( checkNestedLevel ) {
|
|
850
|
-
return res.sendError( { message: 'Unable to create more than 20 linked questions' }, 400 );
|
|
851
|
-
}
|
|
852
|
-
|
|
853
904
|
sectionList.push( {
|
|
854
905
|
section: section.name,
|
|
855
906
|
sectionOldName: section.oldName,
|
|
@@ -906,8 +957,8 @@ export const update = async ( req, res ) => {
|
|
|
906
957
|
delete ans.answeroptionNumber;
|
|
907
958
|
} );
|
|
908
959
|
let compare = findDifferences( qn, question );
|
|
909
|
-
if ( Object.keys( compare ).length
|
|
910
|
-
questionList.questionEdit.push( { sectionName: ele.section, questions: [ { previous: qn
|
|
960
|
+
if ( Object.keys( compare ).length ) {
|
|
961
|
+
questionList.questionEdit.push( { sectionName: ele.section, questions: [ { previous: qn, new: question } ] } );
|
|
911
962
|
}
|
|
912
963
|
} else {
|
|
913
964
|
let sectionIndex = questionList.questionDelete.findIndex( ( sec ) => sec.sectionName === ele.section );
|
|
@@ -971,14 +1022,40 @@ export const update = async ( req, res ) => {
|
|
|
971
1022
|
questionAdd: questionList.questionAdd,
|
|
972
1023
|
questionEdit: questionList.questionEdit,
|
|
973
1024
|
questionDelete: questionList.questionDelete,
|
|
1025
|
+
userType: req.user.userType,
|
|
974
1026
|
},
|
|
975
1027
|
};
|
|
976
|
-
|
|
1028
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, insertLogData );
|
|
977
1029
|
}
|
|
1030
|
+
|
|
1031
|
+
if ( inputBody.submitType == 'save' ) {
|
|
1032
|
+
let logObj = {
|
|
1033
|
+
client_id: inputBody.clientId,
|
|
1034
|
+
createAt: new Date(),
|
|
1035
|
+
sourceCheckList_id: req.params.checklistId,
|
|
1036
|
+
checkListName: inputBody.checklistName,
|
|
1037
|
+
fromCheckListName: '',
|
|
1038
|
+
type: 'checklist',
|
|
1039
|
+
action: 'draft',
|
|
1040
|
+
storeName: '',
|
|
1041
|
+
store_id: '',
|
|
1042
|
+
createdByEmail: req.user.email,
|
|
1043
|
+
createdBy: req.user.userName,
|
|
1044
|
+
coverage: 'store',
|
|
1045
|
+
logDetails: {},
|
|
1046
|
+
userType: req.user.userType,
|
|
1047
|
+
};
|
|
1048
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
1049
|
+
}
|
|
1050
|
+
let actionType = 'Checklist Updated';
|
|
1051
|
+
let teamsMsg;
|
|
1052
|
+
let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
1053
|
+
teamsMsg = 'ClientId: '+ req.body.clientId + ', Action: '+ actionType + ', ChecklistId: '+ checkListId + ', Checklist Name: '+ inputBody.checklistName + ', UpDatedBy: '+ req.user.email;
|
|
1054
|
+
sendTeamsNotification( teamsAlertUrls.checklist, teamsMsg );
|
|
978
1055
|
return res.sendSuccess( { message: 'CheckList Updated Successfully', checklistId: req.params.checklistId } );
|
|
979
1056
|
} catch ( e ) {
|
|
980
|
-
logger.error(
|
|
981
|
-
res.sendError( e, 500 );
|
|
1057
|
+
logger.error( 'update =>', e );
|
|
1058
|
+
return res.sendError( e, 500 );
|
|
982
1059
|
}
|
|
983
1060
|
};
|
|
984
1061
|
|
|
@@ -1003,11 +1080,11 @@ export const uploadImage = async ( req, res ) => {
|
|
|
1003
1080
|
};
|
|
1004
1081
|
imgUrl = await fileUpload( params );
|
|
1005
1082
|
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
imgUrl =
|
|
1083
|
+
let inputData = {
|
|
1084
|
+
Bucket: bucket.sop,
|
|
1085
|
+
file_path: imgUrl.Key,
|
|
1086
|
+
};
|
|
1087
|
+
imgUrl = await signedUrl( inputData );
|
|
1011
1088
|
if ( !imgUrl ) {
|
|
1012
1089
|
return res.sendError( { message: 'Something went Wrong' }, 500 );
|
|
1013
1090
|
}
|
|
@@ -1601,6 +1678,7 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1601
1678
|
await checklistLogs.create( logInsertData );
|
|
1602
1679
|
|
|
1603
1680
|
checklistDetails = await checklistService.findOne( { _id: inputBody.checkListDetails._id, type: 'checklist', isdeleted: false } );
|
|
1681
|
+
let oldPublish = checklistDetails.publish;
|
|
1604
1682
|
|
|
1605
1683
|
if ( [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection' ].includes( inputBody.checkListDetails.checkListType ) && inputBody.uploadUser ) {
|
|
1606
1684
|
checklistDetails = await checklistService.findOne( { _id: inputBody.checkListDetails._id, type: 'checklist' } );
|
|
@@ -1613,8 +1691,9 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1613
1691
|
if ( inputBody.timeZone ) {
|
|
1614
1692
|
currentDate = dayjs().tz( inputBody.timeZone ).format();
|
|
1615
1693
|
} else {
|
|
1616
|
-
currentDate = dayjs().format();
|
|
1694
|
+
currentDate = dayjs().format( 'HH:mm:ss' );
|
|
1617
1695
|
}
|
|
1696
|
+
currentDate = dayjs.utc( currentDate, 'HH:mm:ss' ).format();
|
|
1618
1697
|
let updatedscheduleEndTimeISO = dayjs.utc( inputBody?.checkListDetails?.scheduleEndTime, 'hh:mm A' ).format( 'HH:mm:ss' );
|
|
1619
1698
|
let newUpdatedDate = dayjs.utc( updatedscheduleEndTimeISO, 'HH:mm:ss' ).format();
|
|
1620
1699
|
|
|
@@ -1762,15 +1841,21 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1762
1841
|
checklistDetails.configEndDate = checklistDetails.configEndDate ? dayjs.utc( checklistDetails?.configEndDate ).format( 'YYYY-MM-DD' ) : '';
|
|
1763
1842
|
checklistDetails.scheduleDate = checklistDetails.scheduleDate ? dayjs.utc( checklistDetails?.scheduleDate ).format( 'YYYY-MM-DD' ) : '';
|
|
1764
1843
|
checklistDetails.scheduleRepeatedDay = Array.isArray( checklistDetails.scheduleRepeatedDay ) ? checklistDetails.scheduleRepeatedDay[0] : checklistDetails.scheduleRepeatedDay;
|
|
1765
|
-
configDetails.scheduleRepeatedDay = Array.isArray( configDetails.scheduleRepeatedDay ) ? configDetails?.scheduleRepeatedDay[0] : configDetails?.scheduleRepeatedDay;
|
|
1844
|
+
configDetails.scheduleRepeatedDay = Array.isArray( configDetails.scheduleRepeatedDay ) ? configDetails?.scheduleRepeatedDay?.[0] || '' : configDetails?.scheduleRepeatedDay;
|
|
1766
1845
|
configDetails.scheduleDate = configDetails.scheduleDate ? dayjs( configDetails?.scheduleDate ).format( 'YYYY-MM-DD' ) : '';
|
|
1767
|
-
let removedKeys = [ 'publish', 'publishDate', 'storeCount', 'sections', 'createdAt', 'updatedAt', 'scheduleStartTimeISO', 'scheduleEndTimeISO' ];
|
|
1846
|
+
let removedKeys = [ 'publish', 'publishDate', 'storeCount', 'sections', 'createdAt', 'updatedAt', 'scheduleStartTimeISO', 'scheduleEndTimeISO', 'aiConfig' ];
|
|
1768
1847
|
removedKeys.forEach( ( item ) => {
|
|
1769
1848
|
delete configDetails?.[item];
|
|
1770
1849
|
delete checklistDetails?.[item];
|
|
1771
1850
|
} );
|
|
1772
1851
|
let differences = findObjectDifference( checklistDetails, configDetails );
|
|
1773
|
-
if ( Object.keys( differences ).length || req.body.added.length || req.body.removed.length ) {
|
|
1852
|
+
if ( Object.keys( differences ).length || req.body.added.length || req.body.removed?.user?.length || req.body.removed?.store?.length ) {
|
|
1853
|
+
let showSchedule = false;
|
|
1854
|
+
let scheduleKeys = [ 'scheduleDate', 'schedule', 'scheduleEndTime', 'scheduleStartTime', 'scheduleRepeatedDay', 'scheduleRepeatedType', 'configStartDate', 'configEndDate', 'scheduleWeekDays', 'scheduleRepeatedMonthWeek', 'specificDate' ];
|
|
1855
|
+
|
|
1856
|
+
if ( scheduleKeys.some( ( key ) => differences?.[key] ) ) {
|
|
1857
|
+
showSchedule = true;
|
|
1858
|
+
}
|
|
1774
1859
|
let insertData = {
|
|
1775
1860
|
client_id: req.body.clientId,
|
|
1776
1861
|
createAt: new Date(),
|
|
@@ -1778,7 +1863,7 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1778
1863
|
checkListName: configDetails.checkListName,
|
|
1779
1864
|
fromCheckListName: '',
|
|
1780
1865
|
type: 'checklist',
|
|
1781
|
-
action: 'updated',
|
|
1866
|
+
action: inputBody.checkListDetails.publish ? 'updated' : 'draft',
|
|
1782
1867
|
storeName: '',
|
|
1783
1868
|
store_id: '',
|
|
1784
1869
|
createdByEmail: req.user.email,
|
|
@@ -1787,29 +1872,29 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1787
1872
|
logDetails: {
|
|
1788
1873
|
schedule: {
|
|
1789
1874
|
previous: {
|
|
1790
|
-
...(
|
|
1791
|
-
schedule:
|
|
1792
|
-
time: ( (
|
|
1793
|
-
scheduleRepeatedDay:
|
|
1794
|
-
scheduleRepeatedType:
|
|
1795
|
-
...(
|
|
1796
|
-
...(
|
|
1797
|
-
scheduleWeekDays:
|
|
1798
|
-
scheduleRepeatedMonthWeek:
|
|
1799
|
-
specificDate:
|
|
1875
|
+
...( showSchedule && checklistDetails.schedule == 'onetime' ) ? { scheduleDate: dayjs( checklistDetails?.scheduleDate, 'YYYY-MM-DD' ).format( 'DD MMM, YYYY' ) } :{},
|
|
1876
|
+
schedule: showSchedule ? checklistDetails.schedule : '',
|
|
1877
|
+
time: ( ( showSchedule ) && ( checklistDetails.scheduleStartTime != '' || checklistDetails.scheduleEndTime != '' ) ) ? checklistDetails.scheduleStartTime + ' to ' + checklistDetails.scheduleEndTime : '',
|
|
1878
|
+
scheduleRepeatedDay: showSchedule ? checklistDetails?.scheduleRepeatedDay : '',
|
|
1879
|
+
scheduleRepeatedType: showSchedule ? checklistDetails?.scheduleRepeatedType : '',
|
|
1880
|
+
...( showSchedule && checklistDetails?.configStartDate ) ? { configStartDate: dayjs( checklistDetails?.configStartDate, 'YYYY-MM-DD' ).format( 'DD MMM, YYYY' ) } :{},
|
|
1881
|
+
...( showSchedule && checklistDetails?.configEndDate ) ? { configEndDate: dayjs( checklistDetails?.configEndDate, 'YYYY-MM-DD' ).format( 'DD MMM, YYYY' ) } :{},
|
|
1882
|
+
scheduleWeekDays: showSchedule ? checklistDetails?.scheduleWeekDays : [],
|
|
1883
|
+
scheduleRepeatedMonthWeek: showSchedule ? checklistDetails?.scheduleRepeatedMonthWeek : '',
|
|
1884
|
+
specificDate: showSchedule ? checklistDetails?.specificDate : [],
|
|
1800
1885
|
|
|
1801
1886
|
},
|
|
1802
1887
|
new: {
|
|
1803
|
-
...(
|
|
1804
|
-
schedule:
|
|
1805
|
-
time: ( (
|
|
1806
|
-
scheduleRepeatedDay:
|
|
1807
|
-
scheduleRepeatedType:
|
|
1808
|
-
...(
|
|
1809
|
-
...(
|
|
1810
|
-
scheduleWeekDays:
|
|
1811
|
-
scheduleRepeatedMonthWeek:
|
|
1812
|
-
specificDate:
|
|
1888
|
+
...( showSchedule && configDetails.schedule == 'onetime' ) ? { scheduleDate: dayjs( configDetails?.scheduleDate, 'YYYY-MM-DD' ).format( 'DD MMM, YYYY' ) } :{},
|
|
1889
|
+
schedule: showSchedule ? configDetails.schedule : '',
|
|
1890
|
+
time: ( ( showSchedule ) && ( configDetails.scheduleStartTime != '' || configDetails.scheduleEndTime != '' ) ) ? configDetails.scheduleStartTime + ' to ' + configDetails.scheduleEndTime : '',
|
|
1891
|
+
scheduleRepeatedDay: showSchedule ? configDetails?.scheduleRepeatedDay : '',
|
|
1892
|
+
scheduleRepeatedType: showSchedule ? configDetails?.scheduleRepeatedType : '',
|
|
1893
|
+
...( showSchedule && configDetails?.configStartDate ) ? { configStartDate: dayjs( configDetails?.configStartDate, 'YYYY-MM-DD' ).format( 'DD MMM, YYYY' ) } :{},
|
|
1894
|
+
...( showSchedule && configDetails?.configEndDate ) ? { configEndDate: dayjs( configDetails?.configEndDate, 'YYYY-MM-DD' ).format( 'DD MMM, YYYY' ) } :{},
|
|
1895
|
+
scheduleWeekDays: showSchedule ? configDetails?.scheduleWeekDays : [],
|
|
1896
|
+
scheduleRepeatedMonthWeek: showSchedule ? configDetails?.scheduleRepeatedMonthWeek : '',
|
|
1897
|
+
specificDate: showSchedule ? configDetails?.specificDate : [],
|
|
1813
1898
|
},
|
|
1814
1899
|
},
|
|
1815
1900
|
response: {
|
|
@@ -1827,39 +1912,48 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1827
1912
|
],
|
|
1828
1913
|
},
|
|
1829
1914
|
...( differences?.approver ) ? { approver:
|
|
1830
|
-
{ previous:
|
|
1831
|
-
new:
|
|
1915
|
+
{ previous: checklistDetails?.approver.map( ( item ) => item.name ).toString(),
|
|
1916
|
+
new: configDetails?.approver.map( ( item ) => item.name ).toString() },
|
|
1832
1917
|
} : { approver: {} },
|
|
1833
1918
|
...( differences?.owner ) ? { owner:
|
|
1834
|
-
{ previous:
|
|
1835
|
-
new:
|
|
1919
|
+
{ previous: checklistDetails?.owner.map( ( item ) => item.name ).toString(),
|
|
1920
|
+
new: configDetails?.owner.map( ( item ) => item.name ).toString() },
|
|
1836
1921
|
} : { owner: {} },
|
|
1837
1922
|
...( req.body.checkListDetails.coverage == 'store' ) ? { storeAdded: req.body.added } :{ storeAdded: [] },
|
|
1838
|
-
...( req.body.
|
|
1923
|
+
...( req.body.removed.store.length ) ? { storeRemoved: req.body.removed.store } :{ storeRemoved: [] },
|
|
1839
1924
|
...( req.body.checkListDetails.coverage == 'user' ) ? { userAdded: req.body.added } :{ userAdded: [] },
|
|
1840
|
-
...( req.body.
|
|
1925
|
+
...( req.body.removed.user.length ) ? { userRemoved: req.body.removed.user } :{ userRemoved: [] },
|
|
1841
1926
|
},
|
|
1927
|
+
userType: req.user.userType,
|
|
1842
1928
|
};
|
|
1843
|
-
|
|
1929
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, insertData );
|
|
1844
1930
|
}
|
|
1845
1931
|
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1932
|
+
if ( inputBody.checkListDetails.publish != oldPublish ) {
|
|
1933
|
+
let logObj = {
|
|
1934
|
+
client_id: inputBody.checkListDetails.client_id,
|
|
1935
|
+
createAt: new Date(),
|
|
1936
|
+
sourceCheckList_id: inputBody.checkListDetails._id,
|
|
1937
|
+
checkListName: inputBody.checkListDetails.checkListName,
|
|
1938
|
+
fromCheckListName: '',
|
|
1939
|
+
type: 'checklist',
|
|
1940
|
+
action: inputBody.checkListDetails.publish ? 'published' : 'unpublished',
|
|
1941
|
+
storeName: '',
|
|
1942
|
+
store_id: '',
|
|
1943
|
+
createdByEmail: req.user.email,
|
|
1944
|
+
createdBy: req.user.userName,
|
|
1945
|
+
coverage: inputBody.checkListDetails.coverage,
|
|
1946
|
+
logDetails: {},
|
|
1947
|
+
userType: req.user.userType,
|
|
1948
|
+
};
|
|
1949
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
1950
|
+
}
|
|
1951
|
+
let actionType;
|
|
1952
|
+
let teamsMsg;
|
|
1953
|
+
actionType = inputBody.checkListDetails.publish ? 'configPublish' : 'configDraft';
|
|
1954
|
+
let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
1955
|
+
teamsMsg = 'ClientId: '+ checklistDetails.client_id + ', Action: '+ actionType + ', ChecklistId: '+ checklistDetails._id + ', Checklist Name: '+ checklistDetails.checkListName + ', UpDatedBy: '+ req.user.email;
|
|
1956
|
+
sendTeamsNotification( teamsAlertUrls.checklist, teamsMsg );
|
|
1863
1957
|
if ( response?.modifiedCount || response?.matchedCount || response?.upsertedCount ) {
|
|
1864
1958
|
return res.sendSuccess( { id, message: 'Configured Updated Successfully' } );
|
|
1865
1959
|
}
|
|
@@ -1871,7 +1965,6 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1871
1965
|
return res.sendError( e, 500 );
|
|
1872
1966
|
}
|
|
1873
1967
|
};
|
|
1874
|
-
|
|
1875
1968
|
function findObjectDifference( oldObj, newObj ) {
|
|
1876
1969
|
const isEqual = ( a, b ) => JSON.stringify( a ) === JSON.stringify( b );
|
|
1877
1970
|
|
|
@@ -1986,13 +2079,15 @@ export const updatePublish = async ( req, res ) => {
|
|
|
1986
2079
|
createdBy: req.user.userName,
|
|
1987
2080
|
coverage: getCheckDetails.coverage,
|
|
1988
2081
|
logDetails: {},
|
|
2082
|
+
userType: req.user.userType,
|
|
1989
2083
|
};
|
|
1990
|
-
|
|
2084
|
+
insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
|
|
1991
2085
|
if ( getCheckDetails.checkListType == 'custom' ) {
|
|
1992
2086
|
let currentDate = dayjs.utc().format();
|
|
1993
2087
|
let updatedscheduleEndTimeISO = dayjs.utc( getCheckDetails.scheduleEndTimeISO ).format( 'HH:mm:ss' );
|
|
1994
2088
|
let newUpdatedDate = dayjs.utc( updatedscheduleEndTimeISO, 'HH:mm:ss' ).format();
|
|
1995
2089
|
|
|
2090
|
+
|
|
1996
2091
|
if ( req.body.publish && req.body.publish == true ) {
|
|
1997
2092
|
if ( newUpdatedDate > currentDate ) {
|
|
1998
2093
|
let deleteQuery = {
|
|
@@ -2058,6 +2153,12 @@ export const updatePublish = async ( req, res ) => {
|
|
|
2058
2153
|
createdByEmail: req.user.email,
|
|
2059
2154
|
};
|
|
2060
2155
|
await checklistLogs.create( logInsertData );
|
|
2156
|
+
let actionType;
|
|
2157
|
+
let teamsMsg;
|
|
2158
|
+
actionType = req.body.publish ? 'publish' : 'unpublish';
|
|
2159
|
+
let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
2160
|
+
teamsMsg = 'ClientId: '+ getCheckDetails.client_id + ', Action: '+ actionType + ', ChecklistId: '+ getCheckDetails._id + ', Checklist Name: '+ getCheckDetails.checkListName + ', UpDatedBy: '+ req.user.email;
|
|
2161
|
+
sendTeamsNotification( teamsAlertUrls.checklist, teamsMsg );
|
|
2061
2162
|
return res.sendSuccess( { checklistName: getCheckDetails.checkListName, message: 'Updated Successfully' } );
|
|
2062
2163
|
} catch ( e ) {
|
|
2063
2164
|
logger.error( 'updatePublish erroe =>', e );
|
|
@@ -2329,7 +2430,7 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2329
2430
|
{
|
|
2330
2431
|
$project: {
|
|
2331
2432
|
newEmail: { $toLower: '$email' },
|
|
2332
|
-
isActive: 1,
|
|
2433
|
+
// isActive: 1,
|
|
2333
2434
|
clientId: 1,
|
|
2334
2435
|
email: 1,
|
|
2335
2436
|
},
|
|
@@ -2337,7 +2438,7 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2337
2438
|
{
|
|
2338
2439
|
$match: {
|
|
2339
2440
|
newEmail: { $in: userEmailList },
|
|
2340
|
-
isActive: true,
|
|
2441
|
+
// isActive: true,
|
|
2341
2442
|
clientId: { $ne: req.body.clientId },
|
|
2342
2443
|
},
|
|
2343
2444
|
},
|
|
@@ -2379,7 +2480,7 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2379
2480
|
let newStoreList = storeList.filter( ( ele ) => ele != null && !existsStore.includes( ele.toLowerCase() ) );
|
|
2380
2481
|
if ( req.body.coverage == 'store' ) {
|
|
2381
2482
|
assignDetails.forEach( ( item ) => {
|
|
2382
|
-
let getStoreDetails = storeDetails.find( ( store ) => store.storeName.toLowerCase() == item.storeName.toLowerCase() );
|
|
2483
|
+
let getStoreDetails = storeDetails.find( ( store ) => store.storeName.trim().toLowerCase() == item.storeName.trim().toLowerCase() );
|
|
2383
2484
|
if ( getStoreDetails ) {
|
|
2384
2485
|
let storeUserDetails = userDetails.find( ( ele ) => ele.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
|
|
2385
2486
|
item._id = getStoreDetails._id;
|
|
@@ -2400,6 +2501,10 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2400
2501
|
} );
|
|
2401
2502
|
}
|
|
2402
2503
|
|
|
2504
|
+
newStoreList = [ ...new Set( newStoreList.map( ( item ) => item ) ) ];
|
|
2505
|
+
newUserList = [ ...new Set( newUserList.map( ( item ) => item ) ) ];
|
|
2506
|
+
existEmail = [ ...new Set( existEmail.map( ( item ) => item ) ) ];
|
|
2507
|
+
inActiveStores = [ ...new Set( inActiveStores.map( ( item ) => item ) ) ];
|
|
2403
2508
|
if ( ( newUserList.length || newStoreList.length || existEmail.length || inActiveStores.length ) && !req.body?.addUser ) {
|
|
2404
2509
|
return res.sendError( { validate: false, user: newUserList, store: newStoreList, existEmail, inActiveStores, data: assignDetails }, 400 );
|
|
2405
2510
|
}
|
|
@@ -2845,6 +2950,7 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
|
|
|
2845
2950
|
insertdata.restrictAttendance = getCLconfig?.restrictAttendance;
|
|
2846
2951
|
insertdata.coverage = getCLconfig?.coverage;
|
|
2847
2952
|
insertdata.rawImageUpload = getCLconfig?.rawImageUpload || false;
|
|
2953
|
+
insertdata.rawVideoUpload = getCLconfig?.rawVideoUpload || false;
|
|
2848
2954
|
|
|
2849
2955
|
let collectSections = [];
|
|
2850
2956
|
let sectionQuery = [];
|
|
@@ -3434,6 +3540,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3434
3540
|
}
|
|
3435
3541
|
if ( getsubmitDetails ) {
|
|
3436
3542
|
getsubmitDetails = [ getsubmitDetails ];
|
|
3543
|
+
console.log( submittedDetails, getsubmitDetails );
|
|
3437
3544
|
}
|
|
3438
3545
|
function findDifferences( obj1, obj2 ) {
|
|
3439
3546
|
return Object.keys( obj1 ).reduce( ( diff, key ) => {
|
|
@@ -3464,14 +3571,11 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3464
3571
|
let findQuestion = getsubmitDetails[0].questionAnswers[index].questions.findIndex( ( ele ) => ele.qname.trim() == qns?.oldQname?.trim() || ele.qname.trim() == qns.qname.trim() );
|
|
3465
3572
|
if ( findQuestion != -1 ) {
|
|
3466
3573
|
let data = JSON.parse( JSON.stringify( getsubmitDetails[0].questionAnswers[index].questions[findQuestion] ) );
|
|
3467
|
-
|
|
3468
|
-
question.push( { question: qns, type: 'noChange' } );
|
|
3469
|
-
}
|
|
3574
|
+
getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qno = qns.qno;
|
|
3470
3575
|
delete data.userAnswer;
|
|
3471
3576
|
delete data.parentanswer;
|
|
3472
3577
|
delete data.remarks;
|
|
3473
3578
|
delete data.linkquestionenabled;
|
|
3474
|
-
delete data.uniqueNo;
|
|
3475
3579
|
if ( data.descriptivetype == null ) {
|
|
3476
3580
|
delete data.descriptivetype;
|
|
3477
3581
|
}
|
|
@@ -3483,136 +3587,29 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3483
3587
|
delete ans.index;
|
|
3484
3588
|
delete ans.validationAnswer;
|
|
3485
3589
|
delete ans.answeroptionNumber;
|
|
3486
|
-
ans.nestedQuestion = ans?.oldNestedQuestion ? ans.oldNestedQuestion : ans.nestedQuestion;
|
|
3487
|
-
ans.linkedQuestion = ans?.oldLinkedQuestion ? ans.oldLinkedQuestion : ans.linkedQuestion;
|
|
3488
|
-
delete ans.oldNestedQuestion;
|
|
3489
|
-
delete ans.oldLinkedQuestion;
|
|
3490
3590
|
} );
|
|
3491
3591
|
const compare = findDifferences( data, qns );
|
|
3492
3592
|
if ( compare?.answerType || compare?.answers || compare?.linkType ) {
|
|
3493
3593
|
logger.info( 'compare =>', compare );
|
|
3494
|
-
logger.info( 'compareSection =>', { section: section.sectionName } );
|
|
3495
|
-
logger.info( 'qno =>', { qno: data.qno } );
|
|
3496
3594
|
modifiedCount++;
|
|
3497
|
-
question.push(
|
|
3595
|
+
question.push( qns );
|
|
3498
3596
|
} else {
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
}
|
|
3502
|
-
// getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qname = qns.qname;
|
|
3597
|
+
getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qname = qns.qname;
|
|
3598
|
+
question.push( getsubmitDetails[0].questionAnswers[index].questions[findQuestion] );
|
|
3503
3599
|
}
|
|
3504
3600
|
} else {
|
|
3505
3601
|
modifiedCount++;
|
|
3506
|
-
question.push(
|
|
3602
|
+
question.push( qns );
|
|
3507
3603
|
}
|
|
3508
3604
|
} );
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
sectionList.push( { sectionName: section.sectionName, oldName: section.sectionOldName, question: question, type: 'edit' } );
|
|
3512
|
-
}
|
|
3605
|
+
getsubmitDetails[0].questionAnswers[index].questions = question;
|
|
3606
|
+
sectionList.push( getsubmitDetails[0].questionAnswers[index] );
|
|
3513
3607
|
} else {
|
|
3514
3608
|
modifiedCount++;
|
|
3515
|
-
sectionList.push(
|
|
3609
|
+
sectionList.push( section );
|
|
3516
3610
|
}
|
|
3517
3611
|
}
|
|
3518
|
-
|
|
3519
|
-
getsubmitDetails[0].questionAnswers.forEach( ( section, sectionIdx ) => {
|
|
3520
|
-
let sectionIndex = questionList.findIndex( ( sec ) => section.sectionName == sec?.sectionOldName || section.sectionName == sec.sectionName );
|
|
3521
|
-
if ( sectionIndex == -1 ) {
|
|
3522
|
-
removed.push( { section: section.sectionName, type: 'delete' } );
|
|
3523
|
-
} else {
|
|
3524
|
-
let question = [];
|
|
3525
|
-
section.questions.forEach( ( qn ) => {
|
|
3526
|
-
let questionIndex = questionList[sectionIndex].questions.findIndex( ( ele ) => qn.qname.trim() == ele?.oldQname?.trim() || qn.qname.trim() == ele.qname.trim() );
|
|
3527
|
-
if ( questionIndex == -1 ) {
|
|
3528
|
-
question.push( qn.qname );
|
|
3529
|
-
}
|
|
3530
|
-
} );
|
|
3531
|
-
if ( question.length ) {
|
|
3532
|
-
removed.push( { section: section.sectionName, question: question, type: 'qnDelete' } );
|
|
3533
|
-
}
|
|
3534
|
-
}
|
|
3535
|
-
} );
|
|
3536
|
-
removed.forEach( ( ele ) => {
|
|
3537
|
-
if ( ele?.type == 'delete' ) {
|
|
3538
|
-
getsubmitDetails[0].questionAnswers = getsubmitDetails[0].questionAnswers.filter( ( section ) => section.sectionName != ele.section );
|
|
3539
|
-
} else {
|
|
3540
|
-
let sectionIndex = getsubmitDetails[0].questionAnswers.findIndex( ( section ) => section.sectionName == ele?.section );
|
|
3541
|
-
getsubmitDetails[0].questionAnswers[sectionIndex].questions = getsubmitDetails[0].questionAnswers[sectionIndex].questions.filter( ( qns ) => !qns.qname.includes( ele.question ) );
|
|
3542
|
-
}
|
|
3543
|
-
} );
|
|
3544
|
-
|
|
3545
|
-
// getsubmitDetails[0].questionAnswers = sectionList;
|
|
3546
|
-
logger.info( 'removedSections =>', { data: JSON.stringify( removed ) } );
|
|
3547
|
-
logger.info( 'modifiedSections =>', { data: JSON.stringify( sectionList ) } );
|
|
3548
|
-
sectionList.forEach( ( sec ) => {
|
|
3549
|
-
if ( sec.type == 'add' ) {
|
|
3550
|
-
getsubmitDetails[0].questionAnswers.push( sec.section );
|
|
3551
|
-
} else {
|
|
3552
|
-
sec.question.forEach( ( qn ) => {
|
|
3553
|
-
let sectionDetails = getsubmitDetails[0].questionAnswers.findIndex( ( section ) => section.sectionName == sec?.oldName || section.sectionName == sec.sectionName );
|
|
3554
|
-
if ( qn.type == 'add' ) {
|
|
3555
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions.push( qn.question );
|
|
3556
|
-
} else {
|
|
3557
|
-
let questions = getsubmitDetails[0].questionAnswers[sectionDetails].questions.reduce( ( acc, ele, idx ) => {
|
|
3558
|
-
if ( ele.qname.trim() == qn?.question?.oldQname?.trim() || ele.qname.trim() == qn.question.qname.trim() ) {
|
|
3559
|
-
acc.push( idx );
|
|
3560
|
-
}
|
|
3561
|
-
return acc;
|
|
3562
|
-
}, [] );
|
|
3563
|
-
if ( questions.length && [ 'qnEdit', 'nameChange', 'noChange' ].includes( qn.type ) ) {
|
|
3564
|
-
if ( qn.type == 'qnEdit' ) {
|
|
3565
|
-
let checkLinkType = getsubmitDetails[0].questionAnswers[sectionDetails].questions[questions[0]].linkType;
|
|
3566
|
-
if ( checkLinkType && !qn.question.linkType ) {
|
|
3567
|
-
questions.forEach( ( qnIdx, index ) => {
|
|
3568
|
-
if ( index != 0 ) {
|
|
3569
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions.splice( qnIdx, 1 );
|
|
3570
|
-
}
|
|
3571
|
-
} );
|
|
3572
|
-
questions = [ questions[0] ];
|
|
3573
|
-
}
|
|
3574
|
-
}
|
|
3575
|
-
questions.forEach( ( qnIdx ) => {
|
|
3576
|
-
if ( qn.type == 'qnEdit' ) {
|
|
3577
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].answers.forEach( ( ele ) => {
|
|
3578
|
-
console.log( ele?.nestedQuestion );
|
|
3579
|
-
if ( ele?.nestedQuestion.length ) {
|
|
3580
|
-
ele?.nestedQuestion.forEach( ( nested ) => {
|
|
3581
|
-
let findIndex = getsubmitDetails[0].questionAnswers[sectionDetails].questions.findIndex( ( qn ) => qn.uniqueNo == nested );
|
|
3582
|
-
if ( findIndex != -1 ) {
|
|
3583
|
-
delete getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].userAnswer;
|
|
3584
|
-
let questionDetails = getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex];
|
|
3585
|
-
let checkQuestionExists = getsubmitDetails[0].questionAnswers[sectionDetails].questions.filter( ( qnDetails ) => qnDetails.qname == questionDetails.qname );
|
|
3586
|
-
if ( checkQuestionExists.length > 1 ) {
|
|
3587
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions.splice( findIndex, 1 );
|
|
3588
|
-
} else {
|
|
3589
|
-
delete getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].uniqueNo;
|
|
3590
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].linkquestionenabled = false;
|
|
3591
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].answers.forEach( ( ele ) => {
|
|
3592
|
-
if ( ele?.oldNestedQuestion?.length ) {
|
|
3593
|
-
ele.nestedQuestion = ele.oldNestedQuestion;
|
|
3594
|
-
ele.linkedQuestion = ele.oldLinkedQuestion;
|
|
3595
|
-
}
|
|
3596
|
-
} );
|
|
3597
|
-
}
|
|
3598
|
-
}
|
|
3599
|
-
} );
|
|
3600
|
-
}
|
|
3601
|
-
} );
|
|
3602
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx] = qn.question;
|
|
3603
|
-
} else {
|
|
3604
|
-
if ( qn.type == 'nameChange' ) {
|
|
3605
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].qname = qn.question.qname;
|
|
3606
|
-
} else {
|
|
3607
|
-
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].qno = qn.question.qno;
|
|
3608
|
-
}
|
|
3609
|
-
}
|
|
3610
|
-
} );
|
|
3611
|
-
}
|
|
3612
|
-
}
|
|
3613
|
-
} );
|
|
3614
|
-
}
|
|
3615
|
-
} );
|
|
3612
|
+
getsubmitDetails[0].questionAnswers = sectionList;
|
|
3616
3613
|
if ( modifiedCount ) {
|
|
3617
3614
|
getsubmitDetails[0].checklistStatus = 'inprogress';
|
|
3618
3615
|
getsubmitDetails[0].date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
|
|
@@ -3621,7 +3618,6 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3621
3618
|
getsubmitDetails[0].approvalStatus = false;
|
|
3622
3619
|
}
|
|
3623
3620
|
let data = { ...getsubmitDetails[0]._doc };
|
|
3624
|
-
logger.info( 'modifiedData =>', { data: JSON.stringify( data ) } );
|
|
3625
3621
|
await processedchecklist.updateOne( { _id: getsubmitDetails[0]._id }, data );
|
|
3626
3622
|
if ( editSubmit && getsubmitDetails[0].checklistStatus == 'submit' ) {
|
|
3627
3623
|
let user = {
|
|
@@ -3667,6 +3663,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3667
3663
|
element4.restrictAttendance = getCLconfig?.restrictAttendance;
|
|
3668
3664
|
element4.coverage = getCLconfig?.coverage;
|
|
3669
3665
|
element4.rawImageUpload = getCLconfig?.rawImageUpload || false;
|
|
3666
|
+
element4.rawVideoUpload = getCLconfig?.rawVideoUpload || false;
|
|
3670
3667
|
assignUserList.push( { ...element4 } );
|
|
3671
3668
|
}
|
|
3672
3669
|
} ) );
|
|
@@ -3708,25 +3705,19 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3708
3705
|
}
|
|
3709
3706
|
}
|
|
3710
3707
|
} else {
|
|
3711
|
-
let
|
|
3712
|
-
if ( !acc[item.userEmail] ) {
|
|
3713
|
-
acc[item.userEmail]=[ item.store_id ];
|
|
3714
|
-
} else {
|
|
3715
|
-
acc[item.userEmail].push( item.store_id );
|
|
3716
|
-
}
|
|
3717
|
-
return acc;
|
|
3718
|
-
}, {} );
|
|
3708
|
+
let deletedList = [];
|
|
3719
3709
|
|
|
3720
|
-
|
|
3710
|
+
await processedchecklist.deleteMany( { date_string: insertdata.date_string,
|
|
3711
|
+
date_iso: insertdata.date_iso,
|
|
3712
|
+
client_id: insertdata.client_id,
|
|
3713
|
+
checkListId: updatedchecklist._id, checklistStatus: 'open' } );
|
|
3721
3714
|
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
}
|
|
3729
|
-
}
|
|
3715
|
+
|
|
3716
|
+
let actionType = 'deleteOpenUsers';
|
|
3717
|
+
let teamsMsg;
|
|
3718
|
+
let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
3719
|
+
teamsMsg = 'ClientId: '+ insertdata.client_id + ', Action: '+ actionType + ', ChecklistId: '+ getCLconfig._id + ', Checklist Name: '+ getCLconfig.checkListName;
|
|
3720
|
+
sendTeamsNotification( teamsAlertUrls.checklist, teamsMsg );
|
|
3730
3721
|
|
|
3731
3722
|
let inprogressData = await processedchecklist.find( {
|
|
3732
3723
|
date_string: insertdata.date_string,
|
|
@@ -3737,6 +3728,12 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3737
3728
|
}, { userId: 1, store_id: 1 } );
|
|
3738
3729
|
|
|
3739
3730
|
if ( inprogressData.length ) {
|
|
3731
|
+
inprogressData.forEach( ( item ) => {
|
|
3732
|
+
let checkData = assignUserList.find( ( ele ) => ele.userId.toString() == item.userId.toString() && ele.store_id == item.store_id );
|
|
3733
|
+
if ( !checkData ) {
|
|
3734
|
+
deletedList.push( item._id );
|
|
3735
|
+
}
|
|
3736
|
+
} );
|
|
3740
3737
|
assignUserList = assignUserList.filter( ( item ) => {
|
|
3741
3738
|
let findData = inprogressData.find( ( ele ) => ele.userId.toString() == item.userId.toString() && ele.store_id == item.store_id );
|
|
3742
3739
|
if ( !findData ) {
|
|
@@ -3745,11 +3742,15 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3745
3742
|
} );
|
|
3746
3743
|
}
|
|
3747
3744
|
|
|
3748
|
-
|
|
3749
|
-
date_iso: insertdata.date_iso,
|
|
3750
|
-
|
|
3751
|
-
checkListId: updatedchecklist._id, checklistStatus: 'open' } );
|
|
3745
|
+
if ( deletedList.length ) {
|
|
3746
|
+
await processedchecklist.deleteMany( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, _id: { $in: deletedList } } );
|
|
3747
|
+
}
|
|
3752
3748
|
await processedchecklist.insertMany( assignUserList );
|
|
3749
|
+
actionType = 'insertAssignUsers';
|
|
3750
|
+
teamsMsg;
|
|
3751
|
+
teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
3752
|
+
teamsMsg = 'ClientId: '+ insertdata.client_id + ', Action: '+ actionType + ', ChecklistId: '+ getCLconfig._id + ', Checklist Name: '+ getCLconfig.checkListName + ', assignedUserCount:'+ assignUserList.length+', inprogressSubmitCount:' + submittedDetails?.length;
|
|
3753
|
+
sendTeamsNotification( teamsAlertUrls.checklist, teamsMsg );
|
|
3753
3754
|
}
|
|
3754
3755
|
|
|
3755
3756
|
tokenList.forEach( ( item ) => {
|
|
@@ -3824,11 +3825,11 @@ async function updateOpenSearch( user, data ) {
|
|
|
3824
3825
|
export const aiChecklist = async ( req, res ) => {
|
|
3825
3826
|
try {
|
|
3826
3827
|
let storeDetails = await storeService.count( { clientId: req.query.clientId, status: 'active' } );
|
|
3827
|
-
let aiList = [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum' ];
|
|
3828
|
+
let aiList = [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection' ];
|
|
3828
3829
|
let checklistDetails = [];
|
|
3829
3830
|
let publishList = [];
|
|
3830
3831
|
let unpublishList = [];
|
|
3831
|
-
publishList = await checklistService.find( { client_id: req.query.clientId, checkListType: { $in: aiList } }, { publish: 1, checkListName: 1, checkListType: 1, client_id: 1, checkListDescription: 1 } );
|
|
3832
|
+
publishList = await checklistService.find( { client_id: req.query.clientId, checkListType: { $in: aiList } }, { publish: 1, checkListName: 1, checkListType: 1, client_id: 1, checkListDescription: 1, storeCount: 1 } );
|
|
3832
3833
|
if ( publishList.length ) {
|
|
3833
3834
|
let existList = publishList.map( ( item ) => item.checkListType );
|
|
3834
3835
|
aiList = aiList.filter( ( item ) => !existList.includes( item ) );
|
|
@@ -3837,9 +3838,13 @@ export const aiChecklist = async ( req, res ) => {
|
|
|
3837
3838
|
checklistDetails = [ ...publishList, ...unpublishList ];
|
|
3838
3839
|
|
|
3839
3840
|
checklistDetails.forEach( ( item ) => {
|
|
3840
|
-
item.
|
|
3841
|
+
if ( ![ 'mobileusagedetection', 'storeopenandclose', 'cleaning', 'scrum', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended' ].includes( item.checkListType ) ) {
|
|
3842
|
+
item.storeCount = storeDetails;
|
|
3843
|
+
}
|
|
3841
3844
|
} );
|
|
3842
3845
|
|
|
3846
|
+
checklistDetails.sort( ( a, b ) => a.checkListName.localeCompare( b.checkListName ) );
|
|
3847
|
+
|
|
3843
3848
|
return res.sendSuccess( checklistDetails );
|
|
3844
3849
|
} catch ( e ) {
|
|
3845
3850
|
logger.error( 'aiChecklist =>', e );
|
|
@@ -4021,12 +4026,7 @@ export const selectAssign = async ( req, res ) => {
|
|
|
4021
4026
|
// //Select Store and cluster
|
|
4022
4027
|
if ( requestData.assignType == 'store' ) {
|
|
4023
4028
|
let storeQuery = [
|
|
4024
|
-
{
|
|
4025
|
-
$match: {
|
|
4026
|
-
...( req.user.userType==='client'&&req.user.role!='superadmin' ) ? { storeId: { $in: requestData?.assignedStores } } :{ clientId: requestData.clientId },
|
|
4027
|
-
status: 'active',
|
|
4028
|
-
},
|
|
4029
|
-
},
|
|
4029
|
+
{ $match: { clientId: requestData.clientId, status: 'active' } },
|
|
4030
4030
|
{
|
|
4031
4031
|
$project: {
|
|
4032
4032
|
storeName: 1,
|
|
@@ -4036,6 +4036,8 @@ export const selectAssign = async ( req, res ) => {
|
|
|
4036
4036
|
userEmail: { $arrayElemAt: [ '$spocDetails.email', 0 ] },
|
|
4037
4037
|
contact: { $arrayElemAt: [ '$spocDetails.contact', 0 ] },
|
|
4038
4038
|
city: '$storeProfile.city',
|
|
4039
|
+
openTime: '$storeProfile.open',
|
|
4040
|
+
closeTime: '$storeProfile.close',
|
|
4039
4041
|
},
|
|
4040
4042
|
},
|
|
4041
4043
|
|
|
@@ -4188,47 +4190,75 @@ export async function updateAssign( req, res ) {
|
|
|
4188
4190
|
if ( !checklistDetails ) {
|
|
4189
4191
|
return res.sendError( 'No data found', 204 );
|
|
4190
4192
|
}
|
|
4193
|
+
let groupList = req.body.assignedGroup;
|
|
4191
4194
|
req.body.assignedGroup = [ ...new Set( req.body.assignedGroup.map( ( item ) => item.id ) ) ];
|
|
4195
|
+
groupList = req.body.assignedGroup.reduce( ( acc, ele ) => {
|
|
4196
|
+
let findDetails = groupList.find( ( item ) => item.id == ele );
|
|
4197
|
+
if ( findDetails ) {
|
|
4198
|
+
acc.push( findDetails?.clusterName || findDetails?.teamName );
|
|
4199
|
+
};
|
|
4200
|
+
return acc;
|
|
4201
|
+
}, [] );
|
|
4192
4202
|
// req.body.assignedGroup = req.body.assignedGroup.map( ( ele ) => {
|
|
4193
4203
|
// return { id: ele };
|
|
4194
4204
|
// } );
|
|
4195
4205
|
let getAssignedDetails = await assignedService.find( { checkListId: req.body.checkListId } );
|
|
4206
|
+
let oldCoverage;
|
|
4196
4207
|
if ( getAssignedDetails.length ) {
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4208
|
+
oldCoverage = getAssignedDetails?.[0]?.coverage;
|
|
4209
|
+
let storeClusterDetails = getAssignedDetails.filter( ( ele ) => ele?.storeName || ele?.clusterName );
|
|
4210
|
+
let userTeamDetails = getAssignedDetails.filter( ( ele ) => !ele?.storeName && ( ele?.userName || ele?.teamName ) );
|
|
4211
|
+
storeClusterDetails = [ ...new Set( storeClusterDetails.map( ( ele ) => ele?.storeName || ele?.clusterName ) ) ];
|
|
4212
|
+
userTeamDetails= [ ...new Set( userTeamDetails.map( ( ele ) => ele?.userName || ele?.teamName ) ) ];
|
|
4213
|
+
getAssignedDetails = [ ...storeClusterDetails, ...userTeamDetails ];
|
|
4202
4214
|
}
|
|
4203
|
-
|
|
4204
|
-
let added =
|
|
4215
|
+
let assignedAllList = [ ...req.body.assignedList, ...groupList ];
|
|
4216
|
+
let added = assignedAllList.filter( ( item ) => {
|
|
4205
4217
|
let storeUsername;
|
|
4218
|
+
let clusterTeamName;
|
|
4206
4219
|
if ( req.body.coverage == 'store' ) {
|
|
4207
|
-
|
|
4220
|
+
if ( item?.storeName ) {
|
|
4221
|
+
storeUsername = item?.storeName;
|
|
4222
|
+
} else {
|
|
4223
|
+
clusterTeamName = item;
|
|
4224
|
+
}
|
|
4208
4225
|
} else {
|
|
4209
|
-
|
|
4226
|
+
if ( item?.userName ) {
|
|
4227
|
+
storeUsername = item?.userName;
|
|
4228
|
+
} else {
|
|
4229
|
+
clusterTeamName = item;
|
|
4230
|
+
}
|
|
4210
4231
|
}
|
|
4211
|
-
if ( !getAssignedDetails.includes( storeUsername ) ) {
|
|
4232
|
+
if ( !getAssignedDetails.includes( storeUsername ) && !getAssignedDetails.includes( clusterTeamName ) ) {
|
|
4212
4233
|
return item;
|
|
4213
4234
|
}
|
|
4214
4235
|
} ).map( ( ele ) => {
|
|
4215
4236
|
if ( req.body.coverage == 'store' ) {
|
|
4216
|
-
return ele
|
|
4237
|
+
return ele?.storeName || ele;
|
|
4217
4238
|
} else {
|
|
4218
|
-
return ele
|
|
4239
|
+
return ele?.userName || ele;
|
|
4219
4240
|
}
|
|
4220
4241
|
} );
|
|
4221
4242
|
let removed = getAssignedDetails.filter( ( item ) => {
|
|
4222
4243
|
let list;
|
|
4223
4244
|
if ( req.body.coverage == 'store' ) {
|
|
4224
|
-
list =
|
|
4245
|
+
list = assignedAllList.map( ( item ) => item?.storeName );
|
|
4246
|
+
let clusterList = assignedAllList.filter( ( item ) => !item?.storeName );
|
|
4247
|
+
list = [ ...list, ...clusterList ];
|
|
4225
4248
|
} else {
|
|
4226
|
-
list =
|
|
4249
|
+
list = assignedAllList.map( ( item ) => item.userName );
|
|
4250
|
+
let teamList = assignedAllList.filter( ( item ) => !item?.userName );
|
|
4251
|
+
list = [ ...list, ...teamList ];
|
|
4227
4252
|
}
|
|
4228
4253
|
if ( !list.includes( item ) ) {
|
|
4229
4254
|
return item;
|
|
4230
4255
|
}
|
|
4231
4256
|
} );
|
|
4257
|
+
if ( getAssignedDetails.length ) {
|
|
4258
|
+
removed = { user: oldCoverage == 'user' ? removed : [], store: oldCoverage == 'store' ? removed : [] };
|
|
4259
|
+
} else {
|
|
4260
|
+
removed = { user: [], store: [] };
|
|
4261
|
+
}
|
|
4232
4262
|
|
|
4233
4263
|
await assignedService.deleteMany( { checkListId: req.body.checkListId } );
|
|
4234
4264
|
let assignedUserList = [];
|
|
@@ -4247,7 +4277,7 @@ export async function updateAssign( req, res ) {
|
|
|
4247
4277
|
},
|
|
4248
4278
|
];
|
|
4249
4279
|
let assignUserDetails = await userService.aggregate( query );
|
|
4250
|
-
|
|
4280
|
+
for ( let assign of req.body.assignedList ) {
|
|
4251
4281
|
let userDetails = assignUserDetails.find( ( ele ) => ele.email.toLowerCase() == assign.userEmail.toLowerCase() );
|
|
4252
4282
|
if ( !userDetails ) {
|
|
4253
4283
|
let userData = {
|
|
@@ -4257,7 +4287,7 @@ export async function updateAssign( req, res ) {
|
|
|
4257
4287
|
clientId: req.body.clientId,
|
|
4258
4288
|
};
|
|
4259
4289
|
userDetails = await createUser( userData );
|
|
4260
|
-
userDetails
|
|
4290
|
+
assignUserDetails.push( userDetails );
|
|
4261
4291
|
}
|
|
4262
4292
|
let data = {
|
|
4263
4293
|
...assign,
|
|
@@ -4271,7 +4301,7 @@ export async function updateAssign( req, res ) {
|
|
|
4271
4301
|
};
|
|
4272
4302
|
delete data._id;
|
|
4273
4303
|
assignedUserList.push( data );
|
|
4274
|
-
}
|
|
4304
|
+
}
|
|
4275
4305
|
let assignGroupDetails = [];
|
|
4276
4306
|
if ( req.body.coverage == 'store' ) {
|
|
4277
4307
|
assignGroupDetails = await clusterServices.findcluster( { _id: { $in: req.body.assignedGroup } } );
|
|
@@ -4299,3 +4329,225 @@ export async function updateAssign( req, res ) {
|
|
|
4299
4329
|
return res.sendError( e, 500 );
|
|
4300
4330
|
}
|
|
4301
4331
|
}
|
|
4332
|
+
|
|
4333
|
+
export async function updateAiConfigure( req, res ) {
|
|
4334
|
+
try {
|
|
4335
|
+
if ( !req.body.storeList.length && req.body.publish ) {
|
|
4336
|
+
return res.sendError( 'Please assign a store', 400 );
|
|
4337
|
+
}
|
|
4338
|
+
if ( !req.body.id && !req.body.type ) {
|
|
4339
|
+
return res.sendError( 'Type/Id is required', 400 );
|
|
4340
|
+
}
|
|
4341
|
+
if ( req.body.aiConfig?.assignConfig && req.body.aiConfig?.assignConfig == 'global' && !req.body?.aiConfig?.events?.length ) {
|
|
4342
|
+
return res.sendError( 'Event is required', 400 );
|
|
4343
|
+
}
|
|
4344
|
+
let query;
|
|
4345
|
+
query = req.body.type ? { checkListType: req.body.type, client_id: { $exists: false } } : { _id: req.body.id, client_id: req.body.clientId };
|
|
4346
|
+
let aiChecklistDetails = await checklistService.findOne( query );
|
|
4347
|
+
if ( !aiChecklistDetails ) {
|
|
4348
|
+
return res.sendError( 'No data found', 204 );
|
|
4349
|
+
}
|
|
4350
|
+
let details = {
|
|
4351
|
+
checkListName: aiChecklistDetails.checkListName,
|
|
4352
|
+
checkListDescription: aiChecklistDetails.checkListDescription,
|
|
4353
|
+
client_id: req.body.clientId,
|
|
4354
|
+
publish: req.body.publish,
|
|
4355
|
+
aiConfig: req.body.aiConfig,
|
|
4356
|
+
...( !req.body?.id ) ? { createdBy: req.user._id, createdByName: req.user.userName } : {},
|
|
4357
|
+
questionCount: 0,
|
|
4358
|
+
storeCount: req.body.storeList.length,
|
|
4359
|
+
type: 'checklist',
|
|
4360
|
+
checkListType: aiChecklistDetails.checkListType,
|
|
4361
|
+
schedule: 'daily',
|
|
4362
|
+
...( req.body.publish ) ? { publishDate: new Date() } :{},
|
|
4363
|
+
approver: req.body?.approver || [],
|
|
4364
|
+
scheduleRepeatedDay: [ '01' ],
|
|
4365
|
+
scheduleStartTime: '06:00 AM',
|
|
4366
|
+
scheduleEndTime: '11:59 PM',
|
|
4367
|
+
enableNewDeployedStore: req.body.enableNewDeployedStore,
|
|
4368
|
+
checkListNumber: aiChecklistDetails?.checkListNumber || 1,
|
|
4369
|
+
};
|
|
4370
|
+
let aiResponse = await checklistService.updateOne( { checkListType: aiChecklistDetails.checkListType, client_id: req.body.clientId }, details );
|
|
4371
|
+
let checklistId = req.body?.id || aiResponse?.upsertedId;
|
|
4372
|
+
if ( req.body?.approver ) {
|
|
4373
|
+
let data = [];
|
|
4374
|
+
let existEmail = await traxApprover.find( { checkListId: checklistId, isDeleted: false } );
|
|
4375
|
+
let mailList = existEmail.map( ( item ) => item.userEmail );
|
|
4376
|
+
existEmail = req.body?.approver.filter( ( item ) => mailList.includes( item.value ) ).map( ( item ) => item.value );
|
|
4377
|
+
let userMailList = req.body?.approver.map( ( ele ) => ele.value );
|
|
4378
|
+
req.body?.approver.forEach( ( ele ) => {
|
|
4379
|
+
if ( !existEmail.includes( ele.value ) ) {
|
|
4380
|
+
data.push( {
|
|
4381
|
+
userEmail: ele.value,
|
|
4382
|
+
checkListId: checklistId,
|
|
4383
|
+
type: 'checklist',
|
|
4384
|
+
checkListName: aiChecklistDetails.checkListName,
|
|
4385
|
+
client_id: req.body.clientId,
|
|
4386
|
+
} );
|
|
4387
|
+
}
|
|
4388
|
+
} );
|
|
4389
|
+
|
|
4390
|
+
await traxApprover.updateMany( { checkListId: checklistId, userEmail: { $nin: userMailList } }, { isDeleted: true } );
|
|
4391
|
+
if ( data.length ) {
|
|
4392
|
+
await traxApprover.insertMany( data );
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
if ( req.body.storeList ) {
|
|
4396
|
+
let storeData = [];
|
|
4397
|
+
req.body.storeList.forEach( ( ele ) => {
|
|
4398
|
+
let eventTime = [];
|
|
4399
|
+
Object.keys( ele ).forEach( ( key ) => {
|
|
4400
|
+
let keyValue ={};
|
|
4401
|
+
if ( req.body.aiConfig?.assignConfig && req.body.aiConfig?.assignConfig == 'store' && key.includes( 'startTime' ) ) {
|
|
4402
|
+
let num = key.slice( -1 );
|
|
4403
|
+
if ( ele[key] && ele[`configTime${num}`] ) {
|
|
4404
|
+
keyValue['time'] = ele[key];
|
|
4405
|
+
keyValue['duration'] = ele[`configTime${num}`];
|
|
4406
|
+
eventTime.push( keyValue );
|
|
4407
|
+
}
|
|
4408
|
+
}
|
|
4409
|
+
} );
|
|
4410
|
+
if ( req.body.aiConfig?.assignConfig && req.body.aiConfig?.assignConfig == 'global' ) {
|
|
4411
|
+
req.body.aiConfig.events.forEach( ( event ) => {
|
|
4412
|
+
if ( event.time.split( ':' ).length <= 2 ) {
|
|
4413
|
+
event.time = event.time + ':00';
|
|
4414
|
+
}
|
|
4415
|
+
} );
|
|
4416
|
+
eventTime = req.body.aiConfig.events;
|
|
4417
|
+
}
|
|
4418
|
+
storeData.push( {
|
|
4419
|
+
storeName: ele.storeName,
|
|
4420
|
+
...( req.body.aiConfig?.assignConfig ) ? { events: eventTime } : { events: [] },
|
|
4421
|
+
checkListId: checklistId,
|
|
4422
|
+
client_id: req.body.clientId,
|
|
4423
|
+
checkListName: aiChecklistDetails.checkListName,
|
|
4424
|
+
store_id: ele.storeId,
|
|
4425
|
+
assignId: ele._id,
|
|
4426
|
+
} );
|
|
4427
|
+
} );
|
|
4428
|
+
await assignedService.deleteMany( { checkListId: checklistId } );
|
|
4429
|
+
await assignedService.insertMany( storeData );
|
|
4430
|
+
if ( req.body.publish ) {
|
|
4431
|
+
let processedData = {
|
|
4432
|
+
client_id: req.body.clientId,
|
|
4433
|
+
date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
4434
|
+
date_string: dayjs().format( 'YYYY-MM-DD' ),
|
|
4435
|
+
sourceCheckList_id: checklistId,
|
|
4436
|
+
checkListName: aiChecklistDetails.checkListName,
|
|
4437
|
+
checkListDescription: aiChecklistDetails.checkListDescription,
|
|
4438
|
+
scheduleStartTime: '06:00 AM',
|
|
4439
|
+
scheduleEndTime: '11:59 PM',
|
|
4440
|
+
scheduleStartTime_iso: dayjs.utc( '06:00 AM', 'hh:mm A' ).format(),
|
|
4441
|
+
scheduleEndTime_iso: dayjs.utc( '11:59 PM', 'hh:mm A' ).format(),
|
|
4442
|
+
allowedOverTime: false,
|
|
4443
|
+
allowedStoreLocation: false,
|
|
4444
|
+
createdBy: req.user._id,
|
|
4445
|
+
createdByName: req.user.userName,
|
|
4446
|
+
questionAnswers: [],
|
|
4447
|
+
isdeleted: false,
|
|
4448
|
+
questionCount: 0,
|
|
4449
|
+
storeCount: req.body.storeList.length,
|
|
4450
|
+
publishDate: details?.publishDate,
|
|
4451
|
+
locationCount: 1,
|
|
4452
|
+
checkListType: aiChecklistDetails.checkListType,
|
|
4453
|
+
scheduleRepeatedType: 'daily',
|
|
4454
|
+
aiStoreList: storeData.length? storeData.map( ( store ) => {
|
|
4455
|
+
return { storeName: store.storeName, events: store.events, storeId: store.store_id };
|
|
4456
|
+
} ) : [],
|
|
4457
|
+
aiConfig: req.body.aiConfig,
|
|
4458
|
+
approver: req.body?.approver || [],
|
|
4459
|
+
};
|
|
4460
|
+
let configResponse = await processedchecklistConfig.updateOne( { date_string: dayjs().format( 'YYYY-MM-DD' ), sourceCheckList_id: checklistId, checkListType: aiChecklistDetails.checkListType }, processedData );
|
|
4461
|
+
let data = {
|
|
4462
|
+
...( configResponse?.upsertedId ) ? { checkListId: configResponse?.upsertedId } : {},
|
|
4463
|
+
checkListName: aiChecklistDetails.checkListName,
|
|
4464
|
+
checkListDescription: aiChecklistDetails.checkListDescription,
|
|
4465
|
+
date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
4466
|
+
date_string: dayjs().format( 'YYYY-MM-DD' ),
|
|
4467
|
+
allowedOverTime: false,
|
|
4468
|
+
allowedStoreLocation: false,
|
|
4469
|
+
scheduleStartTime: '06:00 AM',
|
|
4470
|
+
scheduleStartTime_iso: dayjs.utc( '06:00 AM', 'hh:mm A' ).format(),
|
|
4471
|
+
scheduleEndTime: '11:59 PM',
|
|
4472
|
+
scheduleEndTime_iso: dayjs.utc( '11:59 PM', 'hh:mm A' ).format(),
|
|
4473
|
+
createdBy: req.user._id,
|
|
4474
|
+
createdByName: req.user.userName,
|
|
4475
|
+
sourceCheckList_id: checklistId,
|
|
4476
|
+
checkListType: aiChecklistDetails.checkListType,
|
|
4477
|
+
storeCount: storeData.length,
|
|
4478
|
+
questionCount: 0,
|
|
4479
|
+
publishDate: new Date(),
|
|
4480
|
+
locationCount: 0,
|
|
4481
|
+
scheduleRepeatedType: 'daily',
|
|
4482
|
+
client_id: req.body.clientId,
|
|
4483
|
+
aiStoreList: storeData?.length ? storeData.map( ( store ) => store.store_id ) : [],
|
|
4484
|
+
approvalEnable: req.body?.approver.length ? true : false,
|
|
4485
|
+
};
|
|
4486
|
+
await processedchecklist.updateOne( { date_string: dayjs().format( 'YYYY-MM-DD' ), sourceCheckList_id: checklistId, checkListType: aiChecklistDetails.checkListType }, data );
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
return res.sendSuccess( 'Checklist updated successfully' );
|
|
4490
|
+
} catch ( e ) {
|
|
4491
|
+
logger.error( { functionName: 'updateAiConfigure', error: e } );
|
|
4492
|
+
return res.sendError( e, 500 );
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4495
|
+
|
|
4496
|
+
|
|
4497
|
+
export async function getAiDetails( req, res ) {
|
|
4498
|
+
try {
|
|
4499
|
+
let storeList = [];
|
|
4500
|
+
if ( !req.query.id && !req.query.type ) {
|
|
4501
|
+
return res.sendError( 'Type/Id is required', 400 );
|
|
4502
|
+
}
|
|
4503
|
+
let query = req.query.type ? { checkListType: req.query.type, client_id: { $exists: false } } : { _id: req.query.id, client_id: req.query.clientId };
|
|
4504
|
+
let checklistDetails = await checklistService.findOne( query );
|
|
4505
|
+
if ( !checklistDetails ) {
|
|
4506
|
+
return res.sendError( 'No data found', 204 );
|
|
4507
|
+
}
|
|
4508
|
+
let clientDetails = await clientService.findOne( { clientId: req.query.clientId }, { 'planDetails.product': 1 } );
|
|
4509
|
+
if ( !clientDetails ) {
|
|
4510
|
+
return res.sendError( 'No data found', 204 );
|
|
4511
|
+
}
|
|
4512
|
+
if ( req.query?.id ) {
|
|
4513
|
+
storeList = await assignedService.find( { checkListId: req.query?.id } );
|
|
4514
|
+
let data = [];
|
|
4515
|
+
await Promise.all( ( storeList.map( async ( ele ) => {
|
|
4516
|
+
let element = {};
|
|
4517
|
+
element['storeName'] = ele.storeName,
|
|
4518
|
+
element['storeId'] = ele.store_id;
|
|
4519
|
+
element['_id'] = ele.assignId;
|
|
4520
|
+
let getStoreDetails = await storeService.findOne( { storeId: ele.store_id, status: 'active', clientId: req.query.clientId } );
|
|
4521
|
+
if ( getStoreDetails ) {
|
|
4522
|
+
element['openTime'] = getStoreDetails?.storeProfile?.open;
|
|
4523
|
+
element['closeTime'] = getStoreDetails?.storeProfile?.close;
|
|
4524
|
+
}
|
|
4525
|
+
if ( [ 'cleaning', 'scrum' ].includes( checklistDetails.checkListType ) && checklistDetails?.aiConfig?.assignConfig == 'store' ) {
|
|
4526
|
+
ele.events.forEach( ( event, index ) => {
|
|
4527
|
+
element[`startTime${index+1}`] = event.time;
|
|
4528
|
+
element[`configTime${index+1}`] = event.duration;
|
|
4529
|
+
} );
|
|
4530
|
+
}
|
|
4531
|
+
data.push( element );
|
|
4532
|
+
} ) ) );
|
|
4533
|
+
storeList = data;
|
|
4534
|
+
}
|
|
4535
|
+
|
|
4536
|
+
let response = {
|
|
4537
|
+
checkListName: checklistDetails?.checkListName,
|
|
4538
|
+
checkListDescription: checklistDetails?.checkListDescription,
|
|
4539
|
+
publish: checklistDetails?.publish,
|
|
4540
|
+
aiConfig: checklistDetails?.aiConfig,
|
|
4541
|
+
storeList: storeList,
|
|
4542
|
+
approver: checklistDetails?.approver,
|
|
4543
|
+
storeCount: checklistDetails?.storeCount,
|
|
4544
|
+
...( checklistDetails?.client_id ) ? { clientId: checklistDetails?.client_id } :{},
|
|
4545
|
+
enableNewDeployedStore: checklistDetails?.enableNewDeployedStore,
|
|
4546
|
+
product: clientDetails?.planDetails?.product.map( ( product ) => product.productName ),
|
|
4547
|
+
};
|
|
4548
|
+
return res.sendSuccess( response );
|
|
4549
|
+
} catch ( e ) {
|
|
4550
|
+
logger.error( { functionName: getAiDetails, error: e } );
|
|
4551
|
+
return res.sendError( e, 500 );
|
|
4552
|
+
}
|
|
4553
|
+
}
|