tango-app-api-trax 3.8.16 → 3.8.17-nike
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 -2
- package/src/controllers/download.controller.js +19 -19
- package/src/controllers/gallery.controller.js +88 -25
- package/src/controllers/handlebar-helper.js +1 -0
- package/src/controllers/internalTrax.controller.js +1017 -14
- package/src/controllers/mobileTrax.controller.js +334 -201
- package/src/controllers/teaxFlag.controller.js +5 -5
- package/src/controllers/trax.controller.js +6 -2
- package/src/hbs/recurringFlag.hbs +250 -0
- package/src/hbs/template.hbs +47 -32
- package/src/hbs/visit-checklist.hbs +107 -62
- package/src/hbs/weeklyWrap.hbs +218 -0
- package/src/routes/internalTraxApi.router.js +4 -0
- package/src/services/recurringFlagTracker.service.js +33 -0
- package/src/utils/visitChecklistPdf.utils.js +6 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger, signedUrl, fileUpload, getOtp, sendEmailWithSES, getUuid, insertOpenSearchData, listFileByPath, getObject, deleteFiles } from 'tango-app-api-middleware';
|
|
1
|
+
import { logger, signedUrl, fileUpload, getOtp, sendEmailWithSES, getUuid, insertOpenSearchData, listFileByPath, getObject, deleteFiles, sendMessageToQueue } from 'tango-app-api-middleware';
|
|
2
2
|
import * as processedchecklist from '../services/processedchecklist.services.js';
|
|
3
3
|
import * as processedtask from '../services/processedTaskList.service.js';
|
|
4
4
|
import * as PCLconfig from '../services/processedchecklistconfig.services.js';
|
|
@@ -26,6 +26,7 @@ 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
|
+
import * as recurringFlagTracker from '../services/recurringFlagTracker.service.js';
|
|
29
30
|
dayjs.extend( isSameOrBefore );
|
|
30
31
|
import puppeteer from 'puppeteer';
|
|
31
32
|
import handlebars from './handlebar-helper.js';
|
|
@@ -117,7 +118,7 @@ export async function startChecklist( req, res ) {
|
|
|
117
118
|
$and: [
|
|
118
119
|
{ _id: new ObjectId( requestData.processedcheckListId ) },
|
|
119
120
|
{ userId: req.user._id },
|
|
120
|
-
{ date_string: requestData.date },
|
|
121
|
+
{ $or: [ { date_string: requestData.date }, { redoStatus: true } ] },
|
|
121
122
|
],
|
|
122
123
|
},
|
|
123
124
|
} );
|
|
@@ -233,15 +234,15 @@ export async function startChecklist( req, res ) {
|
|
|
233
234
|
},
|
|
234
235
|
} );
|
|
235
236
|
let getupdatedchecklist = await processedchecklist.aggregate( findQuery );
|
|
236
|
-
let bucket = JSON.parse( process.env.BUCKET );
|
|
237
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
237
238
|
getupdatedchecklist[0].questionAnswers.forEach( ( section ) => {
|
|
238
239
|
section.questions.forEach( async ( question ) => {
|
|
239
240
|
if ( question.questionReferenceImage && question.questionReferenceImage!='' ) {
|
|
240
|
-
question.questionReferenceImage =
|
|
241
|
+
question.questionReferenceImage = `${cdnurl.TraxAnswerCDN}${question.questionReferenceImage}`;
|
|
241
242
|
}
|
|
242
243
|
question.answers.forEach( async ( answer ) => {
|
|
243
244
|
if ( answer.referenceImage != '' ) {
|
|
244
|
-
answer.referenceImage =
|
|
245
|
+
answer.referenceImage = `${cdnurl.TraxAnswerCDN}${answer.referenceImage}`;
|
|
245
246
|
}
|
|
246
247
|
} );
|
|
247
248
|
} );
|
|
@@ -466,19 +467,16 @@ export async function startTask( req, res ) {
|
|
|
466
467
|
} );
|
|
467
468
|
const getUpdatedTask = await processedTask.aggregate( findQuery );
|
|
468
469
|
|
|
469
|
-
|
|
470
|
+
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
470
471
|
if ( !( task.checkListFrom && task.checkListFrom == 'api' ) ) {
|
|
471
|
-
const bucket = JSON.parse( process.env.BUCKET );
|
|
472
|
+
// const bucket = JSON.parse( process.env.BUCKET );
|
|
472
473
|
await Promise.all(
|
|
473
474
|
getUpdatedTask[0].questionAnswers.map( ( section ) =>
|
|
474
475
|
section.questions.map( async ( question ) => {
|
|
475
476
|
if ( question.questionReferenceImage.length > 0 ) {
|
|
476
477
|
question.questionReferenceImage = await Promise.all(
|
|
477
478
|
question.questionReferenceImage.map( async ( image ) => {
|
|
478
|
-
return
|
|
479
|
-
Bucket: bucket.sop,
|
|
480
|
-
file_path: decodeURIComponent( image ),
|
|
481
|
-
} );
|
|
479
|
+
return `${cdnurl.TraxAnswerCDN}${image}`;
|
|
482
480
|
} ),
|
|
483
481
|
);
|
|
484
482
|
}
|
|
@@ -488,10 +486,7 @@ export async function startTask( req, res ) {
|
|
|
488
486
|
if ( answer.referenceImage.length > 0 ) {
|
|
489
487
|
answer.referenceImage = await Promise.all(
|
|
490
488
|
answer.referenceImage.map( async ( image ) => {
|
|
491
|
-
return
|
|
492
|
-
Bucket: bucket.sop,
|
|
493
|
-
file_path: decodeURIComponent( image ),
|
|
494
|
-
} );
|
|
489
|
+
return `${cdnurl.TraxAnswerCDN}${image}`;
|
|
495
490
|
} ),
|
|
496
491
|
);
|
|
497
492
|
}
|
|
@@ -1087,12 +1082,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1087
1082
|
try {
|
|
1088
1083
|
let requestData = req.body;
|
|
1089
1084
|
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
1090
|
-
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
1085
|
+
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1, redoEdit: 1 } );
|
|
1091
1086
|
let reqAnswers = requestData.questionAnswers;
|
|
1092
1087
|
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1093
1088
|
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1094
1089
|
|
|
1095
1090
|
if ( requestData.submittype == 'submit' ) {
|
|
1091
|
+
if ( getChecklistQA?.redoEdit ) {
|
|
1092
|
+
requestData.submittype = 'draft';
|
|
1093
|
+
}
|
|
1096
1094
|
reqAnswers.forEach( ( reqA ) => {
|
|
1097
1095
|
if ( ![ 'multiplechoicemultiple', 'multipleImage', 'image/video' ].includes( reqA?.answerType ) && ( reqA.answerType == 'dropDown' && !reqA.allowMultiple ) ) {
|
|
1098
1096
|
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
@@ -1179,24 +1177,29 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1179
1177
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1180
1178
|
let qaans = qaAnswers[j].answers;
|
|
1181
1179
|
let yn = [];
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
if (
|
|
1185
|
-
if (
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
splitImgUrl.
|
|
1191
|
-
|
|
1180
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1181
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1182
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1183
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1184
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1185
|
+
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1186
|
+
if ( validateAns.length ) {
|
|
1187
|
+
let splitImgUrl = validateAns.split( '/' );
|
|
1188
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1189
|
+
splitImgUrl.splice( 0, 3 );
|
|
1190
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1191
|
+
}
|
|
1192
1192
|
}
|
|
1193
1193
|
}
|
|
1194
|
+
} else {
|
|
1195
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1196
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1194
1197
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1199
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1200
|
+
}
|
|
1201
|
+
yn.push( qaans[k] );
|
|
1198
1202
|
}
|
|
1199
|
-
yn.push( qaans[k] );
|
|
1200
1203
|
}
|
|
1201
1204
|
}
|
|
1202
1205
|
let structure = {};
|
|
@@ -1236,39 +1239,44 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1236
1239
|
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
|
|
1237
1240
|
let qaans = qaAnswers[j].answers;
|
|
1238
1241
|
let ms = [];
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
if (
|
|
1242
|
-
if (
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
splitImgUrl.
|
|
1248
|
-
|
|
1242
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1243
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1244
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1245
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1246
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1247
|
+
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1248
|
+
if ( validationAnswer.length ) {
|
|
1249
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1250
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1251
|
+
splitImgUrl.splice( 0, 3 );
|
|
1252
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1253
|
+
}
|
|
1249
1254
|
}
|
|
1250
1255
|
}
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1256
|
+
} else {
|
|
1257
|
+
if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
|
|
1258
|
+
qaans[k]['validationImage']=[];
|
|
1259
|
+
if ( requestSection[i].validationImage.length ) {
|
|
1260
|
+
for ( let image of requestSection[i].validationImage ) {
|
|
1261
|
+
let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
|
|
1262
|
+
if ( validationAnswer.length ) {
|
|
1263
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1264
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1265
|
+
splitImgUrl.splice( 0, 3 );
|
|
1266
|
+
qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1265
1270
|
}
|
|
1266
1271
|
}
|
|
1272
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1273
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1267
1274
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1275
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1276
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1277
|
+
}
|
|
1278
|
+
ms.push( qaans[k] );
|
|
1270
1279
|
}
|
|
1271
|
-
ms.push( qaans[k] );
|
|
1272
1280
|
}
|
|
1273
1281
|
}
|
|
1274
1282
|
let structure = {};
|
|
@@ -1309,30 +1317,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1309
1317
|
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
|
|
1310
1318
|
let qaans = qaAnswers[j].answers;
|
|
1311
1319
|
let mcmo = [];
|
|
1312
|
-
|
|
1313
|
-
let
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
if (
|
|
1317
|
-
if ( separatedArray[s].
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1320
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1321
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1322
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1323
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1324
|
+
if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
|
|
1325
|
+
if ( ( getChecklistQA?.redoEdit && qaans[k].redo == separatedArray[s].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1326
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1327
|
+
if ( separatedArray[s].validationAnswer ) {
|
|
1328
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1329
|
+
if ( validationAnswer.length ) {
|
|
1330
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1331
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1332
|
+
splitImgUrl.splice( 0, 3 );
|
|
1333
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1324
1336
|
}
|
|
1337
|
+
} else {
|
|
1338
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1339
|
+
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1340
|
+
}
|
|
1341
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1342
|
+
qaans[k].runAIData = separatedArray[s].runAIData;
|
|
1325
1343
|
}
|
|
1326
1344
|
}
|
|
1327
|
-
|
|
1328
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1329
|
-
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1345
|
+
mcmo.push( qaans[k] );
|
|
1330
1346
|
}
|
|
1331
|
-
|
|
1332
|
-
mcmo.push( qaans[k] );
|
|
1333
1347
|
}
|
|
1334
1348
|
}
|
|
1335
1349
|
}
|
|
1350
|
+
qaAnswers[j].answers.forEach( ( ele ) => {
|
|
1351
|
+
if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1352
|
+
ele.redo = false;
|
|
1353
|
+
}
|
|
1354
|
+
} );
|
|
1355
|
+
|
|
1336
1356
|
let structure = {};
|
|
1337
1357
|
structure.qno = qaAnswers[j].qno;
|
|
1338
1358
|
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
@@ -1371,37 +1391,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1371
1391
|
} else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
|
|
1372
1392
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1373
1393
|
let mcmi = [];
|
|
1394
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1374
1395
|
// for (let k = 0; k < qaans.length; k++) {
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1396
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1397
|
+
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1398
|
+
let newAnswer = {};
|
|
1399
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1400
|
+
if ( validationAnswer.length ) {
|
|
1401
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1402
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1403
|
+
splitImgUrl.splice( 0, 3 );
|
|
1404
|
+
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1405
|
+
}
|
|
1384
1406
|
}
|
|
1385
|
-
}
|
|
1386
1407
|
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1408
|
+
newAnswer.answeroptionNumber = 0;
|
|
1409
|
+
newAnswer.sopFlag = false;
|
|
1410
|
+
newAnswer.validation = false;
|
|
1411
|
+
newAnswer.validationType = '';
|
|
1412
|
+
newAnswer.referenceImage = '';
|
|
1413
|
+
newAnswer.allowUploadfromGallery = false;
|
|
1414
|
+
newAnswer.descriptivetype = '';
|
|
1415
|
+
newAnswer.showLinked = false;
|
|
1416
|
+
newAnswer.linkedQuestion = 0;
|
|
1417
|
+
newAnswer.nestedQuestion = [];
|
|
1418
|
+
newAnswer.index = s;
|
|
1419
|
+
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1420
|
+
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1421
|
+
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1422
|
+
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1423
|
+
newAnswer.answerType = separatedArray[s].answerType;
|
|
1424
|
+
}
|
|
1425
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1426
|
+
newAnswer.runAIData = separatedArray[s].runAIData;
|
|
1427
|
+
}
|
|
1428
|
+
mcmi.push( newAnswer );
|
|
1403
1429
|
}
|
|
1404
|
-
mcmi.push( newAnswer );
|
|
1405
1430
|
}
|
|
1406
1431
|
}
|
|
1407
1432
|
// }
|
|
@@ -1441,71 +1466,76 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1441
1466
|
newArray.push( structure );
|
|
1442
1467
|
} else {
|
|
1443
1468
|
let des = [];
|
|
1444
|
-
if (
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
if ( validationAnswer.length ) {
|
|
1450
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1451
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1452
|
-
splitImgUrl.splice( 0, 3 );
|
|
1453
|
-
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1469
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1470
|
+
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1471
|
+
let validationAnswer = '';
|
|
1472
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
1473
|
+
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1454
1474
|
}
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1475
|
+
if ( validationAnswer.length ) {
|
|
1476
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1477
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1478
|
+
splitImgUrl.splice( 0, 3 );
|
|
1479
|
+
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
let ansstructure = {
|
|
1483
|
+
answer: requestSection[i].answer,
|
|
1484
|
+
answeroptionNumber: 1,
|
|
1485
|
+
sopFlag: false,
|
|
1486
|
+
validation: false,
|
|
1487
|
+
validationType: '',
|
|
1488
|
+
validationAnswer: '',
|
|
1489
|
+
referenceImage: qaAnswers[j].answers[0].referenceImage || '',
|
|
1490
|
+
multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
|
|
1491
|
+
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1492
|
+
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1493
|
+
runAI: qaAnswers[j].answers[0]?.runAI || false,
|
|
1494
|
+
runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
|
|
1495
|
+
runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
|
|
1496
|
+
};
|
|
1497
|
+
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1498
|
+
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1474
1499
|
if ( qaAnswers[j].compliance ) {
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1500
|
+
if ( qaAnswers[j].compliance ) {
|
|
1501
|
+
let ansArray = requestSection[i].answer.split( ',' );
|
|
1502
|
+
if ( ansArray.includes( '-' ) ) {
|
|
1503
|
+
ansArray = requestSection[i].answer.split( '-' );
|
|
1504
|
+
}
|
|
1505
|
+
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 ) ) {
|
|
1506
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1507
|
+
} 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 ) ) {
|
|
1508
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1509
|
+
} 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]?.endDate ) {
|
|
1510
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1511
|
+
} else {
|
|
1512
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1513
|
+
}
|
|
1478
1514
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
if ( qaAnswers[j].answerType == 'linearscale' ) {
|
|
1518
|
+
if ( qaAnswers[j].compliance ) {
|
|
1519
|
+
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
1520
|
+
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1484
1521
|
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1485
1522
|
} else {
|
|
1486
1523
|
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1487
1524
|
}
|
|
1488
1525
|
}
|
|
1526
|
+
ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
|
|
1527
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1528
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1489
1529
|
}
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
1494
|
-
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1495
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1496
|
-
} else {
|
|
1497
|
-
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1498
|
-
}
|
|
1530
|
+
if ( qaAnswers[j].answerType == 'image' ) {
|
|
1531
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1532
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1499
1533
|
}
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
if ( qaAnswers[j].answerType == 'image' ) {
|
|
1505
|
-
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1506
|
-
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1534
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1535
|
+
ansstructure.runAIData = requestSection[i].runAIData;
|
|
1536
|
+
}
|
|
1537
|
+
des.push( ansstructure );
|
|
1507
1538
|
}
|
|
1508
|
-
des.push( ansstructure );
|
|
1509
1539
|
}
|
|
1510
1540
|
let structure = {};
|
|
1511
1541
|
structure.qno = qaAnswers[j].qno;
|
|
@@ -1937,7 +1967,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
1937
1967
|
let des = [];
|
|
1938
1968
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1939
1969
|
let validationAnswer = '';
|
|
1940
|
-
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1970
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
1941
1971
|
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1942
1972
|
}
|
|
1943
1973
|
if ( validationAnswer.length ) {
|
|
@@ -2034,6 +2064,102 @@ function QuestionFlag( req, res ) {
|
|
|
2034
2064
|
}
|
|
2035
2065
|
}
|
|
2036
2066
|
|
|
2067
|
+
async function updateRecurringFlagTracker( processedChecklist, questionAnswers, currentDateTime ) {
|
|
2068
|
+
try {
|
|
2069
|
+
if ( !processedChecklist?.sourceCheckList_id ) return;
|
|
2070
|
+
|
|
2071
|
+
const isUserBased = processedChecklist?.coverage === 'user';
|
|
2072
|
+
const storeId = isUserBased ? '' : ( processedChecklist?.store_id || '' );
|
|
2073
|
+
const userId = isUserBased ? ( processedChecklist?.userId ? String( processedChecklist.userId ) : ( processedChecklist?.userEmail || '' ) ) : '';
|
|
2074
|
+
if ( !isUserBased && !storeId ) return;
|
|
2075
|
+
if ( isUserBased && !userId ) return;
|
|
2076
|
+
|
|
2077
|
+
const today = currentDateTime ? currentDateTime.format( 'YYYY-MM-DD' ) : dayjs().format( 'YYYY-MM-DD' );
|
|
2078
|
+
const yesterday = dayjs( today, 'YYYY-MM-DD' ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
|
|
2079
|
+
|
|
2080
|
+
const trackerKeyBase = {
|
|
2081
|
+
client_id: processedChecklist.client_id,
|
|
2082
|
+
sourceCheckList_id: processedChecklist.sourceCheckList_id,
|
|
2083
|
+
...( isUserBased ) ? { user_id: userId } : { store_id: storeId },
|
|
2084
|
+
};
|
|
2085
|
+
|
|
2086
|
+
const existingRows = await recurringFlagTracker.find( trackerKeyBase, { section_id: 1, qno: 1, consecutiveCount: 1, lastFlaggedDate: 1 } );
|
|
2087
|
+
const existingMap = new Map();
|
|
2088
|
+
for ( const r of existingRows ) {
|
|
2089
|
+
existingMap.set( `${r.section_id || ''}::${r.qno || ''}`, r );
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
const ops = [];
|
|
2093
|
+
|
|
2094
|
+
( questionAnswers || [] ).forEach( ( section ) => {
|
|
2095
|
+
( section?.questions || [] ).forEach( ( question ) => {
|
|
2096
|
+
const sectionId = section?.section_id || '';
|
|
2097
|
+
const qno = question?.qno || '';
|
|
2098
|
+
if ( qno === '' ) return;
|
|
2099
|
+
|
|
2100
|
+
const flaggedNow = Array.isArray( question?.userAnswer ) && question.userAnswer.some( ( a ) => a?.sopFlag === true );
|
|
2101
|
+
const key = `${sectionId}::${qno}`;
|
|
2102
|
+
const existing = existingMap.get( key );
|
|
2103
|
+
console.log( flaggedNow, 'test' );
|
|
2104
|
+
if ( flaggedNow ) {
|
|
2105
|
+
let newCount;
|
|
2106
|
+
if ( !existing ) {
|
|
2107
|
+
newCount = 1;
|
|
2108
|
+
} else if ( existing.lastFlaggedDate === today ) {
|
|
2109
|
+
// Multi-submit on same day: already counted, no-op.
|
|
2110
|
+
return;
|
|
2111
|
+
} else if ( existing.lastFlaggedDate === yesterday ) {
|
|
2112
|
+
newCount = ( existing.consecutiveCount || 0 ) + 1;
|
|
2113
|
+
} else {
|
|
2114
|
+
// Gap broke the streak — fresh start.
|
|
2115
|
+
newCount = 1;
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
ops.push( {
|
|
2119
|
+
updateOne: {
|
|
2120
|
+
filter: { ...trackerKeyBase, section_id: sectionId, qno },
|
|
2121
|
+
update: {
|
|
2122
|
+
$set: {
|
|
2123
|
+
coverage: isUserBased ? 'user' : 'store',
|
|
2124
|
+
checkListName: processedChecklist.checkListName,
|
|
2125
|
+
storeName: isUserBased ? '' : ( processedChecklist.storeName || '' ),
|
|
2126
|
+
userName: processedChecklist.userName || '',
|
|
2127
|
+
userEmail: processedChecklist.userEmail || '',
|
|
2128
|
+
sectionName: section?.sectionName || '',
|
|
2129
|
+
qname: question?.qname || '',
|
|
2130
|
+
consecutiveCount: newCount,
|
|
2131
|
+
lastFlaggedDate: today,
|
|
2132
|
+
lastSubmittedBy: processedChecklist.userName || processedChecklist.userEmail || '--',
|
|
2133
|
+
lastSubmissionDate: currentDateTime ? currentDateTime.format( 'hh:mm A, DD MMM YYYY' ) : today,
|
|
2134
|
+
},
|
|
2135
|
+
},
|
|
2136
|
+
upsert: true,
|
|
2137
|
+
},
|
|
2138
|
+
} );
|
|
2139
|
+
} else if ( existing && ( existing.consecutiveCount || 0 ) > 0 ) {
|
|
2140
|
+
// Question answered correctly today — break the streak.
|
|
2141
|
+
ops.push( {
|
|
2142
|
+
updateOne: {
|
|
2143
|
+
filter: { ...trackerKeyBase, section_id: sectionId, qno },
|
|
2144
|
+
update: { $set: { lastFlaggedDate: today } },
|
|
2145
|
+
},
|
|
2146
|
+
} );
|
|
2147
|
+
}
|
|
2148
|
+
} );
|
|
2149
|
+
} );
|
|
2150
|
+
if ( ops.length ) {
|
|
2151
|
+
try {
|
|
2152
|
+
let data = await recurringFlagTracker.bulkWrite( ops, { ordered: false } );
|
|
2153
|
+
console.log( 'recurringFlagTracker bulkWrite result', data );
|
|
2154
|
+
} catch ( bulkErr ) {
|
|
2155
|
+
logger.error( { function: 'updateRecurringFlagTracker.bulkWrite', code: bulkErr?.code, message: bulkErr?.message, writeErrors: bulkErr?.writeErrors } );
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
} catch ( error ) {
|
|
2159
|
+
logger.error( { function: 'updateRecurringFlagTracker', error } );
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2037
2163
|
export async function submitChecklist( req, res ) {
|
|
2038
2164
|
try {
|
|
2039
2165
|
let requestData = req.body;
|
|
@@ -2081,6 +2207,7 @@ export async function submitChecklist( req, res ) {
|
|
|
2081
2207
|
let flagCount = QuestionFlag( req, res );
|
|
2082
2208
|
updateData.questionFlag = flagCount;
|
|
2083
2209
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
2210
|
+
updateData.redoEdit = false;
|
|
2084
2211
|
if ( requestData.deviceDetails && requestData.deviceDetails != '' ) {
|
|
2085
2212
|
updateData.deviceDetails =JSON.parse( requestData.deviceDetails );
|
|
2086
2213
|
}
|
|
@@ -2169,6 +2296,10 @@ export async function submitChecklist( req, res ) {
|
|
|
2169
2296
|
// };
|
|
2170
2297
|
// await detectionService.create( detectionData );
|
|
2171
2298
|
if ( requestData.submittype == 'submit' ) {
|
|
2299
|
+
console.log( checklistDetails?.recurringFlag?.notifyType?.length );
|
|
2300
|
+
if ( checklistDetails?.recurringFlag?.notifyType?.length ) {
|
|
2301
|
+
updateRecurringFlagTracker( getchecklist[0], requestData.questionAnswers, currentDateTime );
|
|
2302
|
+
}
|
|
2172
2303
|
updateOpenSearch( req.user, requestData );
|
|
2173
2304
|
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2174
2305
|
// console.log( 'openSearch', openSearch );
|
|
@@ -2340,8 +2471,17 @@ export async function submitTask( req, res ) {
|
|
|
2340
2471
|
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
2341
2472
|
if ( submittype === 'submit' ) {
|
|
2342
2473
|
const excludedChecklists = [ 'Store Hygiene Check' ];
|
|
2343
|
-
if ( checklist.checkListName.includes( 'Store Hygiene' ) ) {
|
|
2344
|
-
|
|
2474
|
+
if ( checklist.checkListName.includes( 'Store Hygiene' ) && checklist?.streamId ) {
|
|
2475
|
+
let sqsData = {
|
|
2476
|
+
'storeId': checklist.store_id,
|
|
2477
|
+
'streamID': checklist.streamId,
|
|
2478
|
+
'detectionTime': checklist?.questionAnswers?.[0]?.questions?.[0]?.answers?.[0]?.detectionTime,
|
|
2479
|
+
'date': checklist.date_string,
|
|
2480
|
+
'storeResponseTime': currentDateTime.format( 'HH:mm:ss - MMM DD, YYYY' ),
|
|
2481
|
+
'message_mode': 'retriggered',
|
|
2482
|
+
};
|
|
2483
|
+
let sqsResponse = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
2484
|
+
console.log( sqsResponse );
|
|
2345
2485
|
}
|
|
2346
2486
|
if ( !excludedChecklists.includes( checklist.checkListName ) ) {
|
|
2347
2487
|
const query1 = [
|
|
@@ -2846,6 +2986,9 @@ export async function dashboardv1( req, res ) {
|
|
|
2846
2986
|
// const { store_id, date } = req.query;
|
|
2847
2987
|
const { date } = req.query;
|
|
2848
2988
|
const userId = req.user._id;
|
|
2989
|
+
let fromDate = new Date( req.query.date );
|
|
2990
|
+
let toDate = new Date( req.query.date );
|
|
2991
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
2849
2992
|
|
|
2850
2993
|
// //Get User Based Checklist //
|
|
2851
2994
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -2856,7 +2999,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2856
2999
|
// eslint-disable-next-line camelcase
|
|
2857
3000
|
// store_id,
|
|
2858
3001
|
userId,
|
|
2859
|
-
date_string: date,
|
|
3002
|
+
$or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ],
|
|
2860
3003
|
timeFlagStatus: true,
|
|
2861
3004
|
...clientId,
|
|
2862
3005
|
...storeMatch,
|
|
@@ -2882,9 +3025,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2882
3025
|
},
|
|
2883
3026
|
];
|
|
2884
3027
|
|
|
2885
|
-
|
|
2886
|
-
let toDate = new Date( req.query.date );
|
|
2887
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3028
|
+
|
|
2888
3029
|
const taskBaseMatch = {
|
|
2889
3030
|
// eslint-disable-next-line camelcase
|
|
2890
3031
|
// store_id,
|
|
@@ -2933,6 +3074,8 @@ export async function dashboardv1( req, res ) {
|
|
|
2933
3074
|
processedTask.aggregate( taskQuery ),
|
|
2934
3075
|
] );
|
|
2935
3076
|
|
|
3077
|
+
console.log( checklistResult );
|
|
3078
|
+
|
|
2936
3079
|
const checklistResultData =
|
|
2937
3080
|
checklistResult.status === 'fulfilled' ?
|
|
2938
3081
|
processResult( checklistResult.value ) :
|
|
@@ -3062,6 +3205,9 @@ export async function checklistv1( req, res ) {
|
|
|
3062
3205
|
// const { store_id, date, checklistStatus, searchValue } = req.query;
|
|
3063
3206
|
const { date, checklistStatus, searchValue } = req.query;
|
|
3064
3207
|
const userId = req.user._id;
|
|
3208
|
+
let fromDate = new Date( req.query.date );
|
|
3209
|
+
let toDate = new Date( req.query.date );
|
|
3210
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
3065
3211
|
|
|
3066
3212
|
// Get User Based Checklist //
|
|
3067
3213
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -3073,16 +3219,23 @@ export async function checklistv1( req, res ) {
|
|
|
3073
3219
|
// eslint-disable-next-line camelcase
|
|
3074
3220
|
// { store_id },
|
|
3075
3221
|
{ userId },
|
|
3076
|
-
{ date_string: date },
|
|
3222
|
+
// { $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
|
|
3077
3223
|
{ timeFlagStatus: true },
|
|
3078
3224
|
...matchExtraConditions,
|
|
3079
3225
|
clientId,
|
|
3080
3226
|
storeMatch,
|
|
3081
3227
|
];
|
|
3228
|
+
if ( checklistStatus != 'submit' ) {
|
|
3229
|
+
matchConditions.push( { $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] } );
|
|
3230
|
+
}
|
|
3231
|
+
if ( checklistStatus == 'submit' ) {
|
|
3232
|
+
matchConditions.push( { date_string: date } );
|
|
3233
|
+
}
|
|
3082
3234
|
if ( checklistStatus ) {
|
|
3083
3235
|
matchConditions.push( { checklistStatus } );
|
|
3084
3236
|
}
|
|
3085
3237
|
|
|
3238
|
+
|
|
3086
3239
|
const pipeline = [
|
|
3087
3240
|
{ $match: { $and: matchConditions } },
|
|
3088
3241
|
...( searchValue ?
|
|
@@ -3135,9 +3288,7 @@ export async function checklistv1( req, res ) {
|
|
|
3135
3288
|
return pipeline;
|
|
3136
3289
|
};
|
|
3137
3290
|
|
|
3138
|
-
|
|
3139
|
-
let toDate = new Date( req.query.date );
|
|
3140
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3291
|
+
|
|
3141
3292
|
const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
|
|
3142
3293
|
const matchConditions = [
|
|
3143
3294
|
// eslint-disable-next-line camelcase
|
|
@@ -3486,7 +3637,7 @@ export async function questionList( req, res ) {
|
|
|
3486
3637
|
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
3487
3638
|
} else {
|
|
3488
3639
|
logger.info( `v5 => Checklist Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
|
|
3489
|
-
let bucket = JSON.parse( process.env.BUCKET );
|
|
3640
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3490
3641
|
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3491
3642
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3492
3643
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
@@ -3512,12 +3663,12 @@ export async function questionList( req, res ) {
|
|
|
3512
3663
|
let checkvalidation = null;
|
|
3513
3664
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3514
3665
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3515
|
-
checkvalidation =
|
|
3666
|
+
checkvalidation = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3516
3667
|
} else {
|
|
3517
3668
|
checkvalidation = answer.validationAnswer;
|
|
3518
3669
|
}
|
|
3519
3670
|
}
|
|
3520
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3671
|
+
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
|
|
3521
3672
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3522
3673
|
}
|
|
3523
3674
|
|
|
@@ -3533,23 +3684,23 @@ export async function questionList( req, res ) {
|
|
|
3533
3684
|
answer.referenceImage= `${cdnurl.TraxAnswerCDN}${answer.referenceImage}`;
|
|
3534
3685
|
}
|
|
3535
3686
|
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3536
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer =
|
|
3687
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3537
3688
|
}
|
|
3538
3689
|
}
|
|
3539
3690
|
if ( question?.userAnswer ) {
|
|
3540
3691
|
for ( let [ userAnsIndex, userAns ] of question.userAnswer.entries() ) {
|
|
3541
3692
|
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3542
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer =
|
|
3693
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${userAns.validationAnswer}`;
|
|
3543
3694
|
}
|
|
3544
3695
|
if ( userAns.validationType == 'Capture Multiple Image with description' ) {
|
|
3545
3696
|
let imageAnswers = userAns.validationImage;
|
|
3546
3697
|
userAns.validationImage = [];
|
|
3547
3698
|
for ( let image of imageAnswers ) {
|
|
3548
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationImage.push(
|
|
3699
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationImage.push( `${cdnurl.TraxAnswerCDN}${image}` );
|
|
3549
3700
|
}
|
|
3550
3701
|
}
|
|
3551
3702
|
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3552
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer
|
|
3703
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer =`${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
3553
3704
|
}
|
|
3554
3705
|
if ( userAns.referenceImage != '' ) {
|
|
3555
3706
|
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( userAns.referenceImage ), Bucket: bucket.sop } );
|
|
@@ -3856,7 +4007,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3856
4007
|
return res.sendError( 'Task Got Edited Please Fill Again', 422 );
|
|
3857
4008
|
} else {
|
|
3858
4009
|
logger.info( `v5 => Task Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Task Name: ${getchecklist[0].checkListName}` );
|
|
3859
|
-
let bucket = JSON.parse( process.env.BUCKET );
|
|
4010
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3860
4011
|
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3861
4012
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3862
4013
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
@@ -3867,13 +4018,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3867
4018
|
if ( Array.isArray( questionReferenceImage ) ) {
|
|
3868
4019
|
questionReferenceImage = questionReferenceImage.filter( ( item ) => item != '' );
|
|
3869
4020
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = await Promise.all(
|
|
3870
|
-
questionReferenceImage.map( async ( image ) => image ?
|
|
4021
|
+
questionReferenceImage.map( async ( image ) => image ? `${cdnurl.TraxAnswerCDN}${image}` : '' ),
|
|
3871
4022
|
);
|
|
3872
4023
|
} else if ( questionReferenceImage !== '' ) {
|
|
3873
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage =
|
|
3874
|
-
file_path: decodeURIComponent( questionReferenceImage ),
|
|
3875
|
-
Bucket: bucket.sop,
|
|
3876
|
-
} );
|
|
4024
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = `${cdnurl.TraxAnswerCDN}${questionReferenceImage}`;
|
|
3877
4025
|
}
|
|
3878
4026
|
}
|
|
3879
4027
|
|
|
@@ -3884,13 +4032,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3884
4032
|
if ( Array.isArray( referenceImage ) ) {
|
|
3885
4033
|
referenceImage = referenceImage.filter( ( item ) => item != '' );
|
|
3886
4034
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = await Promise.all(
|
|
3887
|
-
referenceImage.map( async ( image ) => image ?
|
|
4035
|
+
referenceImage.map( async ( image ) => image ? `${cdnurl.TraxAnswerCDN}${image}` : '' ),
|
|
3888
4036
|
);
|
|
3889
4037
|
} else if ( referenceImage !== '' ) {
|
|
3890
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage =
|
|
3891
|
-
file_path: decodeURIComponent( referenceImage ),
|
|
3892
|
-
Bucket: bucket.sop,
|
|
3893
|
-
} );
|
|
4038
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = `${cdnurl.TraxAnswerCDN}${referenceImage}`;
|
|
3894
4039
|
}
|
|
3895
4040
|
}
|
|
3896
4041
|
|
|
@@ -3898,7 +4043,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3898
4043
|
let checkvalidation = null;
|
|
3899
4044
|
if ( answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3900
4045
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3901
|
-
checkvalidation =
|
|
4046
|
+
checkvalidation = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3902
4047
|
} else {
|
|
3903
4048
|
checkvalidation = answer.validationAnswer;
|
|
3904
4049
|
}
|
|
@@ -3907,10 +4052,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3907
4052
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3908
4053
|
}
|
|
3909
4054
|
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3910
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer =
|
|
3911
|
-
file_path: decodeURIComponent( answer.validationAnswer ),
|
|
3912
|
-
Bucket: bucket.sop,
|
|
3913
|
-
} );
|
|
4055
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3914
4056
|
}
|
|
3915
4057
|
}
|
|
3916
4058
|
|
|
@@ -3921,25 +4063,16 @@ export async function taskQuestionList( req, res ) {
|
|
|
3921
4063
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].linearType = question.answers[0].linearType;
|
|
3922
4064
|
}
|
|
3923
4065
|
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3924
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer =
|
|
3925
|
-
file_path: decodeURIComponent( userAns.validationAnswer ),
|
|
3926
|
-
Bucket: bucket.sop,
|
|
3927
|
-
} );
|
|
4066
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${userAns.validationAnswer}`;
|
|
3928
4067
|
}
|
|
3929
4068
|
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && rawAnswer != '' ) {
|
|
3930
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer =
|
|
3931
|
-
file_path: decodeURIComponent( rawAnswer ),
|
|
3932
|
-
Bucket: bucket.sop,
|
|
3933
|
-
} );
|
|
4069
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = `${cdnurl.TraxAnswerCDN}${rawAnswer}`;
|
|
3934
4070
|
}
|
|
3935
4071
|
if ( question.answerType == 'image/video' && rawAnswer != '' ) {
|
|
3936
4072
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = `${cdnurl.TraxAnswerCDN}${rawAnswer}`;
|
|
3937
4073
|
}
|
|
3938
4074
|
if ( userAns.referenceImage != '' ) {
|
|
3939
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage =
|
|
3940
|
-
file_path: decodeURIComponent( userAns.referenceImage ),
|
|
3941
|
-
Bucket: bucket.sop,
|
|
3942
|
-
} );
|
|
4075
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = `${cdnurl.TraxAnswerCDN}${userAns.referenceImage}`;
|
|
3943
4076
|
}
|
|
3944
4077
|
if ( question.answerType == 'multiplechoicemultiple' || ( question.answerType == 'dropdown' && question.allowMultiple ) ) {
|
|
3945
4078
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == rawAnswer );
|