tango-app-api-trax 3.7.74 → 3.7.75-temp
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 +41 -383
- package/src/controllers/teaxFlag.controller.js +7 -7
- 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,9 +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
|
-
await
|
|
2456
|
-
await
|
|
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 } );
|
|
2457
2259
|
return res.sendSuccess( 'Qr code added successfully' );
|
|
2458
2260
|
|
|
2459
2261
|
const findQuery = [
|
|
@@ -3429,7 +3231,6 @@ export async function questionList( req, res ) {
|
|
|
3429
3231
|
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
3430
3232
|
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
3431
3233
|
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
3432
|
-
sourceCheckList_id: 1,
|
|
3433
3234
|
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
3434
3235
|
allowedStoreLocation: {
|
|
3435
3236
|
$cond: {
|
|
@@ -3455,7 +3256,6 @@ export async function questionList( req, res ) {
|
|
|
3455
3256
|
videoUploadTimeLimit: { $ifNull: [ '$videoUploadTimeLimit', 0 ] },
|
|
3456
3257
|
taskType: { $ifNull: [ '$planoType', '' ] },
|
|
3457
3258
|
streamId: { $ifNull: [ '$streamId', '' ] },
|
|
3458
|
-
export: { $ifNull: [ '$export', '' ] },
|
|
3459
3259
|
},
|
|
3460
3260
|
} );
|
|
3461
3261
|
|
|
@@ -3486,7 +3286,7 @@ export async function questionList( req, res ) {
|
|
|
3486
3286
|
}
|
|
3487
3287
|
|
|
3488
3288
|
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
3489
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3289
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3490
3290
|
let checkvalidation = null;
|
|
3491
3291
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3492
3292
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
@@ -3540,24 +3340,24 @@ export async function questionList( req, res ) {
|
|
|
3540
3340
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].multiReferenceImage = userAns.multiReferenceImage;
|
|
3541
3341
|
}
|
|
3542
3342
|
|
|
3543
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3343
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3544
3344
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3545
3345
|
if ( ansIndex ) {
|
|
3546
3346
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
3547
3347
|
}
|
|
3548
3348
|
}
|
|
3549
|
-
if (
|
|
3349
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3550
3350
|
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
3551
3351
|
// let manswer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3552
3352
|
let manswer = `${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
3553
|
-
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': ''
|
|
3353
|
+
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
3554
3354
|
} else {
|
|
3555
3355
|
|
|
3556
3356
|
}
|
|
3557
3357
|
}
|
|
3558
3358
|
}
|
|
3559
3359
|
}
|
|
3560
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3360
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3561
3361
|
Multianswer.forEach( ( item ) => {
|
|
3562
3362
|
if ( item.validationAnswer == null ) {
|
|
3563
3363
|
item.answer = null;
|
|
@@ -3569,11 +3369,11 @@ export async function questionList( req, res ) {
|
|
|
3569
3369
|
question.Multianswer = Multianswer;
|
|
3570
3370
|
}
|
|
3571
3371
|
}
|
|
3572
|
-
if (
|
|
3372
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3573
3373
|
if ( Multianswer.length ) {
|
|
3574
3374
|
question.Multianswer = Multianswer;
|
|
3575
3375
|
} else {
|
|
3576
|
-
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null
|
|
3376
|
+
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null } );
|
|
3577
3377
|
question.Multianswer = Multianswer;
|
|
3578
3378
|
}
|
|
3579
3379
|
}
|
|
@@ -3618,11 +3418,6 @@ export async function questionList( req, res ) {
|
|
|
3618
3418
|
}
|
|
3619
3419
|
}
|
|
3620
3420
|
|
|
3621
|
-
let checklisDetails = await checklistService.findOne( { _id: getchecklist?.[0]?.sourceCheckList_id }, { export: 1 } );
|
|
3622
|
-
if ( checklisDetails ) {
|
|
3623
|
-
getchecklist[0]['export'] = checklisDetails.export;
|
|
3624
|
-
}
|
|
3625
|
-
|
|
3626
3421
|
return res.sendSuccess( getchecklist );
|
|
3627
3422
|
}
|
|
3628
3423
|
} catch ( e ) {
|
|
@@ -3827,7 +3622,6 @@ export async function taskQuestionList( req, res ) {
|
|
|
3827
3622
|
} else {
|
|
3828
3623
|
logger.info( `v5 => Task Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Task Name: ${getchecklist[0].checkListName}` );
|
|
3829
3624
|
let bucket = JSON.parse( process.env.BUCKET );
|
|
3830
|
-
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3831
3625
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3832
3626
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
3833
3627
|
let Multianswer = [];
|
|
@@ -3864,14 +3658,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3864
3658
|
}
|
|
3865
3659
|
}
|
|
3866
3660
|
|
|
3867
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3661
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3868
3662
|
let checkvalidation = null;
|
|
3869
3663
|
if ( answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3870
|
-
|
|
3871
|
-
checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3872
|
-
} else {
|
|
3873
|
-
checkvalidation = answer.validationAnswer;
|
|
3874
|
-
}
|
|
3664
|
+
checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3875
3665
|
}
|
|
3876
3666
|
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3877
3667
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
@@ -3892,7 +3682,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3892
3682
|
Bucket: bucket.sop,
|
|
3893
3683
|
} );
|
|
3894
3684
|
}
|
|
3895
|
-
if ( [ 'image', 'descriptiveImage', 'video'
|
|
3685
|
+
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3896
3686
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = await signedUrl( {
|
|
3897
3687
|
file_path: decodeURIComponent( userAns.answer ),
|
|
3898
3688
|
Bucket: bucket.sop,
|
|
@@ -3904,23 +3694,23 @@ export async function taskQuestionList( req, res ) {
|
|
|
3904
3694
|
Bucket: bucket.sop,
|
|
3905
3695
|
} );
|
|
3906
3696
|
}
|
|
3907
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3697
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3908
3698
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3909
|
-
if ( ansIndex
|
|
3699
|
+
if ( ansIndex ) {
|
|
3910
3700
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
3911
3701
|
}
|
|
3912
3702
|
}
|
|
3913
|
-
if ( question.answerType == 'multipleImage'
|
|
3703
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3914
3704
|
if ( userAns && userAns.answer && userAns.answer != '' ) {
|
|
3915
|
-
let manswer =
|
|
3916
|
-
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': '' } );
|
|
3917
3707
|
} else {
|
|
3918
3708
|
|
|
3919
3709
|
}
|
|
3920
3710
|
}
|
|
3921
3711
|
}
|
|
3922
3712
|
}
|
|
3923
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
3713
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3924
3714
|
Multianswer.forEach( ( item ) => {
|
|
3925
3715
|
if ( item.validationAnswer == null ) {
|
|
3926
3716
|
item.answer = null;
|
|
@@ -3932,11 +3722,11 @@ export async function taskQuestionList( req, res ) {
|
|
|
3932
3722
|
question.Multianswer = Multianswer;
|
|
3933
3723
|
}
|
|
3934
3724
|
}
|
|
3935
|
-
if ( question.answerType == 'multipleImage'
|
|
3725
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
3936
3726
|
if ( Multianswer.length ) {
|
|
3937
3727
|
question.Multianswer = Multianswer;
|
|
3938
3728
|
} else {
|
|
3939
|
-
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null
|
|
3729
|
+
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null } );
|
|
3940
3730
|
question.Multianswer = Multianswer;
|
|
3941
3731
|
}
|
|
3942
3732
|
}
|
|
@@ -4023,9 +3813,8 @@ export async function uploadAnswerImage( req, res ) {
|
|
|
4023
3813
|
if ( req.files && req.files.answerImage ) {
|
|
4024
3814
|
let imageUrl;
|
|
4025
3815
|
let filePath = `${folder}/${req.user.clientId}/${date}/${input.checklistId}/${input.sectionName.replace( ' ', '' )}/${input.questionNo}/`;
|
|
4026
|
-
const ext = path.extname( req.files.answerImage.name ).slice( 1 );
|
|
4027
3816
|
let params = {
|
|
4028
|
-
fileName: `${Date.now()}-${Math.floor( 1000 + Math.random() * 9000 )}.${
|
|
3817
|
+
fileName: `${Date.now()}-${Math.floor( 1000 + Math.random() * 9000 )}.${req.files.answerImage.name.split( '.' )[1]}`,
|
|
4029
3818
|
Key: filePath,
|
|
4030
3819
|
Bucket: bucket.sop,
|
|
4031
3820
|
body: req.files.answerImage.data,
|
|
@@ -4450,7 +4239,6 @@ export async function questionListV1( req, res ) {
|
|
|
4450
4239
|
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
4451
4240
|
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
4452
4241
|
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
4453
|
-
sourceCheckList_id: { $ifNull: [ '$sourceCheckList_id', '' ] },
|
|
4454
4242
|
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
4455
4243
|
allowedStoreLocation: {
|
|
4456
4244
|
$cond: {
|
|
@@ -4506,7 +4294,7 @@ export async function questionListV1( req, res ) {
|
|
|
4506
4294
|
}
|
|
4507
4295
|
|
|
4508
4296
|
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
4509
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4297
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4510
4298
|
let checkvalidation = null;
|
|
4511
4299
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
4512
4300
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
@@ -4558,13 +4346,13 @@ export async function questionListV1( req, res ) {
|
|
|
4558
4346
|
|
|
4559
4347
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].multiReferenceImage = userAns.multiReferenceImage;
|
|
4560
4348
|
}
|
|
4561
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4349
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4562
4350
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
4563
4351
|
if ( ansIndex ) {
|
|
4564
4352
|
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
4565
4353
|
}
|
|
4566
4354
|
}
|
|
4567
|
-
if ( question.answerType == 'multipleImage'
|
|
4355
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
4568
4356
|
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
4569
4357
|
let manswer = `${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
4570
4358
|
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
@@ -4574,7 +4362,7 @@ export async function questionListV1( req, res ) {
|
|
|
4574
4362
|
}
|
|
4575
4363
|
}
|
|
4576
4364
|
}
|
|
4577
|
-
if ( question.answerType == 'multiplechoicemultiple'
|
|
4365
|
+
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
4578
4366
|
Multianswer.forEach( ( item ) => {
|
|
4579
4367
|
if ( item.validationAnswer == null ) {
|
|
4580
4368
|
item.answer = null;
|
|
@@ -4586,7 +4374,7 @@ export async function questionListV1( req, res ) {
|
|
|
4586
4374
|
question.Multianswer = Multianswer;
|
|
4587
4375
|
}
|
|
4588
4376
|
}
|
|
4589
|
-
if ( question.answerType == 'multipleImage'
|
|
4377
|
+
if ( question.answerType == 'multipleImage' ) {
|
|
4590
4378
|
if ( Multianswer.length ) {
|
|
4591
4379
|
question.Multianswer = Multianswer;
|
|
4592
4380
|
} else {
|
|
@@ -4635,11 +4423,6 @@ export async function questionListV1( req, res ) {
|
|
|
4635
4423
|
}
|
|
4636
4424
|
}
|
|
4637
4425
|
|
|
4638
|
-
let checklisDetails = await checklistService.findOne( { _id: getchecklist?.[0]?.sourceCheckList_id }, { export: 1 } );
|
|
4639
|
-
if ( checklisDetails ) {
|
|
4640
|
-
getchecklist[0]['export'] = checklisDetails.export;
|
|
4641
|
-
}
|
|
4642
|
-
|
|
4643
4426
|
return res.sendSuccess( getchecklist );
|
|
4644
4427
|
}
|
|
4645
4428
|
} catch ( e ) {
|
|
@@ -4702,128 +4485,3 @@ export async function chunkUpload( req, res ) {
|
|
|
4702
4485
|
return res.sendError( e, 500 );
|
|
4703
4486
|
}
|
|
4704
4487
|
}
|
|
4705
|
-
|
|
4706
|
-
export async function downloadChecklist( req, res ) {
|
|
4707
|
-
try {
|
|
4708
|
-
let requestData = req.body;
|
|
4709
|
-
|
|
4710
|
-
if ( !requestData.checklistId ) {
|
|
4711
|
-
return res.sendError( 'checklistId is Required', 400 );
|
|
4712
|
-
}
|
|
4713
|
-
|
|
4714
|
-
let checklistDetails;
|
|
4715
|
-
|
|
4716
|
-
if ( requestData.type == 'checklist' ) {
|
|
4717
|
-
checklistDetails = await processedchecklist.findOne( { _id: requestData.checklistId, checklistStatus: 'submit' } );
|
|
4718
|
-
} else {
|
|
4719
|
-
checklistDetails = await processedTask.findOne( { _id: requestData.checklistId, checklistStatus: 'submit' } );
|
|
4720
|
-
}
|
|
4721
|
-
|
|
4722
|
-
if ( !checklistDetails ) {
|
|
4723
|
-
return res.sendError( 'No data found', 204 );
|
|
4724
|
-
}
|
|
4725
|
-
|
|
4726
|
-
let storeDetails = await storeService.findOne( { storeId: checklistDetails.store_id }, { storeProfile: 1 } );
|
|
4727
|
-
if ( !storeDetails ) {
|
|
4728
|
-
return res.sendError( 'No data found', 204 );
|
|
4729
|
-
}
|
|
4730
|
-
|
|
4731
|
-
let clientDetails = await clientService.findOne( { clientId: checklistDetails.client_id } );
|
|
4732
|
-
|
|
4733
|
-
if ( !clientDetails ) {
|
|
4734
|
-
return res.sendError( 'No client found', 204 );
|
|
4735
|
-
}
|
|
4736
|
-
|
|
4737
|
-
checklistDetails = { ...checklistDetails.toObject(), ...storeDetails?.toObject()?.storeProfile };
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
let scheduleDateTime = dayjs( checklistDetails.submitTime );
|
|
4741
|
-
checklistDetails.submitDate = scheduleDateTime.format( 'DD MMM, YYYY' );
|
|
4742
|
-
checklistDetails.submitTime = scheduleDateTime.format( 'hh:mm A' );
|
|
4743
|
-
if ( clientDetails?.profileDetails?.logo ) {
|
|
4744
|
-
let bucketpath = checklistDetails.client_id + '/logo';
|
|
4745
|
-
|
|
4746
|
-
let params = {
|
|
4747
|
-
Bucket: JSON.parse( process.env.BUCKET )?.assets,
|
|
4748
|
-
file_path: `${bucketpath}/${clientDetails?.profileDetails?.logo}`,
|
|
4749
|
-
};
|
|
4750
|
-
let brandImage = await signedUrl( params );
|
|
4751
|
-
if ( brandImage ) {
|
|
4752
|
-
checklistDetails['brandLogo'] = brandImage;
|
|
4753
|
-
}
|
|
4754
|
-
}
|
|
4755
|
-
checklistDetails['brandName'] = clientDetails?.clientName;
|
|
4756
|
-
checklistDetails.questionAnswers.forEach( ( section ) => {
|
|
4757
|
-
section.questions.forEach( ( question ) => {
|
|
4758
|
-
question.remarks = question.remarks == null || question.remarks == 'null' ? '' : question.remarks;
|
|
4759
|
-
question.userAnswer.forEach( ( answer ) => {
|
|
4760
|
-
if ( answer?.referenceImage?.trim() ) {
|
|
4761
|
-
answer.referenceImage = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.referenceImage;
|
|
4762
|
-
}
|
|
4763
|
-
if ( [ 'Capture Image', 'Capture Video' ].includes( answer.validationType ) && answer?.validationAnswer?.trim() ) {
|
|
4764
|
-
answer.validationAnswer = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.validationAnswer;
|
|
4765
|
-
}
|
|
4766
|
-
if ( answer?.answer?.trim() && [ 'image', 'descriptiveImage', 'multipleImage', 'image/video', 'video' ].includes( question.answerType ) ) {
|
|
4767
|
-
answer.answer = 'https://d1r0hc2sskgmri.cloudfront.net/'+answer.answer;
|
|
4768
|
-
}
|
|
4769
|
-
} );
|
|
4770
|
-
} );
|
|
4771
|
-
} );
|
|
4772
|
-
|
|
4773
|
-
checklistDetails['validateType']=[ 'yes/no', 'descriptive', 'multiplechoicesingle', 'multiplechoicemultiple', 'dropdown', 'date', 'linearscale', 'time' ];
|
|
4774
|
-
|
|
4775
|
-
const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/template.hbs', 'utf8' );
|
|
4776
|
-
const template = handlebars.compile( templateHtml );
|
|
4777
|
-
const html = template( { data: checklistDetails } );
|
|
4778
|
-
|
|
4779
|
-
// Generate PDF using puppeteer instead of deprecated html-pdf
|
|
4780
|
-
const browser = await puppeteer.launch( {
|
|
4781
|
-
headless: 'new',
|
|
4782
|
-
args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage' ],
|
|
4783
|
-
} );
|
|
4784
|
-
|
|
4785
|
-
const page = await browser.newPage();
|
|
4786
|
-
|
|
4787
|
-
await page.setContent( html, {
|
|
4788
|
-
waitUntil: 'domcontentloaded',
|
|
4789
|
-
} );
|
|
4790
|
-
|
|
4791
|
-
/* -------- WAIT FOR ALL IMAGES TO LOAD -------- */
|
|
4792
|
-
|
|
4793
|
-
await page.evaluate( async () => {
|
|
4794
|
-
const images = Array.from( document.images );
|
|
4795
|
-
|
|
4796
|
-
await Promise.all(
|
|
4797
|
-
images.map( ( img ) => {
|
|
4798
|
-
if ( img.complete ) return;
|
|
4799
|
-
|
|
4800
|
-
return new Promise( ( resolve ) => {
|
|
4801
|
-
img.onload = img.onerror = resolve;
|
|
4802
|
-
} );
|
|
4803
|
-
} ),
|
|
4804
|
-
);
|
|
4805
|
-
} );
|
|
4806
|
-
|
|
4807
|
-
/* ---------------- GENERATE PDF ---------------- */
|
|
4808
|
-
|
|
4809
|
-
const pdfBuffer = await page.pdf( {
|
|
4810
|
-
format: 'A4',
|
|
4811
|
-
printBackground: true,
|
|
4812
|
-
} );
|
|
4813
|
-
|
|
4814
|
-
await browser.close();
|
|
4815
|
-
|
|
4816
|
-
/* ---------------- RESPONSE ---------------- */
|
|
4817
|
-
|
|
4818
|
-
res.setHeader( 'Content-Type', 'application/pdf' );
|
|
4819
|
-
res.setHeader(
|
|
4820
|
-
'Content-Disposition',
|
|
4821
|
-
'attachment; filename=checkListDetails.pdf',
|
|
4822
|
-
);
|
|
4823
|
-
|
|
4824
|
-
return res.end( pdfBuffer );
|
|
4825
|
-
} catch ( e ) {
|
|
4826
|
-
logger.error( { functionName: 'getChecklistQuestionAnswers', error: e } );
|
|
4827
|
-
return res.sendError( e, 500 );
|
|
4828
|
-
}
|
|
4829
|
-
}
|