tango-app-api-trax 3.7.73 → 3.7.75
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 +2 -4
- package/src/controllers/internalTrax.controller.js +3 -157
- package/src/controllers/mobileTrax.controller.js +39 -379
- package/src/controllers/trax.controller.js +1 -80
- package/src/controllers/traxDashboard.controllers.js +3 -58
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/internalTraxApi.router.js +0 -1
- package/src/routes/mobileTrax.routes.js +1 -3
- package/src/routes/trax.routes.js +1 -2
- package/src/controllers/handlebar-helper.js +0 -16
- package/src/hbs/flag.hbs +0 -249
- package/src/hbs/template.hbs +0 -337
|
@@ -21,16 +21,12 @@ import * as clientService from '../services/clients.services.js';
|
|
|
21
21
|
import { create } from '../services/authentication.service.js';
|
|
22
22
|
import { readFileSync } from 'fs';
|
|
23
23
|
import { join } from 'path';
|
|
24
|
-
|
|
24
|
+
import handlebars from 'handlebars';
|
|
25
25
|
dayjs.extend( customParseFormat );
|
|
26
26
|
dayjs.extend( timeZone );
|
|
27
27
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
|
|
28
28
|
import * as cameraService from '../services/camera.service.js';
|
|
29
29
|
dayjs.extend( isSameOrBefore );
|
|
30
|
-
import puppeteer from 'puppeteer';
|
|
31
|
-
import handlebars from './handlebar-helper.js';
|
|
32
|
-
import fs from 'fs';
|
|
33
|
-
import path from 'path';
|
|
34
30
|
|
|
35
31
|
export async function storeList( req, res ) {
|
|
36
32
|
try {
|
|
@@ -229,7 +225,6 @@ export async function startChecklist( req, res ) {
|
|
|
229
225
|
},
|
|
230
226
|
questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
|
|
231
227
|
redoStatus: { $ifNull: [ '$redoStatus', '' ] },
|
|
232
|
-
export: { $ifNull: [ '$export', '' ] },
|
|
233
228
|
},
|
|
234
229
|
} );
|
|
235
230
|
let getupdatedchecklist = await processedchecklist.aggregate( findQuery );
|
|
@@ -665,10 +660,10 @@ export async function sopMobilechecklistQuestionValidatorv1( req, res, next ) {
|
|
|
665
660
|
// question.answers.forEach( ( answer ) => {
|
|
666
661
|
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
667
662
|
if ( sectionQuestion.length ) {
|
|
668
|
-
if (
|
|
663
|
+
if ( question.answerType == 'multiplechoicemultiple' && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
|
|
669
664
|
validationCount++;
|
|
670
665
|
} else {
|
|
671
|
-
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) && (
|
|
666
|
+
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) && ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) ) {
|
|
672
667
|
validationCount++;
|
|
673
668
|
}
|
|
674
669
|
}
|
|
@@ -714,13 +709,10 @@ export async function sopMobileTaskQuestionValidator( req, res, next ) {
|
|
|
714
709
|
section.questions.forEach( ( question ) => {
|
|
715
710
|
question.answers.forEach( ( answer ) => {
|
|
716
711
|
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qno == question.qno );
|
|
717
|
-
if ( sectionQuestion[0] ) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
if ( usesMultianswer && multianswerEmpty ) {
|
|
722
|
-
validationCount++;
|
|
723
|
-
} else if ( !usesMultianswer && answerEmpty ) {
|
|
712
|
+
if ( question.answerType == 'multiplechoicemultiple' && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
|
|
713
|
+
validationCount++;
|
|
714
|
+
} else {
|
|
715
|
+
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) && ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) ) {
|
|
724
716
|
validationCount++;
|
|
725
717
|
}
|
|
726
718
|
}
|
|
@@ -1090,7 +1082,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1090
1082
|
|
|
1091
1083
|
if ( requestData.submittype == 'submit' ) {
|
|
1092
1084
|
reqAnswers.forEach( ( reqA ) => {
|
|
1093
|
-
if ( ![ 'multiplechoicemultiple', 'multipleImage'
|
|
1085
|
+
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( reqA?.answerType ) ) {
|
|
1094
1086
|
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
1095
1087
|
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1096
1088
|
}
|
|
@@ -1213,7 +1205,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1213
1205
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1214
1206
|
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1215
1207
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1216
|
-
structure.compliance = qaAnswers[j]?.compliance;
|
|
1217
1208
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1218
1209
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1219
1210
|
if ( qaAnswers[j]?.taskId ) {
|
|
@@ -1229,7 +1220,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1229
1220
|
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1230
1221
|
};
|
|
1231
1222
|
newArray.push( structure );
|
|
1232
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle'
|
|
1223
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
|
|
1233
1224
|
let qaans = qaAnswers[j].answers;
|
|
1234
1225
|
let ms = [];
|
|
1235
1226
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
@@ -1270,8 +1261,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1270
1261
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1271
1262
|
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1272
1263
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1273
|
-
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1274
|
-
structure.compliance = qaAnswers[j]?.compliance;
|
|
1275
1264
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1276
1265
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1277
1266
|
if ( qaAnswers[j]?.taskId ) {
|
|
@@ -1287,7 +1276,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1287
1276
|
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1288
1277
|
};
|
|
1289
1278
|
newArray.push( structure );
|
|
1290
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple'
|
|
1279
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
|
|
1291
1280
|
let qaans = qaAnswers[j].answers;
|
|
1292
1281
|
let mcmo = [];
|
|
1293
1282
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
@@ -1332,8 +1321,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1332
1321
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1333
1322
|
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1334
1323
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1335
|
-
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1336
|
-
structure.compliance = qaAnswers[j]?.compliance;
|
|
1337
1324
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1338
1325
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1339
1326
|
if ( qaAnswers[j]?.taskId ) {
|
|
@@ -1349,7 +1336,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1349
1336
|
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1350
1337
|
};
|
|
1351
1338
|
newArray.push( structure );
|
|
1352
|
-
} else if (
|
|
1339
|
+
} else if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
1353
1340
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1354
1341
|
let mcmi = [];
|
|
1355
1342
|
// for (let k = 0; k < qaans.length; k++) {
|
|
@@ -1379,9 +1366,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1379
1366
|
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1380
1367
|
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1381
1368
|
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1382
|
-
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1383
|
-
newAnswer.answerType = separatedArray[s].answerType;
|
|
1384
|
-
}
|
|
1385
1369
|
mcmi.push( newAnswer );
|
|
1386
1370
|
}
|
|
1387
1371
|
}
|
|
@@ -1404,7 +1388,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1404
1388
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1405
1389
|
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1406
1390
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1407
|
-
structure.compliance = qaAnswers[j]?.compliance;
|
|
1408
1391
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1409
1392
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1410
1393
|
if ( qaAnswers[j]?.taskId ) {
|
|
@@ -1451,40 +1434,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1451
1434
|
};
|
|
1452
1435
|
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1453
1436
|
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1454
|
-
if ( qaAnswers[j].compliance ) {
|
|
1455
|
-
if ( qaAnswers[j].compliance ) {
|
|
1456
|
-
let ansArray = requestSection[i].answer.split( ',' );
|
|
1457
|
-
if ( ansArray.includes( '-' ) ) {
|
|
1458
|
-
ansArray = requestSection[i].answer.split( '-' );
|
|
1459
|
-
}
|
|
1460
|
-
if ( ansArray.length > 1 && ansArray.some( ( date ) => dayjs( date, 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate || dayjs( date, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
|
|
1461
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1462
|
-
} else if ( ansArray.length > 1 && ( dayjs( ansArray?.[0], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate || dayjs( ansArray?.[1], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
|
|
1463
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1464
|
-
} else if ( dayjs( requestSection[i].answer, 'DD MMM YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate || dayjs( requestSection[i].answer, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.startDate ) {
|
|
1465
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1466
|
-
} else {
|
|
1467
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
if ( qaAnswers[j].answerType == 'linearscale' ) {
|
|
1473
|
-
if ( qaAnswers[j].compliance ) {
|
|
1474
|
-
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
1475
|
-
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue || parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1476
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1477
|
-
} else {
|
|
1478
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
|
|
1482
|
-
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1483
|
-
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1484
|
-
}
|
|
1485
|
-
if ( qaAnswers[j].answerType == 'image' ) {
|
|
1486
|
-
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1487
|
-
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1488
1437
|
}
|
|
1489
1438
|
des.push( ansstructure );
|
|
1490
1439
|
}
|
|
@@ -1508,7 +1457,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1508
1457
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1509
1458
|
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1510
1459
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1511
|
-
structure.compliance = qaAnswers[j]?.compliance;
|
|
1512
1460
|
if ( qaAnswers[j]?.taskId ) {
|
|
1513
1461
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1514
1462
|
structure.task = true;
|
|
@@ -1555,7 +1503,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
1555
1503
|
|
|
1556
1504
|
if ( requestData.submittype == 'submit' ) {
|
|
1557
1505
|
reqAnswers.forEach( ( reqA ) => {
|
|
1558
|
-
if ( ![ 'multiplechoicemultiple', 'multipleImage'
|
|
1506
|
+
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( reqA?.answerType ) ) {
|
|
1559
1507
|
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
1560
1508
|
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1561
1509
|
}
|
|
@@ -1736,64 +1684,8 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
1736
1684
|
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1737
1685
|
};
|
|
1738
1686
|
newArray.push( structure );
|
|
1739
|
-
} else if ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) {
|
|
1740
|
-
let qaans = qaAnswers[j].answers;
|
|
1741
|
-
let mcmo = [];
|
|
1742
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1743
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1744
|
-
if ( separatedArray && separatedArray.length ) {
|
|
1745
|
-
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1746
|
-
if ( separatedArray[s].answer == qaans[k].answer ) {
|
|
1747
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1748
|
-
if ( separatedArray[s].validationAnswer ) {
|
|
1749
|
-
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1750
|
-
if ( validationAnswer.length ) {
|
|
1751
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1752
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1753
|
-
splitImgUrl.splice( 0, 3 );
|
|
1754
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
} else {
|
|
1759
|
-
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1760
|
-
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1761
|
-
}
|
|
1762
|
-
mcmo.push( qaans[k] );
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
let structure = {};
|
|
1768
|
-
structure.qno = qaAnswers[j].qno;
|
|
1769
|
-
structure.qname = qaAnswers[j].qname;
|
|
1770
|
-
if ( qaAnswers[j].qcomment && qaAnswers[j].qcomment!='' ) {
|
|
1771
|
-
structure.qcomment = qaAnswers[j].qcomment;
|
|
1772
|
-
}
|
|
1773
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1774
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1775
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1776
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1777
|
-
structure.remarks = requestSection[i].remarks;
|
|
1778
|
-
structure.answers = qaAnswers[j].answers;
|
|
1779
|
-
structure.userAnswer = mcmo;
|
|
1780
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1781
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1782
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1783
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1784
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1785
|
-
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1786
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1787
|
-
structure.redo = false;
|
|
1788
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1789
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1790
|
-
}
|
|
1791
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1792
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1793
|
-
};
|
|
1794
|
-
newArray.push( structure );
|
|
1795
1687
|
} else if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
1796
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) :
|
|
1688
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1797
1689
|
let mcmi = [];
|
|
1798
1690
|
// for (let k = 0; k < qaans.length; k++) {
|
|
1799
1691
|
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
@@ -1851,69 +1743,6 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
1851
1743
|
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1852
1744
|
};
|
|
1853
1745
|
newArray.push( structure );
|
|
1854
|
-
} else if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1855
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1856
|
-
let mcmi = [];
|
|
1857
|
-
if ( separatedArray && separatedArray.length ) {
|
|
1858
|
-
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1859
|
-
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1860
|
-
let newAnswer = {};
|
|
1861
|
-
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1862
|
-
if ( validationAnswer.length ) {
|
|
1863
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1864
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1865
|
-
splitImgUrl.splice( 0, 3 );
|
|
1866
|
-
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
newAnswer.answeroptionNumber = 0;
|
|
1870
|
-
newAnswer.sopFlag = false;
|
|
1871
|
-
newAnswer.validation = false;
|
|
1872
|
-
newAnswer.validationType = '';
|
|
1873
|
-
newAnswer.referenceImage = '';
|
|
1874
|
-
newAnswer.allowUploadfromGallery = false;
|
|
1875
|
-
newAnswer.descriptivetype = '';
|
|
1876
|
-
newAnswer.showLinked = false;
|
|
1877
|
-
newAnswer.linkedQuestion = 0;
|
|
1878
|
-
newAnswer.nestedQuestion = [];
|
|
1879
|
-
newAnswer.index = s;
|
|
1880
|
-
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1881
|
-
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1882
|
-
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1883
|
-
if ( separatedArray[s].answerType ) {
|
|
1884
|
-
newAnswer.answerType = separatedArray[s].answerType;
|
|
1885
|
-
}
|
|
1886
|
-
mcmi.push( newAnswer );
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
let structure = {};
|
|
1891
|
-
structure.qno = qaAnswers[j].qno;
|
|
1892
|
-
structure.qname = qaAnswers[j].qname;
|
|
1893
|
-
if ( qaAnswers[j].qcomment && qaAnswers[j].qcomment!='' ) {
|
|
1894
|
-
structure.qcomment = qaAnswers[j].qcomment;
|
|
1895
|
-
}
|
|
1896
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1897
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1898
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1899
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1900
|
-
structure.remarks = requestSection[i].remarks;
|
|
1901
|
-
structure.answers = qaAnswers[j].answers;
|
|
1902
|
-
structure.userAnswer = mcmi;
|
|
1903
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1904
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1905
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1906
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1907
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1908
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1909
|
-
structure.redo = false;
|
|
1910
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1911
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1912
|
-
}
|
|
1913
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1914
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1915
|
-
};
|
|
1916
|
-
newArray.push( structure );
|
|
1917
1746
|
} else {
|
|
1918
1747
|
let des = [];
|
|
1919
1748
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
@@ -2171,35 +2000,8 @@ export async function submitChecklist( req, res ) {
|
|
|
2171
2000
|
logDetails: {},
|
|
2172
2001
|
userType: req.user.userType,
|
|
2173
2002
|
};
|
|
2003
|
+
console.log( 'inserttraxlogs =>', inserttraxlogs );
|
|
2174
2004
|
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
2175
|
-
if ( updateData.questionFlag ) {
|
|
2176
|
-
let checklistDetails = await checklistService.findOne( { _id: getchecklist[0].sourceCheckList_id }, { notifyFlags: 1, approver: 1 } );
|
|
2177
|
-
if ( checklistDetails?.notifyFlags?.notifyType?.length ) {
|
|
2178
|
-
let emailList = checklistDetails?.notifyFlags?.notifyType.includes( 'approver' ) ? checklistDetails.approver.map( ( ele ) => ele?.value ): [];
|
|
2179
|
-
emailList = [ ...emailList, ...checklistDetails?.notifyFlags?.users?.map( ( ele ) => ele?.value ) ];
|
|
2180
|
-
let data = {
|
|
2181
|
-
storeName: getchecklist[0].storeName,
|
|
2182
|
-
flagCount: updateData.questionFlag,
|
|
2183
|
-
checklistName: getchecklist[0].checkListName,
|
|
2184
|
-
submittedBy: getchecklist[0].userName,
|
|
2185
|
-
time: updateData.submitTime_string,
|
|
2186
|
-
domain: `${JSON.parse( process.env.URL ).domain}/manage/trax/flags`,
|
|
2187
|
-
};
|
|
2188
|
-
const fileContent = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/flag.hbs', 'utf8' );
|
|
2189
|
-
const htmlContent = handlebars.compile( fileContent );
|
|
2190
|
-
const html = htmlContent( { data: data } );
|
|
2191
|
-
emailList.forEach( ( email ) => {
|
|
2192
|
-
let params = {
|
|
2193
|
-
toEmail: email,
|
|
2194
|
-
mailSubject: 'TangoEye | Checklist Flag',
|
|
2195
|
-
htmlBody: html,
|
|
2196
|
-
attachment: '',
|
|
2197
|
-
sourceEmail: JSON.parse( process.env.SES ).adminEmail,
|
|
2198
|
-
};
|
|
2199
|
-
sendEmailWithSES( params.toEmail, params.mailSubject, params.htmlBody, params.attachment, params.sourceEmail );
|
|
2200
|
-
} );
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
2005
|
}
|
|
2204
2006
|
|
|
2205
2007
|
return res.sendSuccess( 'Checklist Updated Successfully' );
|
|
@@ -2451,8 +2253,9 @@ export async function submiteyeTestTask( req, res ) {
|
|
|
2451
2253
|
if ( findQrExists ) {
|
|
2452
2254
|
return res.sendError( 'Qr code already Exists', 400 );
|
|
2453
2255
|
}
|
|
2454
|
-
|
|
2455
2256
|
await cameraService.updateOne( { streamName: streamId }, { qrCode: qrCode, isEyeTestStream: true } );
|
|
2257
|
+
let findCamera = await cameraService.findOne( { streamName: streamId } );
|
|
2258
|
+
await storeService.updateOne( { storeId: findCamera.storeId }, { 'edge.isSocketEnable': true } );
|
|
2456
2259
|
return res.sendSuccess( 'Qr code added successfully' );
|
|
2457
2260
|
|
|
2458
2261
|
const findQuery = [
|
|
@@ -3428,7 +3231,6 @@ export async function questionList( req, res ) {
|
|
|
3428
3231
|
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
3429
3232
|
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
3430
3233
|
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
3431
|
-
sourceCheckList_id: 1,
|
|
3432
3234
|
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
3433
3235
|
allowedStoreLocation: {
|
|
3434
3236
|
$cond: {
|
|
@@ -3454,7 +3256,6 @@ export async function questionList( req, res ) {
|
|
|
3454
3256
|
videoUploadTimeLimit: { $ifNull: [ '$videoUploadTimeLimit', 0 ] },
|
|
3455
3257
|
taskType: { $ifNull: [ '$planoType', '' ] },
|
|
3456
3258
|
streamId: { $ifNull: [ '$streamId', '' ] },
|
|
3457
|
-
export: { $ifNull: [ '$export', '' ] },
|
|
3458
3259
|
},
|
|
3459
3260
|
} );
|
|
3460
3261
|
|
|
@@ -3485,7 +3286,7 @@ export async function questionList( req, res ) {
|
|
|
3485
3286
|
}
|
|
3486
3287
|
|
|
3487
3288
|
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
3488
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3289
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3489
3290
|
let checkvalidation = null;
|
|
3490
3291
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3491
3292
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
@@ -3539,24 +3340,24 @@ export async function questionList( req, res ) {
|
|
|
3539
3340
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].multiReferenceImage = userAns.multiReferenceImage;
|
|
3540
3341
|
}
|
|
3541
3342
|
|
|
3542
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3343
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3543
3344
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3544
3345
|
if ( ansIndex ) {
|
|
3545
3346
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
3546
3347
|
}
|
|
3547
3348
|
}
|
|
3548
|
-
if (
|
|
3349
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3549
3350
|
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
3550
3351
|
// let manswer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3551
3352
|
let manswer = `${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
3552
|
-
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': ''
|
|
3353
|
+
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
3553
3354
|
} else {
|
|
3554
3355
|
|
|
3555
3356
|
}
|
|
3556
3357
|
}
|
|
3557
3358
|
}
|
|
3558
3359
|
}
|
|
3559
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3360
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3560
3361
|
Multianswer.forEach( ( item ) => {
|
|
3561
3362
|
if ( item.validationAnswer == null ) {
|
|
3562
3363
|
item.answer = null;
|
|
@@ -3568,11 +3369,11 @@ export async function questionList( req, res ) {
|
|
|
3568
3369
|
question.Multianswer = Multianswer;
|
|
3569
3370
|
}
|
|
3570
3371
|
}
|
|
3571
|
-
if (
|
|
3372
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3572
3373
|
if ( Multianswer.length ) {
|
|
3573
3374
|
question.Multianswer = Multianswer;
|
|
3574
3375
|
} else {
|
|
3575
|
-
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null
|
|
3376
|
+
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null } );
|
|
3576
3377
|
question.Multianswer = Multianswer;
|
|
3577
3378
|
}
|
|
3578
3379
|
}
|
|
@@ -3617,11 +3418,6 @@ export async function questionList( req, res ) {
|
|
|
3617
3418
|
}
|
|
3618
3419
|
}
|
|
3619
3420
|
|
|
3620
|
-
let checklisDetails = await checklistService.findOne( { _id: getchecklist?.[0]?.sourceCheckList_id }, { export: 1 } );
|
|
3621
|
-
if ( checklisDetails ) {
|
|
3622
|
-
getchecklist[0]['export'] = checklisDetails.export;
|
|
3623
|
-
}
|
|
3624
|
-
|
|
3625
3421
|
return res.sendSuccess( getchecklist );
|
|
3626
3422
|
}
|
|
3627
3423
|
} catch ( e ) {
|
|
@@ -3826,7 +3622,6 @@ export async function taskQuestionList( req, res ) {
|
|
|
3826
3622
|
} else {
|
|
3827
3623
|
logger.info( `v5 => Task Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Task Name: ${getchecklist[0].checkListName}` );
|
|
3828
3624
|
let bucket = JSON.parse( process.env.BUCKET );
|
|
3829
|
-
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3830
3625
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3831
3626
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
3832
3627
|
let Multianswer = [];
|
|
@@ -3863,14 +3658,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3863
3658
|
}
|
|
3864
3659
|
}
|
|
3865
3660
|
|
|
3866
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3661
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3867
3662
|
let checkvalidation = null;
|
|
3868
3663
|
if ( answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3869
|
-
|
|
3870
|
-
checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3871
|
-
} else {
|
|
3872
|
-
checkvalidation = answer.validationAnswer;
|
|
3873
|
-
}
|
|
3664
|
+
checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3874
3665
|
}
|
|
3875
3666
|
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3876
3667
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
@@ -3891,7 +3682,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3891
3682
|
Bucket: bucket.sop,
|
|
3892
3683
|
} );
|
|
3893
3684
|
}
|
|
3894
|
-
if ( [ 'image', 'descriptiveImage', 'video'
|
|
3685
|
+
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3895
3686
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = await signedUrl( {
|
|
3896
3687
|
file_path: decodeURIComponent( userAns.answer ),
|
|
3897
3688
|
Bucket: bucket.sop,
|
|
@@ -3903,23 +3694,23 @@ export async function taskQuestionList( req, res ) {
|
|
|
3903
3694
|
Bucket: bucket.sop,
|
|
3904
3695
|
} );
|
|
3905
3696
|
}
|
|
3906
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3697
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3907
3698
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3908
|
-
if ( ansIndex
|
|
3699
|
+
if ( ansIndex ) {
|
|
3909
3700
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
3910
3701
|
}
|
|
3911
3702
|
}
|
|
3912
|
-
if ( question.answerType == 'multipleImage'
|
|
3703
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3913
3704
|
if ( userAns && userAns.answer && userAns.answer != '' ) {
|
|
3914
|
-
let manswer =
|
|
3915
|
-
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': ''
|
|
3705
|
+
let manswer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3706
|
+
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
3916
3707
|
} else {
|
|
3917
3708
|
|
|
3918
3709
|
}
|
|
3919
3710
|
}
|
|
3920
3711
|
}
|
|
3921
3712
|
}
|
|
3922
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3713
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3923
3714
|
Multianswer.forEach( ( item ) => {
|
|
3924
3715
|
if ( item.validationAnswer == null ) {
|
|
3925
3716
|
item.answer = null;
|
|
@@ -3931,11 +3722,11 @@ export async function taskQuestionList( req, res ) {
|
|
|
3931
3722
|
question.Multianswer = Multianswer;
|
|
3932
3723
|
}
|
|
3933
3724
|
}
|
|
3934
|
-
if ( question.answerType == 'multipleImage'
|
|
3725
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3935
3726
|
if ( Multianswer.length ) {
|
|
3936
3727
|
question.Multianswer = Multianswer;
|
|
3937
3728
|
} else {
|
|
3938
|
-
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null
|
|
3729
|
+
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null } );
|
|
3939
3730
|
question.Multianswer = Multianswer;
|
|
3940
3731
|
}
|
|
3941
3732
|
}
|
|
@@ -4448,7 +4239,6 @@ export async function questionListV1( req, res ) {
|
|
|
4448
4239
|
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
4449
4240
|
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
4450
4241
|
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
4451
|
-
sourceCheckList_id: { $ifNull: [ '$sourceCheckList_id', '' ] },
|
|
4452
4242
|
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
4453
4243
|
allowedStoreLocation: {
|
|
4454
4244
|
$cond: {
|
|
@@ -4504,7 +4294,7 @@ export async function questionListV1( req, res ) {
|
|
|
4504
4294
|
}
|
|
4505
4295
|
|
|
4506
4296
|
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
4507
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4297
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4508
4298
|
let checkvalidation = null;
|
|
4509
4299
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
4510
4300
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
@@ -4556,13 +4346,13 @@ export async function questionListV1( req, res ) {
|
|
|
4556
4346
|
|
|
4557
4347
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].multiReferenceImage = userAns.multiReferenceImage;
|
|
4558
4348
|
}
|
|
4559
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4349
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4560
4350
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
4561
4351
|
if ( ansIndex ) {
|
|
4562
4352
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
4563
4353
|
}
|
|
4564
4354
|
}
|
|
4565
|
-
if ( question.answerType == 'multipleImage'
|
|
4355
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
4566
4356
|
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
4567
4357
|
let manswer = `${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
4568
4358
|
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
@@ -4572,7 +4362,7 @@ export async function questionListV1( req, res ) {
|
|
|
4572
4362
|
}
|
|
4573
4363
|
}
|
|
4574
4364
|
}
|
|
4575
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4365
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4576
4366
|
Multianswer.forEach( ( item ) => {
|
|
4577
4367
|
if ( item.validationAnswer == null ) {
|
|
4578
4368
|
item.answer = null;
|
|
@@ -4584,7 +4374,7 @@ export async function questionListV1( req, res ) {
|
|
|
4584
4374
|
question.Multianswer = Multianswer;
|
|
4585
4375
|
}
|
|
4586
4376
|
}
|
|
4587
|
-
if ( question.answerType == 'multipleImage'
|
|
4377
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
4588
4378
|
if ( Multianswer.length ) {
|
|
4589
4379
|
question.Multianswer = Multianswer;
|
|
4590
4380
|
} else {
|
|
@@ -4633,11 +4423,6 @@ export async function questionListV1( req, res ) {
|
|
|
4633
4423
|
}
|
|
4634
4424
|
}
|
|
4635
4425
|
|
|
4636
|
-
let checklisDetails = await checklistService.findOne( { _id: getchecklist?.[0]?.sourceCheckList_id }, { export: 1 } );
|
|
4637
|
-
if ( checklisDetails ) {
|
|
4638
|
-
getchecklist[0]['export'] = checklisDetails.export;
|
|
4639
|
-
}
|
|
4640
|
-
|
|
4641
4426
|
return res.sendSuccess( getchecklist );
|
|
4642
4427
|
}
|
|
4643
4428
|
} catch ( e ) {
|
|
@@ -4700,128 +4485,3 @@ export async function chunkUpload( req, res ) {
|
|
|
4700
4485
|
return res.sendError( e, 500 );
|
|
4701
4486
|
}
|
|
4702
4487
|
}
|
|
4703
|
-
|
|
4704
|
-
export async function downloadChecklist( req, res ) {
|
|
4705
|
-
try {
|
|
4706
|
-
let requestData = req.body;
|
|
4707
|
-
|
|
4708
|
-
if ( !requestData.checklistId ) {
|
|
4709
|
-
return res.sendError( 'checklistId is Required', 400 );
|
|
4710
|
-
}
|
|
4711
|
-
|
|
4712
|
-
let checklistDetails;
|
|
4713
|
-
|
|
4714
|
-
if ( requestData.type == 'checklist' ) {
|
|
4715
|
-
checklistDetails = await processedchecklist.findOne( { _id: requestData.checklistId, checklistStatus: 'submit' } );
|
|
4716
|
-
} else {
|
|
4717
|
-
checklistDetails = await processedTask.findOne( { _id: requestData.checklistId, checklistStatus: 'submit' } );
|
|
4718
|
-
}
|
|
4719
|
-
|
|
4720
|
-
if ( !checklistDetails ) {
|
|
4721
|
-
return res.sendError( 'No data found', 204 );
|
|
4722
|
-
}
|
|
4723
|
-
|
|
4724
|
-
let storeDetails = await storeService.findOne( { storeId: checklistDetails.store_id }, { storeProfile: 1 } );
|
|
4725
|
-
if ( !storeDetails ) {
|
|
4726
|
-
return res.sendError( 'No data found', 204 );
|
|
4727
|
-
}
|
|
4728
|
-
|
|
4729
|
-
let clientDetails = await clientService.findOne( { clientId: checklistDetails.client_id } );
|
|
4730
|
-
|
|
4731
|
-
if ( !clientDetails ) {
|
|
4732
|
-
return res.sendError( 'No client found', 204 );
|
|
4733
|
-
}
|
|
4734
|
-
|
|
4735
|
-
checklistDetails = { ...checklistDetails.toObject(), ...storeDetails?.toObject()?.storeProfile };
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
let scheduleDateTime = dayjs( checklistDetails.submitTime );
|
|
4739
|
-
checklistDetails.submitDate = scheduleDateTime.format( 'DD MMM, YYYY' );
|
|
4740
|
-
checklistDetails.submitTime = scheduleDateTime.format( 'hh:mm A' );
|
|
4741
|
-
if ( clientDetails?.profileDetails?.logo ) {
|
|
4742
|
-
let bucketpath = checklistDetails.client_id + '/logo';
|
|
4743
|
-
|
|
4744
|
-
let params = {
|
|
4745
|
-
Bucket: JSON.parse( process.env.BUCKET )?.assets,
|
|
4746
|
-
file_path: `${bucketpath}/${clientDetails?.profileDetails?.logo}`,
|
|
4747
|
-
};
|
|
4748
|
-
let brandImage = await signedUrl( params );
|
|
4749
|
-
if ( brandImage ) {
|
|
4750
|
-
checklistDetails['brandLogo'] = brandImage;
|
|
4751
|
-
}
|
|
4752
|
-
}
|
|
4753
|
-
checklistDetails['brandName'] = clientDetails?.clientName;
|
|
4754
|
-
checklistDetails.questionAnswers.forEach( ( section ) => {
|
|
4755
|
-
section.questions.forEach( ( question ) => {
|
|
4756
|
-
question.remarks = question.remarks == null || question.remarks == 'null' ? '' : question.remarks;
|
|
4757
|
-
question.userAnswer.forEach( ( answer ) => {
|
|
4758
|
-
if ( answer?.referenceImage?.trim() ) {
|
|
4759
|
-
answer.referenceImage = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.referenceImage;
|
|
4760
|
-
}
|
|
4761
|
-
if ( [ 'Capture Image', 'Capture Video' ].includes( answer.validationType ) && answer?.validationAnswer?.trim() ) {
|
|
4762
|
-
answer.validationAnswer = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.validationAnswer;
|
|
4763
|
-
}
|
|
4764
|
-
if ( answer?.answer?.trim() && [ 'image', 'descriptiveImage', 'multipleImage', 'image/video', 'video' ].includes( question.answerType ) ) {
|
|
4765
|
-
answer.answer = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.answer;
|
|
4766
|
-
}
|
|
4767
|
-
} );
|
|
4768
|
-
} );
|
|
4769
|
-
} );
|
|
4770
|
-
|
|
4771
|
-
checklistDetails['validateType']=[ 'yes/no', 'descriptive', 'multiplechoicesingle', 'multiplechoicemultiple', 'dropdown', 'date', 'linearscale', 'time' ];
|
|
4772
|
-
|
|
4773
|
-
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/template.hbs', 'utf8' );
|
|
4774
|
-
const template = handlebars.compile( templateHtml );
|
|
4775
|
-
const html = template( { data: checklistDetails } );
|
|
4776
|
-
|
|
4777
|
-
// Generate PDF using puppeteer instead of deprecated html-pdf
|
|
4778
|
-
const browser = await puppeteer.launch( {
|
|
4779
|
-
headless: 'new',
|
|
4780
|
-
args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage' ],
|
|
4781
|
-
} );
|
|
4782
|
-
|
|
4783
|
-
const page = await browser.newPage();
|
|
4784
|
-
|
|
4785
|
-
await page.setContent( html, {
|
|
4786
|
-
waitUntil: 'domcontentloaded',
|
|
4787
|
-
} );
|
|
4788
|
-
|
|
4789
|
-
/* -------- WAIT FOR ALL IMAGES TO LOAD -------- */
|
|
4790
|
-
|
|
4791
|
-
await page.evaluate( async () => {
|
|
4792
|
-
const images = Array.from( document.images );
|
|
4793
|
-
|
|
4794
|
-
await Promise.all(
|
|
4795
|
-
images.map( ( img ) => {
|
|
4796
|
-
if ( img.complete ) return;
|
|
4797
|
-
|
|
4798
|
-
return new Promise( ( resolve ) => {
|
|
4799
|
-
img.onload = img.onerror = resolve;
|
|
4800
|
-
} );
|
|
4801
|
-
} ),
|
|
4802
|
-
);
|
|
4803
|
-
} );
|
|
4804
|
-
|
|
4805
|
-
/* ---------------- GENERATE PDF ---------------- */
|
|
4806
|
-
|
|
4807
|
-
const pdfBuffer = await page.pdf( {
|
|
4808
|
-
format: 'A4',
|
|
4809
|
-
printBackground: true,
|
|
4810
|
-
} );
|
|
4811
|
-
|
|
4812
|
-
await browser.close();
|
|
4813
|
-
|
|
4814
|
-
/* ---------------- RESPONSE ---------------- */
|
|
4815
|
-
|
|
4816
|
-
res.setHeader( 'Content-Type', 'application/pdf' );
|
|
4817
|
-
res.setHeader(
|
|
4818
|
-
'Content-Disposition',
|
|
4819
|
-
'attachment; filename=checkListDetails.pdf',
|
|
4820
|
-
);
|
|
4821
|
-
|
|
4822
|
-
return res.end( pdfBuffer );
|
|
4823
|
-
} catch ( e ) {
|
|
4824
|
-
logger.error( { functionName: 'getChecklistQuestionAnswers', error: e } );
|
|
4825
|
-
return res.sendError( e, 500 );
|
|
4826
|
-
}
|
|
4827
|
-
}
|