tango-app-api-trax 3.4.1-alpha-16 → 3.4.1-alpha-17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1127,7 +1127,7 @@ export async function pushNotification( req, res ) {
|
|
|
1127
1127
|
const description = `The ${data.checklistName} checklist is due. Complete it within ${data.time} minutes to avoid compliance.`;
|
|
1128
1128
|
const fcmToken = item.token;
|
|
1129
1129
|
try {
|
|
1130
|
-
await sendPushNotification( title, description, fcmToken );
|
|
1130
|
+
await sendPushNotification( title, description, {}, fcmToken );
|
|
1131
1131
|
} catch ( e ) {
|
|
1132
1132
|
logger.error( {
|
|
1133
1133
|
message: 'push notification',
|
|
@@ -1543,7 +1543,7 @@ export async function taskPushNotification( req, res ) {
|
|
|
1543
1543
|
|
|
1544
1544
|
const fcmToken = item.token;
|
|
1545
1545
|
try {
|
|
1546
|
-
await sendPushNotification( title, description, fcmToken );
|
|
1546
|
+
await sendPushNotification( title, description, {}, fcmToken );
|
|
1547
1547
|
} catch ( e ) {
|
|
1548
1548
|
logger.error( {
|
|
1549
1549
|
message: 'push notification',
|
|
@@ -1612,7 +1612,7 @@ export async function internalSendPushNotification( req, res ) {
|
|
|
1612
1612
|
// return res.sendError( 'Token not found', 400 );
|
|
1613
1613
|
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1614
1614
|
}
|
|
1615
|
-
let responseData = await sendPushNotification( requestData.title, requestData.description, fcmToken );
|
|
1615
|
+
let responseData = await sendPushNotification( requestData.title, requestData.description, {}, fcmToken );
|
|
1616
1616
|
// console.log( 'responseData =>', responseData );
|
|
1617
1617
|
if ( responseData ) {
|
|
1618
1618
|
return res.sendSuccess( 'Notification Send Successfully' );
|
|
@@ -90,7 +90,7 @@ export async function storeListv1( req, res ) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
export async function
|
|
93
|
+
export async function startChecklistv1( req, res ) {
|
|
94
94
|
try {
|
|
95
95
|
let requestData = req.body;
|
|
96
96
|
let findQuery = [];
|
|
@@ -326,6 +326,189 @@ export async function startChecklist( req, res ) {
|
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
export async function startChecklist( req, res ) {
|
|
330
|
+
try {
|
|
331
|
+
let requestData = req.body;
|
|
332
|
+
let findQuery = [];
|
|
333
|
+
findQuery.push( {
|
|
334
|
+
$match: {
|
|
335
|
+
$and: [
|
|
336
|
+
{ _id: new ObjectId( requestData.processedcheckListId ) },
|
|
337
|
+
{ userId: req.user._id },
|
|
338
|
+
{ date_string: requestData.date },
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
} );
|
|
342
|
+
|
|
343
|
+
let getBeforeChecklist = await processedchecklist.aggregate( findQuery );
|
|
344
|
+
if ( !getBeforeChecklist.length ) {
|
|
345
|
+
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if ( getBeforeChecklist[0].checklistStatus != 'open' ) {
|
|
349
|
+
return res.sendError( 'already check list started', 400 );
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName || ''}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
|
|
353
|
+
let PCLQusestion = await PCLconfig.findOne( { _id: new ObjectId( getBeforeChecklist[0].checkListId ) } );
|
|
354
|
+
let updateQuery = {};
|
|
355
|
+
updateQuery._id = new ObjectId( requestData.processedcheckListId );
|
|
356
|
+
updateQuery.userId = req.user._id;
|
|
357
|
+
updateQuery.date_string = requestData.date;
|
|
358
|
+
|
|
359
|
+
if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
|
|
360
|
+
await PCLQusestion.questionAnswers.forEach( ( section ) => {
|
|
361
|
+
section.questions.forEach( ( question ) => {
|
|
362
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
363
|
+
let Multianswer = [];
|
|
364
|
+
if ( question.answers.length > 0 ) {
|
|
365
|
+
question.answers.forEach( ( answer, ansIndex ) => {
|
|
366
|
+
Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
|
|
367
|
+
answer.index = ansIndex;
|
|
368
|
+
} );
|
|
369
|
+
question.Multianswer = Multianswer;
|
|
370
|
+
}
|
|
371
|
+
} else if ( question.answerType == 'multipleImage' ) {
|
|
372
|
+
let Multianswer = [];
|
|
373
|
+
if ( question.answers.length > 0 ) {
|
|
374
|
+
question.answers.forEach( ( answer, ansIndex ) => {
|
|
375
|
+
Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
|
|
376
|
+
answer.index = ansIndex;
|
|
377
|
+
} );
|
|
378
|
+
question.Multianswer = Multianswer;
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
question.Multianswer = [];
|
|
382
|
+
}
|
|
383
|
+
} );
|
|
384
|
+
} );
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
let updateData = {};
|
|
388
|
+
let currentDateTime;
|
|
389
|
+
if ( getBeforeChecklist[0].storeName && getBeforeChecklist[0].storeName!='' ) {
|
|
390
|
+
let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeChecklist[0].storeName, $options: 'i' }, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
|
|
391
|
+
if ( storeTimeZone?.storeProfile?.timeZone ) {
|
|
392
|
+
currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
|
|
393
|
+
} else {
|
|
394
|
+
currentDateTime = dayjs();
|
|
395
|
+
}
|
|
396
|
+
} else {
|
|
397
|
+
currentDateTime = dayjs();
|
|
398
|
+
}
|
|
399
|
+
updateData.checklistStatus = 'inprogress';
|
|
400
|
+
updateData.startMobileTime = requestData?.currentTime;
|
|
401
|
+
updateData.questionAnswers = getBeforeChecklist[0]?.redoStatus ? getBeforeChecklist[0].questionAnswers : PCLQusestion.questionAnswers;
|
|
402
|
+
// const newDateTime = currentDateTime.add(5, 'hours').add(30, 'minutes');
|
|
403
|
+
// updateData.startTime_string = newDateTime.format('hh:mm A, DD MMM');
|
|
404
|
+
updateData.startTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
405
|
+
updateData.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
|
|
406
|
+
|
|
407
|
+
let updatechecklist = await processedchecklist.updateOne( updateQuery, updateData );
|
|
408
|
+
PCLQusestion.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
|
|
409
|
+
PCLQusestion.save();
|
|
410
|
+
if ( updatechecklist.modifiedCount > 0 ) {
|
|
411
|
+
findQuery.push( {
|
|
412
|
+
$project: {
|
|
413
|
+
checkListName: { $ifNull: [ '$checkListName', '' ] },
|
|
414
|
+
coverage: { $ifNull: [ '$coverage', '' ] },
|
|
415
|
+
client_id: { $ifNull: [ '$client_id', '' ] },
|
|
416
|
+
scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
|
|
417
|
+
scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
|
|
418
|
+
scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
|
|
419
|
+
scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
|
|
420
|
+
checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
|
|
421
|
+
checkListId: { $ifNull: [ '$checkListId', '' ] },
|
|
422
|
+
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
423
|
+
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
424
|
+
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
425
|
+
// allowedStoreLocation: { $ifNull: [ '$checallowedStoreLocationkListName', false ] },
|
|
426
|
+
allowedStoreLocation: {
|
|
427
|
+
$cond: {
|
|
428
|
+
if: { $eq: [ '$client_id', '11' ] },
|
|
429
|
+
then: false,
|
|
430
|
+
else: {
|
|
431
|
+
'$cond': {
|
|
432
|
+
'if': { '$eq': [ '$coverage', 'user' ] },
|
|
433
|
+
'then': false,
|
|
434
|
+
'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
|
|
440
|
+
redoStatus: { $ifNull: [ '$redoStatus', '' ] },
|
|
441
|
+
},
|
|
442
|
+
} );
|
|
443
|
+
let getupdatedchecklist = await processedchecklist.aggregate( findQuery );
|
|
444
|
+
let bucket = JSON.parse( process.env.BUCKET );
|
|
445
|
+
getupdatedchecklist[0].questionAnswers.forEach( ( section ) => {
|
|
446
|
+
section.questions.forEach( async ( question ) => {
|
|
447
|
+
if ( question.questionReferenceImage && question.questionReferenceImage!='' ) {
|
|
448
|
+
question.questionReferenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( question.questionReferenceImage ) } );
|
|
449
|
+
}
|
|
450
|
+
question.answers.forEach( async ( answer ) => {
|
|
451
|
+
if ( answer.referenceImage != '' ) {
|
|
452
|
+
answer.referenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( answer.referenceImage ) } );
|
|
453
|
+
}
|
|
454
|
+
} );
|
|
455
|
+
} );
|
|
456
|
+
} );
|
|
457
|
+
let logInsertData = {
|
|
458
|
+
store_id: getBeforeChecklist[0]?.store_id || '',
|
|
459
|
+
storeName: getBeforeChecklist[0]?.storeName || '',
|
|
460
|
+
action: 'started',
|
|
461
|
+
checklistId: getBeforeChecklist[0].sourceCheckList_id,
|
|
462
|
+
processedChecklistId: getBeforeChecklist[0]._id,
|
|
463
|
+
checkListName: getBeforeChecklist[0].checkListName,
|
|
464
|
+
type: getBeforeChecklist[0].checkListType,
|
|
465
|
+
client_id: req.user.clientId,
|
|
466
|
+
userEmail: getBeforeChecklist[0].userEmail || '',
|
|
467
|
+
userName: getBeforeChecklist[0].userName || '',
|
|
468
|
+
coverage: getBeforeChecklist[0].coverage || '',
|
|
469
|
+
};
|
|
470
|
+
await checklistLogs.create( logInsertData );
|
|
471
|
+
let getchecklist = getupdatedchecklist;
|
|
472
|
+
let questions = [];
|
|
473
|
+
function processQuestion( question, section, questions, nested=false ) {
|
|
474
|
+
let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
|
|
475
|
+
if ( findExists && nested ) {
|
|
476
|
+
let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
|
|
477
|
+
questions.splice( findIndex, 1 );
|
|
478
|
+
questions.push( question );
|
|
479
|
+
}
|
|
480
|
+
if ( !findExists ) {
|
|
481
|
+
questions.push( question );
|
|
482
|
+
for ( let answer of question.answers ) {
|
|
483
|
+
if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
484
|
+
let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
485
|
+
if ( linkedQuestion ) {
|
|
486
|
+
processQuestion( linkedQuestion, section, questions, true );
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
for ( let [ index, data ] of getchecklist.entries() ) {
|
|
493
|
+
for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
|
|
494
|
+
questions = [];
|
|
495
|
+
for ( let question of section.questions ) {
|
|
496
|
+
processQuestion( question, section, questions );
|
|
497
|
+
}
|
|
498
|
+
getchecklist[index].questionAnswers[secIndex].questions = questions;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return res.sendSuccess( getchecklist );
|
|
502
|
+
} else {
|
|
503
|
+
return res.sendError( 'something went wrong please try again', 500 );
|
|
504
|
+
}
|
|
505
|
+
} catch ( e ) {
|
|
506
|
+
console.log( 'e =>', e );
|
|
507
|
+
logger.error( { function: 'startChecklist', error: e, body: req.body } );
|
|
508
|
+
return res.sendError( e, 500 );
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
329
512
|
export async function startTask( req, res ) {
|
|
330
513
|
try {
|
|
331
514
|
const { body: requestData, user } = req;
|
|
@@ -717,18 +900,414 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
717
900
|
} );
|
|
718
901
|
const uniqueArray = Object.values( uniqueSections );
|
|
719
902
|
for ( let section of uniqueArray ) {
|
|
720
|
-
let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
|
|
903
|
+
let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
|
|
904
|
+
if ( CLQSection ) {
|
|
905
|
+
let newArray = [];
|
|
906
|
+
let qaAnswers = CLQSection.questions;
|
|
907
|
+
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
908
|
+
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
909
|
+
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
910
|
+
if ( requestSection[i].qno == qaAnswers[j].qno ) {
|
|
911
|
+
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
912
|
+
let qaans = qaAnswers[j].answers;
|
|
913
|
+
let yn = [];
|
|
914
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
915
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
916
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
917
|
+
if ( requestSection[i].validationAnswer ) {
|
|
918
|
+
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
919
|
+
if ( validateAns.length ) {
|
|
920
|
+
let splitImgUrl = validateAns.split( '/' );
|
|
921
|
+
if ( splitImgUrl.length > 1 ) {
|
|
922
|
+
splitImgUrl.splice( 0, 3 );
|
|
923
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
} else {
|
|
928
|
+
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
929
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
930
|
+
}
|
|
931
|
+
yn.push( qaans[k] );
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
let structure = {};
|
|
935
|
+
structure.qno = qaAnswers[j].qno;
|
|
936
|
+
structure.qname = qaAnswers[j].qname;
|
|
937
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
938
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
939
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
940
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
941
|
+
structure.remarks = requestSection[i].remarks;
|
|
942
|
+
structure.answers = qaAnswers[j].answers;
|
|
943
|
+
structure.userAnswer = yn;
|
|
944
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
945
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
946
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
947
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
948
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
949
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
950
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
951
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
952
|
+
structure.task = true;
|
|
953
|
+
}
|
|
954
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
955
|
+
structure.redo = false;
|
|
956
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
957
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
958
|
+
}
|
|
959
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
960
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
961
|
+
};
|
|
962
|
+
newArray.push( structure );
|
|
963
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
|
|
964
|
+
let qaans = qaAnswers[j].answers;
|
|
965
|
+
let ms = [];
|
|
966
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
967
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
968
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
969
|
+
if ( requestSection[i].validationAnswer ) {
|
|
970
|
+
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
971
|
+
if ( validationAnswer.length ) {
|
|
972
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
973
|
+
if ( splitImgUrl.length > 1 ) {
|
|
974
|
+
splitImgUrl.splice( 0, 3 );
|
|
975
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
} else {
|
|
980
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
981
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
982
|
+
}
|
|
983
|
+
ms.push( qaans[k] );
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
let structure = {};
|
|
987
|
+
structure.qno = qaAnswers[j].qno;
|
|
988
|
+
structure.qname = qaAnswers[j].qname;
|
|
989
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
990
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
991
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
992
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
993
|
+
structure.remarks = requestSection[i].remarks;
|
|
994
|
+
structure.answers = qaAnswers[j].answers;
|
|
995
|
+
structure.userAnswer = ms;
|
|
996
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
997
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
998
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
999
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1000
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1001
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1002
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1003
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1004
|
+
structure.task = true;
|
|
1005
|
+
}
|
|
1006
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1007
|
+
structure.redo = false;
|
|
1008
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1009
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1010
|
+
}
|
|
1011
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1012
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1013
|
+
};
|
|
1014
|
+
newArray.push( structure );
|
|
1015
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
|
|
1016
|
+
let qaans = qaAnswers[j].answers;
|
|
1017
|
+
let mcmo = [];
|
|
1018
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1019
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1020
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1021
|
+
if ( separatedArray[s].answer == qaans[k].answer ) {
|
|
1022
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1023
|
+
if ( separatedArray[s].validationAnswer ) {
|
|
1024
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1025
|
+
if ( validationAnswer.length ) {
|
|
1026
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1027
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1028
|
+
splitImgUrl.splice( 0, 3 );
|
|
1029
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
} else {
|
|
1034
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1035
|
+
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
mcmo.push( qaans[k] );
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
let structure = {};
|
|
1043
|
+
structure.qno = qaAnswers[j].qno;
|
|
1044
|
+
structure.qname = qaAnswers[j].qname;
|
|
1045
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1046
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1047
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1048
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1049
|
+
structure.remarks = requestSection[i].remarks;
|
|
1050
|
+
structure.answers = qaAnswers[j].answers;
|
|
1051
|
+
structure.userAnswer = mcmo;
|
|
1052
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1053
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1054
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1055
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1056
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1057
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1058
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1059
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1060
|
+
structure.task = true;
|
|
1061
|
+
}
|
|
1062
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1063
|
+
structure.redo = false;
|
|
1064
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1065
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1066
|
+
}
|
|
1067
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1068
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1069
|
+
};
|
|
1070
|
+
newArray.push( structure );
|
|
1071
|
+
} else if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
1072
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1073
|
+
let mcmi = [];
|
|
1074
|
+
// for (let k = 0; k < qaans.length; k++) {
|
|
1075
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1076
|
+
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1077
|
+
let newAnswer = {};
|
|
1078
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1079
|
+
if ( validationAnswer.length ) {
|
|
1080
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1081
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1082
|
+
splitImgUrl.splice( 0, 3 );
|
|
1083
|
+
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
newAnswer.answeroptionNumber = 0;
|
|
1088
|
+
newAnswer.sopFlag = false;
|
|
1089
|
+
newAnswer.validation = false;
|
|
1090
|
+
newAnswer.validationType = '';
|
|
1091
|
+
newAnswer.referenceImage = '';
|
|
1092
|
+
newAnswer.allowUploadfromGallery = false;
|
|
1093
|
+
newAnswer.runAI = false;
|
|
1094
|
+
newAnswer.descriptivetype = '';
|
|
1095
|
+
newAnswer.showLinked = false;
|
|
1096
|
+
newAnswer.linkedQuestion = 0;
|
|
1097
|
+
newAnswer.nestedQuestion = [];
|
|
1098
|
+
newAnswer.index = s;
|
|
1099
|
+
mcmi.push( newAnswer );
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
// }
|
|
1103
|
+
let structure = {};
|
|
1104
|
+
structure.qno = qaAnswers[j].qno;
|
|
1105
|
+
structure.qname = qaAnswers[j].qname;
|
|
1106
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1107
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1108
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1109
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1110
|
+
structure.remarks = requestSection[i].remarks;
|
|
1111
|
+
structure.answers = qaAnswers[j].answers;
|
|
1112
|
+
structure.userAnswer = mcmi;
|
|
1113
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1114
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1115
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1116
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1117
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1118
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1119
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1120
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1121
|
+
structure.task = true;
|
|
1122
|
+
}
|
|
1123
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1124
|
+
structure.redo = false;
|
|
1125
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1126
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1127
|
+
}
|
|
1128
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1129
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1130
|
+
};
|
|
1131
|
+
newArray.push( structure );
|
|
1132
|
+
} else {
|
|
1133
|
+
let des = [];
|
|
1134
|
+
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1135
|
+
let validationAnswer = '';
|
|
1136
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1137
|
+
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1138
|
+
}
|
|
1139
|
+
if ( validationAnswer.length ) {
|
|
1140
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1141
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1142
|
+
splitImgUrl.splice( 0, 3 );
|
|
1143
|
+
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
let ansstructure = {
|
|
1147
|
+
answer: requestSection[i].answer,
|
|
1148
|
+
answeroptionNumber: 1,
|
|
1149
|
+
sopFlag: false,
|
|
1150
|
+
validation: false,
|
|
1151
|
+
validationType: '',
|
|
1152
|
+
validationAnswer: '',
|
|
1153
|
+
referenceImage: qaAnswers[j].answers[0].referenceImage,
|
|
1154
|
+
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1155
|
+
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1156
|
+
};
|
|
1157
|
+
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1158
|
+
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1159
|
+
}
|
|
1160
|
+
des.push( ansstructure );
|
|
1161
|
+
}
|
|
1162
|
+
let structure = {};
|
|
1163
|
+
structure.qno = qaAnswers[j].qno;
|
|
1164
|
+
structure.qname = qaAnswers[j].qname;
|
|
1165
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1166
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1167
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1168
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1169
|
+
structure.remarks = requestSection[i].remarks;
|
|
1170
|
+
structure.answers = qaAnswers[j].answers;
|
|
1171
|
+
structure.userAnswer = des;
|
|
1172
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1173
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1174
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1175
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1176
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1177
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1178
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1179
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1180
|
+
structure.task = true;
|
|
1181
|
+
}
|
|
1182
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1183
|
+
structure.redo = false;
|
|
1184
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1185
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1186
|
+
}
|
|
1187
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1188
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1189
|
+
};
|
|
1190
|
+
newArray.push( structure );
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
let sectionData = {
|
|
1196
|
+
'section_id': section.id,
|
|
1197
|
+
'sectionName': section.name,
|
|
1198
|
+
'questions': newArray,
|
|
1199
|
+
};
|
|
1200
|
+
sectionFormat.push( sectionData );
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
requestData.questionAnswers = sectionFormat;
|
|
1206
|
+
next();
|
|
1207
|
+
} catch ( error ) {
|
|
1208
|
+
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
1209
|
+
return res.sendError( error, 500 );
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next ) {
|
|
1214
|
+
try {
|
|
1215
|
+
let requestData = req.body;
|
|
1216
|
+
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
1217
|
+
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
1218
|
+
let reqAnswers = requestData.questionAnswers;
|
|
1219
|
+
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1220
|
+
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1221
|
+
|
|
1222
|
+
if ( requestData.submittype == 'submit' ) {
|
|
1223
|
+
reqAnswers.forEach( ( reqA ) => {
|
|
1224
|
+
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( reqA?.answerType ) ) {
|
|
1225
|
+
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
1226
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
} );
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
if ( requestData?.editSubmit && requestData?.editSubmit == 'true' ) {
|
|
1233
|
+
let sampleData = reqAnswers[0];
|
|
1234
|
+
CLQAnswers.forEach( ( section ) => {
|
|
1235
|
+
let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
|
|
1236
|
+
if ( requestSection.length ) {
|
|
1237
|
+
requestSection.forEach( ( item ) => item.section_id = section.section_id );
|
|
1238
|
+
section.questions.forEach( ( question ) => {
|
|
1239
|
+
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
1240
|
+
if ( !sectionQuestion.length ) {
|
|
1241
|
+
let data = { ...requestSection[0] };
|
|
1242
|
+
data.answerType = question.answerType;
|
|
1243
|
+
data.qno = question.qno;
|
|
1244
|
+
data.qname = question.qname;
|
|
1245
|
+
data.oldQname = question?.oldQname || question.qname;
|
|
1246
|
+
data.answer = 'null';
|
|
1247
|
+
data.remarks = '';
|
|
1248
|
+
data.validationAnswer = '';
|
|
1249
|
+
data.Multianswer = [];
|
|
1250
|
+
data.linkType = question.linkType;
|
|
1251
|
+
data.linkquestionenabled = question.linkType;
|
|
1252
|
+
data.linkedQuestion = null;
|
|
1253
|
+
data.showLinked = null;
|
|
1254
|
+
data.parentanswer = '';
|
|
1255
|
+
data.dateRangeType = false;
|
|
1256
|
+
reqAnswers.push( data );
|
|
1257
|
+
}
|
|
1258
|
+
} );
|
|
1259
|
+
} else {
|
|
1260
|
+
section.questions.forEach( ( ele ) => {
|
|
1261
|
+
let data = { ...sampleData };
|
|
1262
|
+
data.section_id = section.section_id;
|
|
1263
|
+
data.sectionName = section.sectionName;
|
|
1264
|
+
data.answerType = ele.answerType;
|
|
1265
|
+
data.qno = ele.qno;
|
|
1266
|
+
data.qname = ele.qname;
|
|
1267
|
+
data.oldQname = ele?.oldQname || ele.qname;
|
|
1268
|
+
data.answer = 'null';
|
|
1269
|
+
data.remarks = '';
|
|
1270
|
+
data.validationAnswer = '';
|
|
1271
|
+
data.Multianswer = [];
|
|
1272
|
+
data.linkType = ele.linkType;
|
|
1273
|
+
data.linkquestionenabled = ele.linkType;
|
|
1274
|
+
data.linkedQuestion = null;
|
|
1275
|
+
data.showLinked = null;
|
|
1276
|
+
data.parentanswer = '';
|
|
1277
|
+
data.dateRangeType = false;
|
|
1278
|
+
reqAnswers.push( data );
|
|
1279
|
+
} );
|
|
1280
|
+
}
|
|
1281
|
+
} );
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
let sectionFormat = [];
|
|
1285
|
+
let uniqueSections = {};
|
|
1286
|
+
reqAnswers.forEach( ( item ) => {
|
|
1287
|
+
const key = `${item.section_id}-${item.sectionName}`;
|
|
1288
|
+
if ( !uniqueSections[key] ) {
|
|
1289
|
+
uniqueSections[key] = { id: item.section_id, name: item.sectionName };
|
|
1290
|
+
}
|
|
1291
|
+
} );
|
|
1292
|
+
const uniqueArray = Object.values( uniqueSections );
|
|
1293
|
+
for ( let section of uniqueArray ) {
|
|
1294
|
+
let CLQSection = CLQAnswers.find( ( item ) => item.section_id.toString() == section.id.toString() );
|
|
721
1295
|
if ( CLQSection ) {
|
|
722
1296
|
let newArray = [];
|
|
723
1297
|
let qaAnswers = CLQSection.questions;
|
|
724
1298
|
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
725
1299
|
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
726
1300
|
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
727
|
-
if ( requestSection[i].
|
|
1301
|
+
if ( ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) && ( !qaAnswers[j].uniqueNo || ( qaAnswers[j].uniqueNo && requestSection[i].uniqueNo == qaAnswers[j].uniqueNo ) ) ) {
|
|
728
1302
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
729
1303
|
let qaans = qaAnswers[j].answers;
|
|
730
1304
|
let yn = [];
|
|
731
1305
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1306
|
+
// let requestAnswer = typeof requestSection[i].questionAnswers == 'string' ? JSON.parse( requestSection[i].questionAnswers ) : requestSection[i].questionAnswers;
|
|
1307
|
+
// let findAnswer = requestAnswer.find( ( ele ) => ele.answer == qaans[k].answer && ele.);
|
|
1308
|
+
// if ( findAnswer ) {
|
|
1309
|
+
// qaans[k].nestedQuestion = typeof findAnswer.nestedQuestion == 'string' ? JSON.parse( findAnswer.nestedQuestion ) : findAnswer.nestedQuestion;
|
|
1310
|
+
// }
|
|
732
1311
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
733
1312
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
734
1313
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -742,7 +1321,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
742
1321
|
}
|
|
743
1322
|
}
|
|
744
1323
|
} else {
|
|
745
|
-
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1324
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
746
1325
|
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
747
1326
|
}
|
|
748
1327
|
yn.push( qaans[k] );
|
|
@@ -763,14 +1342,17 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
763
1342
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
764
1343
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
765
1344
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1345
|
+
structure.uniqueNo = requestSection[i].uniqueNo;
|
|
1346
|
+
// qaAnswers[j].nestedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
766
1347
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1348
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
767
1349
|
if ( qaAnswers[j]?.taskId ) {
|
|
768
1350
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
769
1351
|
structure.task = true;
|
|
770
1352
|
}
|
|
771
1353
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
772
1354
|
structure.redo = false;
|
|
773
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1355
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
774
1356
|
structure.redo = qaAnswers[j]?.redo;
|
|
775
1357
|
}
|
|
776
1358
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -781,6 +1363,11 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
781
1363
|
let qaans = qaAnswers[j].answers;
|
|
782
1364
|
let ms = [];
|
|
783
1365
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1366
|
+
// let requestAnswer = typeof requestSection[i].questionAnswers == 'string' ? JSON.parse( requestSection[i].questionAnswers ) : requestSection[i].questionAnswers;
|
|
1367
|
+
// let findAnswer= requestAnswer.find( ( ele ) => ele.answer == qaans[k].answer );
|
|
1368
|
+
// if ( findAnswer ) {
|
|
1369
|
+
// qaans[k].nestedQuestion = typeof findAnswer.nestedQuestion == 'string' ? JSON.parse( findAnswer.nestedQuestion ) : findAnswer.nestedQuestion;
|
|
1370
|
+
// }
|
|
784
1371
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
785
1372
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
786
1373
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -815,14 +1402,18 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
815
1402
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
816
1403
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
817
1404
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1405
|
+
structure.uniqueNo = requestSection[i].uniqueNo;
|
|
1406
|
+
// structure.uniqueqno = parseInt( requestSection[i]?.uniqueqno );
|
|
1407
|
+
// structure.nestedlinkedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
818
1408
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1409
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
819
1410
|
if ( qaAnswers[j]?.taskId ) {
|
|
820
1411
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
821
1412
|
structure.task = true;
|
|
822
1413
|
}
|
|
823
1414
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
824
1415
|
structure.redo = false;
|
|
825
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1416
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
826
1417
|
structure.redo = qaAnswers[j]?.redo;
|
|
827
1418
|
}
|
|
828
1419
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -871,14 +1462,18 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
871
1462
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
872
1463
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
873
1464
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1465
|
+
structure.uniqueNo = requestSection[i].uniqueNo;
|
|
874
1466
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1467
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1468
|
+
// structure.uniqueqno = parseInt( requestSection[i]?.uniqueqno );
|
|
1469
|
+
// structure.nestedlinkedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
875
1470
|
if ( qaAnswers[j]?.taskId ) {
|
|
876
1471
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
877
1472
|
structure.task = true;
|
|
878
1473
|
}
|
|
879
1474
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
880
1475
|
structure.redo = false;
|
|
881
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1476
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
882
1477
|
structure.redo = qaAnswers[j]?.redo;
|
|
883
1478
|
}
|
|
884
1479
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -932,14 +1527,18 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
932
1527
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
933
1528
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
934
1529
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1530
|
+
structure.uniqueNo = requestSection[i].uniqueNo;
|
|
1531
|
+
// structure.uniqueqno = parseInt( requestSection[i]?.uniqueqno );
|
|
1532
|
+
// structure.nestedlinkedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
935
1533
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1534
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
936
1535
|
if ( qaAnswers[j]?.taskId ) {
|
|
937
1536
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
938
1537
|
structure.task = true;
|
|
939
1538
|
}
|
|
940
1539
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
941
1540
|
structure.redo = false;
|
|
942
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1541
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
943
1542
|
structure.redo = qaAnswers[j]?.redo;
|
|
944
1543
|
}
|
|
945
1544
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -950,7 +1549,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
950
1549
|
let des = [];
|
|
951
1550
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
952
1551
|
let validationAnswer = '';
|
|
953
|
-
if ( requestSection[i].answer.
|
|
1552
|
+
if ( requestSection[i].answer.includes( 'https' ) ) {
|
|
954
1553
|
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
955
1554
|
}
|
|
956
1555
|
if ( validationAnswer.length ) {
|
|
@@ -991,14 +1590,18 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
991
1590
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
992
1591
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
993
1592
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1593
|
+
structure.uniqueNo = requestSection[i].uniqueNo;
|
|
1594
|
+
// structure.uniqueqno = parseInt( requestSection[i]?.uniqueqno );
|
|
1595
|
+
// structure.nestedlinkedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
994
1596
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1597
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
995
1598
|
if ( qaAnswers[j]?.taskId ) {
|
|
996
1599
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
997
1600
|
structure.task = true;
|
|
998
1601
|
}
|
|
999
1602
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1000
1603
|
structure.redo = false;
|
|
1001
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1604
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1002
1605
|
structure.redo = qaAnswers[j]?.redo;
|
|
1003
1606
|
}
|
|
1004
1607
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1020,6 +1623,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
1020
1623
|
|
|
1021
1624
|
|
|
1022
1625
|
requestData.questionAnswers = sectionFormat;
|
|
1626
|
+
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
1023
1627
|
next();
|
|
1024
1628
|
} catch ( error ) {
|
|
1025
1629
|
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
@@ -1115,16 +1719,11 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1115
1719
|
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
1116
1720
|
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
1117
1721
|
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1118
|
-
if (
|
|
1722
|
+
if ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) {
|
|
1119
1723
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1120
1724
|
let qaans = qaAnswers[j].answers;
|
|
1121
1725
|
let yn = [];
|
|
1122
1726
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1123
|
-
// let requestAnswer = typeof requestSection[i].questionAnswers == 'string' ? JSON.parse( requestSection[i].questionAnswers ) : requestSection[i].questionAnswers;
|
|
1124
|
-
// let findAnswer = requestAnswer.find( ( ele ) => ele.answer == qaans[k].answer && ele.);
|
|
1125
|
-
// if ( findAnswer ) {
|
|
1126
|
-
// qaans[k].nestedQuestion = typeof findAnswer.nestedQuestion == 'string' ? JSON.parse( findAnswer.nestedQuestion ) : findAnswer.nestedQuestion;
|
|
1127
|
-
// }
|
|
1128
1727
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1129
1728
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1130
1729
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -1159,8 +1758,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1159
1758
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1160
1759
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1161
1760
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1162
|
-
structure.uniqueNo = qaAnswers[j].uniqueNo;
|
|
1163
|
-
// qaAnswers[j].nestedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
1164
1761
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1165
1762
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1166
1763
|
if ( qaAnswers[j]?.taskId ) {
|
|
@@ -1180,11 +1777,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1180
1777
|
let qaans = qaAnswers[j].answers;
|
|
1181
1778
|
let ms = [];
|
|
1182
1779
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1183
|
-
// let requestAnswer = typeof requestSection[i].questionAnswers == 'string' ? JSON.parse( requestSection[i].questionAnswers ) : requestSection[i].questionAnswers;
|
|
1184
|
-
// let findAnswer= requestAnswer.find( ( ele ) => ele.answer == qaans[k].answer );
|
|
1185
|
-
// if ( findAnswer ) {
|
|
1186
|
-
// qaans[k].nestedQuestion = typeof findAnswer.nestedQuestion == 'string' ? JSON.parse( findAnswer.nestedQuestion ) : findAnswer.nestedQuestion;
|
|
1187
|
-
// }
|
|
1188
1780
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1189
1781
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1190
1782
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -1219,9 +1811,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1219
1811
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1220
1812
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1221
1813
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1222
|
-
structure.uniqueNo = qaAnswers[j].uniqueNo;
|
|
1223
|
-
// structure.uniqueqno = parseInt( requestSection[i]?.uniqueqno );
|
|
1224
|
-
// structure.nestedlinkedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
1225
1814
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1226
1815
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1227
1816
|
if ( qaAnswers[j]?.taskId ) {
|
|
@@ -1279,11 +1868,8 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1279
1868
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1280
1869
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1281
1870
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1282
|
-
structure.uniqueNo = qaAnswers[j].uniqueNo;
|
|
1283
1871
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1284
1872
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1285
|
-
// structure.uniqueqno = parseInt( requestSection[i]?.uniqueqno );
|
|
1286
|
-
// structure.nestedlinkedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
1287
1873
|
if ( qaAnswers[j]?.taskId ) {
|
|
1288
1874
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1289
1875
|
structure.task = true;
|
|
@@ -1344,9 +1930,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1344
1930
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1345
1931
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1346
1932
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1347
|
-
structure.uniqueNo = qaAnswers[j].uniqueNo;
|
|
1348
|
-
// structure.uniqueqno = parseInt( requestSection[i]?.uniqueqno );
|
|
1349
|
-
// structure.nestedlinkedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
1350
1933
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1351
1934
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1352
1935
|
if ( qaAnswers[j]?.taskId ) {
|
|
@@ -1366,7 +1949,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1366
1949
|
let des = [];
|
|
1367
1950
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1368
1951
|
let validationAnswer = '';
|
|
1369
|
-
if ( requestSection[i].answer.
|
|
1952
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1370
1953
|
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1371
1954
|
}
|
|
1372
1955
|
if ( validationAnswer.length ) {
|
|
@@ -1407,9 +1990,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1407
1990
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1408
1991
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1409
1992
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1410
|
-
structure.uniqueNo = qaAnswers[j].uniqueNo;
|
|
1411
|
-
// structure.uniqueqno = parseInt( requestSection[i]?.uniqueqno );
|
|
1412
|
-
// structure.nestedlinkedQuestion = requestSection[i]?.nestedlinkedQuestion;
|
|
1413
1993
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1414
1994
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1415
1995
|
if ( qaAnswers[j]?.taskId ) {
|
|
@@ -2589,7 +3169,7 @@ export async function checklistv1( req, res ) {
|
|
|
2589
3169
|
}
|
|
2590
3170
|
}
|
|
2591
3171
|
|
|
2592
|
-
export async function
|
|
3172
|
+
export async function questionListv1( req, res ) {
|
|
2593
3173
|
try {
|
|
2594
3174
|
let requestData = req.query;
|
|
2595
3175
|
if ( !requestData.processedcheckListId ) {
|
|
@@ -2800,13 +3380,16 @@ export async function questionList( req, res ) {
|
|
|
2800
3380
|
answer.nestedQuestion[qidx] = randomNo;
|
|
2801
3381
|
}
|
|
2802
3382
|
} );
|
|
3383
|
+
console.log( nesedQuestion );
|
|
2803
3384
|
nesedQuestion.forEach( ( ele ) => {
|
|
2804
3385
|
let nestedLinkqn = [];
|
|
2805
3386
|
ele.answers.forEach( ( ans ) => {
|
|
2806
3387
|
if ( ans.linkedQuestion ) {
|
|
2807
3388
|
ans.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( ans.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( ans.nestedQuestion ) );
|
|
2808
3389
|
ans.nestedQuestion.forEach( ( nested, idx ) => {
|
|
3390
|
+
console.log( nested, uniqueShow, 'nested', nestedLinkqn );
|
|
2809
3391
|
let findRandom = nesedQuestion.find( ( qn ) => ( uniqueShow ? qn.qno == nested : qn.uniqueNo == nested ) && !nestedLinkqn.includes( qn.uniqueNo ) && !qn.updated );
|
|
3392
|
+
console.log( findRandom );
|
|
2810
3393
|
if ( findRandom ) {
|
|
2811
3394
|
if ( ans.linkedQuestion == findRandom.qno ) {
|
|
2812
3395
|
ans.oldLinkedQuestion = ans.linkedQuestion;
|
|
@@ -2831,6 +3414,184 @@ export async function questionList( req, res ) {
|
|
|
2831
3414
|
}
|
|
2832
3415
|
}
|
|
2833
3416
|
|
|
3417
|
+
await processedchecklist.updateOne( { _id: requestData.processedcheckListId }, { questionAnswers: getchecklist[0].questionAnswers } );
|
|
3418
|
+
|
|
3419
|
+
return res.sendSuccess( getchecklist );
|
|
3420
|
+
}
|
|
3421
|
+
} catch ( e ) {
|
|
3422
|
+
logger.error( { function: 'questionList', error: e, body: req.body } );
|
|
3423
|
+
return res.sendError( e, 500 );
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
export async function questionList( req, res ) {
|
|
3428
|
+
try {
|
|
3429
|
+
let requestData = req.query;
|
|
3430
|
+
if ( !requestData.processedcheckListId ) {
|
|
3431
|
+
res.sendError( 'processedcheckListId is Required', 400 );
|
|
3432
|
+
}
|
|
3433
|
+
|
|
3434
|
+
let findQuery = [];
|
|
3435
|
+
let findAndQuery = [];
|
|
3436
|
+
findAndQuery.push( { _id: new ObjectId( requestData.processedcheckListId ) } );
|
|
3437
|
+
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
3438
|
+
|
|
3439
|
+
findQuery.push( {
|
|
3440
|
+
$project: {
|
|
3441
|
+
checkListName: { $ifNull: [ '$checkListName', '' ] },
|
|
3442
|
+
scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
|
|
3443
|
+
scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
|
|
3444
|
+
scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
|
|
3445
|
+
scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
|
|
3446
|
+
checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
|
|
3447
|
+
checkListId: { $ifNull: [ '$checkListId', '' ] },
|
|
3448
|
+
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
3449
|
+
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
3450
|
+
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
3451
|
+
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
3452
|
+
allowedStoreLocation: {
|
|
3453
|
+
$cond: {
|
|
3454
|
+
if: { $eq: [ '$client_id', '11' ] },
|
|
3455
|
+
then: false,
|
|
3456
|
+
else: {
|
|
3457
|
+
'$cond': {
|
|
3458
|
+
'if': { '$eq': [ '$coverage', 'user' ] },
|
|
3459
|
+
'then': false,
|
|
3460
|
+
'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
|
|
3461
|
+
},
|
|
3462
|
+
},
|
|
3463
|
+
},
|
|
3464
|
+
},
|
|
3465
|
+
reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
|
|
3466
|
+
questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
|
|
3467
|
+
getchecklist: { $ifNull: [ '$getchecklist', '' ] },
|
|
3468
|
+
userEmail: { $ifNull: [ '$userEmail', '' ] },
|
|
3469
|
+
storeName: { $ifNull: [ '$storeName', '' ] },
|
|
3470
|
+
redoStatus: { $ifNull: [ '$redoStatus', false ] },
|
|
3471
|
+
rawImageUpload: { $ifNull: [ '$rawImageUpload', false ] },
|
|
3472
|
+
},
|
|
3473
|
+
} );
|
|
3474
|
+
|
|
3475
|
+
let getchecklist = await processedchecklist.aggregate( findQuery );
|
|
3476
|
+
if ( !getchecklist.length ) {
|
|
3477
|
+
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
3478
|
+
} else {
|
|
3479
|
+
logger.info( `v5 => Checklist Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
|
|
3480
|
+
let bucket = JSON.parse( process.env.BUCKET );
|
|
3481
|
+
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3482
|
+
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
3483
|
+
let Multianswer = [];
|
|
3484
|
+
if ( getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage && getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage !='' ) {
|
|
3485
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = await signedUrl( { file_path: decodeURIComponent( getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage ), Bucket: bucket.sop } );
|
|
3486
|
+
}
|
|
3487
|
+
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
3488
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3489
|
+
let checkvalidation = null;
|
|
3490
|
+
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3491
|
+
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3492
|
+
checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3493
|
+
} else {
|
|
3494
|
+
checkvalidation = answer.validationAnswer;
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3498
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3499
|
+
}
|
|
3500
|
+
if ( answer.referenceImage != '' ) {
|
|
3501
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( answer.referenceImage ), Bucket: bucket.sop } );
|
|
3502
|
+
}
|
|
3503
|
+
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3504
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
if ( question?.userAnswer ) {
|
|
3508
|
+
for ( let [ userAnsIndex, userAns ] of question.userAnswer.entries() ) {
|
|
3509
|
+
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3510
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = await signedUrl( { file_path: decodeURIComponent( userAns.validationAnswer ), Bucket: bucket.sop } );
|
|
3511
|
+
}
|
|
3512
|
+
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3513
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3514
|
+
}
|
|
3515
|
+
if ( userAns.referenceImage != '' ) {
|
|
3516
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( userAns.referenceImage ), Bucket: bucket.sop } );
|
|
3517
|
+
}
|
|
3518
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3519
|
+
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3520
|
+
if ( ansIndex ) {
|
|
3521
|
+
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3525
|
+
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
3526
|
+
let manswer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3527
|
+
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
3528
|
+
} else {
|
|
3529
|
+
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3535
|
+
Multianswer.forEach( ( item ) => {
|
|
3536
|
+
if ( item.validationAnswer == null ) {
|
|
3537
|
+
item.answer = null;
|
|
3538
|
+
}
|
|
3539
|
+
} );
|
|
3540
|
+
if ( Multianswer.length ) {
|
|
3541
|
+
question.Multianswer = Multianswer;
|
|
3542
|
+
} else {
|
|
3543
|
+
question.Multianswer = Multianswer;
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3547
|
+
if ( Multianswer.length ) {
|
|
3548
|
+
question.Multianswer = Multianswer;
|
|
3549
|
+
} else {
|
|
3550
|
+
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null } );
|
|
3551
|
+
question.Multianswer = Multianswer;
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
let questions = [];
|
|
3558
|
+
function processQuestion( question, section, questions, nested=false ) {
|
|
3559
|
+
let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
|
|
3560
|
+
if ( findExists && nested ) {
|
|
3561
|
+
let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
|
|
3562
|
+
questions.splice( findIndex, 1 );
|
|
3563
|
+
questions.push( question );
|
|
3564
|
+
for ( let answer of question.answers ) {
|
|
3565
|
+
if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
3566
|
+
let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
3567
|
+
if ( linkedQuestion ) {
|
|
3568
|
+
processQuestion( linkedQuestion, section, questions, true );
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
if ( !findExists ) {
|
|
3574
|
+
questions.push( question );
|
|
3575
|
+
for ( let answer of question.answers ) {
|
|
3576
|
+
if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
3577
|
+
let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
3578
|
+
if ( linkedQuestion ) {
|
|
3579
|
+
processQuestion( linkedQuestion, section, questions, true );
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
for ( let [ index, data ] of getchecklist.entries() ) {
|
|
3586
|
+
for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
|
|
3587
|
+
questions = [];
|
|
3588
|
+
for ( let question of section.questions ) {
|
|
3589
|
+
processQuestion( question, section, questions );
|
|
3590
|
+
}
|
|
3591
|
+
getchecklist[index].questionAnswers[secIndex].questions = questions;
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
|
|
2834
3595
|
return res.sendSuccess( getchecklist );
|
|
2835
3596
|
}
|
|
2836
3597
|
} catch ( e ) {
|
|
@@ -272,6 +272,18 @@ 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
|
+
}
|
|
275
287
|
|
|
276
288
|
let sectionList = {
|
|
277
289
|
section: section.name,
|
|
@@ -804,6 +816,21 @@ export const update = async ( req, res ) => {
|
|
|
804
816
|
}
|
|
805
817
|
}
|
|
806
818
|
|
|
819
|
+
let checkNestedLevel = false;
|
|
820
|
+
section.questions.forEach( ( qns ) => {
|
|
821
|
+
qns.answers.forEach( ( answ ) => {
|
|
822
|
+
if ( answ.nestedQuestion.length > 20 ) {
|
|
823
|
+
checkNestedLevel = true;
|
|
824
|
+
}
|
|
825
|
+
} );
|
|
826
|
+
} );
|
|
827
|
+
|
|
828
|
+
console.log( checkNestedLevel, 'lebej' );
|
|
829
|
+
|
|
830
|
+
if ( checkNestedLevel ) {
|
|
831
|
+
return res.sendError( { message: 'Unable to create more than 20 linked questions' }, 400 );
|
|
832
|
+
}
|
|
833
|
+
|
|
807
834
|
let sectionList = {
|
|
808
835
|
section: section.name,
|
|
809
836
|
sectionOldName: section.oldName,
|
|
@@ -3148,7 +3175,6 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3148
3175
|
}
|
|
3149
3176
|
if ( getsubmitDetails ) {
|
|
3150
3177
|
getsubmitDetails = [ getsubmitDetails ];
|
|
3151
|
-
console.log( submittedDetails, getsubmitDetails );
|
|
3152
3178
|
}
|
|
3153
3179
|
function findDifferences( obj1, obj2 ) {
|
|
3154
3180
|
return Object.keys( obj1 ).reduce( ( diff, key ) => {
|
|
@@ -3256,6 +3282,31 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3256
3282
|
}
|
|
3257
3283
|
questions.forEach( ( qnIdx ) => {
|
|
3258
3284
|
if ( qn.type == 'qnEdit' ) {
|
|
3285
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].answers.forEach( ( ele ) => {
|
|
3286
|
+
console.log( ele?.nestedQuestion );
|
|
3287
|
+
if ( ele?.nestedQuestion.length ) {
|
|
3288
|
+
ele?.nestedQuestion.forEach( ( nested ) => {
|
|
3289
|
+
let findIndex = getsubmitDetails[0].questionAnswers[sectionDetails].questions.findIndex( ( qn ) => qn.uniqueNo == nested );
|
|
3290
|
+
if ( findIndex != -1 ) {
|
|
3291
|
+
delete getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].userAnswer;
|
|
3292
|
+
let questionDetails = getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex];
|
|
3293
|
+
let checkQuestionExists = getsubmitDetails[0].questionAnswers[sectionDetails].questions.filter( ( qnDetails ) => qnDetails.qname == questionDetails.qname );
|
|
3294
|
+
if ( checkQuestionExists.length > 1 ) {
|
|
3295
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions.splice( findIndex, 1 );
|
|
3296
|
+
} else {
|
|
3297
|
+
delete getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].uniqueNo;
|
|
3298
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].linkquestionenabled = false;
|
|
3299
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].answers.forEach( ( ele ) => {
|
|
3300
|
+
if ( ele?.oldNestedQuestion?.length ) {
|
|
3301
|
+
ele.nestedQuestion = ele.oldNestedQuestion;
|
|
3302
|
+
ele.linkedQuestion = ele.oldLinkedQuestion;
|
|
3303
|
+
}
|
|
3304
|
+
} );
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
} );
|
|
3308
|
+
}
|
|
3309
|
+
} );
|
|
3259
3310
|
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx] = qn.question;
|
|
3260
3311
|
} else {
|
|
3261
3312
|
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].qname = qn.question.qname;
|
|
@@ -3408,14 +3459,14 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3408
3459
|
const title = `${getCLconfig.checkListName}`;
|
|
3409
3460
|
const description = `Checklist has been updated and re-published!`;
|
|
3410
3461
|
const fcmToken = item;
|
|
3411
|
-
sendPushNotification( title, description, fcmToken );
|
|
3462
|
+
sendPushNotification( title, description, {}, fcmToken );
|
|
3412
3463
|
} );
|
|
3413
3464
|
|
|
3414
3465
|
notifyUserList.forEach( ( item ) => {
|
|
3415
3466
|
const title = `New Checklist Assigned ${item.storeName}`;
|
|
3416
3467
|
const description = `The ${getCLconfig.checkListName} checklist has been assigned to ${item.storeName} for the first time.complete to avoid compliance.`;
|
|
3417
3468
|
const fcmToken = item.token;
|
|
3418
|
-
sendPushNotification( title, description, fcmToken );
|
|
3469
|
+
sendPushNotification( title, description, {}, fcmToken );
|
|
3419
3470
|
} );
|
|
3420
3471
|
|
|
3421
3472
|
let updateUserList = notifyUserList.map( ( ele ) => ele.id );
|
|
@@ -3809,7 +3809,8 @@ export async function sendAlert( req, res ) {
|
|
|
3809
3809
|
}
|
|
3810
3810
|
const fcmToken = item.token;
|
|
3811
3811
|
try {
|
|
3812
|
-
await sendPushNotification( title, description, fcmToken );
|
|
3812
|
+
let response = await sendPushNotification( title, description, fcmToken );
|
|
3813
|
+
console.log( response, 'response' );
|
|
3813
3814
|
} catch ( e ) {
|
|
3814
3815
|
logger.error( { message: 'send alert', error: e, details: data } );
|
|
3815
3816
|
}
|
|
@@ -9,15 +9,18 @@ mobileRouter
|
|
|
9
9
|
.get( '/storeList', isAllowedSessionHandler, mobileController.storeList )
|
|
10
10
|
.get( '/storeListv1', isAllowedSessionHandler, mobileController.storeListv1 )
|
|
11
11
|
.post( '/startCheckList', isAllowedSessionHandler, validate( startValidation ), mobileController.startChecklist )
|
|
12
|
+
.post( '/startCheckListv1', isAllowedSessionHandler, validate( startValidation ), mobileController.startChecklistv1 )
|
|
12
13
|
.post( '/startTask', isAllowedSessionHandler, validate( startValidation ), mobileController.startTask )
|
|
13
14
|
.post( '/submitCheckList', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidator, mobileController.sopMobilechecklistMultiSectionFormatter, mobileController.submitChecklist )
|
|
14
15
|
.post( '/submitCheckListv5', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv1, mobileController.submitChecklist )
|
|
16
|
+
.post( '/submitCheckListv6', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv2, mobileController.submitChecklist )
|
|
15
17
|
.post( '/submitTask', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobileTaskQuestionValidator, mobileController.sopMobileTaskMultiSectionFormatter, mobileController.submitTask )
|
|
16
18
|
.get( '/dashboard', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboard )
|
|
17
19
|
.get( '/dashboardv1', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboardv1 )
|
|
18
20
|
.get( '/checklist', isAllowedSessionHandler, validate( mobileChecklistValidation ), mobileController.checklist )
|
|
19
21
|
.get( '/checklistv1', isAllowedSessionHandler, validate( mobileChecklistValidation ), mobileController.checklistv1 )
|
|
20
22
|
.get( '/checklistQuestionList', isAllowedSessionHandler, mobileController.questionList )
|
|
23
|
+
.get( '/checklistQuestionListv1', isAllowedSessionHandler, mobileController.questionListv1 )
|
|
21
24
|
.get( '/taskQuestionList', isAllowedSessionHandler, mobileController.taskQuestionList )
|
|
22
25
|
.post( '/uploadAnswerImage', isAllowedSessionHandler, mobileController.uploadAnswerImage )
|
|
23
26
|
.get( '/appVersion', mobileController.appVersion )
|