tango-app-api-trax 3.8.18 → 3.8.19-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 +91 -27
- package/src/controllers/handlebar-helper.js +1 -0
- package/src/controllers/internalTrax.controller.js +1017 -14
- package/src/controllers/mobileTrax.controller.js +324 -202
- 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 +34 -23
- package/src/hbs/visit-checklist.hbs +84 -40
- 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
|
} );
|
|
@@ -136,7 +137,9 @@ export async function startChecklist( req, res ) {
|
|
|
136
137
|
let updateQuery = {};
|
|
137
138
|
updateQuery._id = new ObjectId( requestData.processedcheckListId );
|
|
138
139
|
updateQuery.userId = req.user._id;
|
|
139
|
-
|
|
140
|
+
if ( getBeforeChecklist?.[0]?.date_string == dayjs().format( 'YYYY-MM-DD' ) ) {
|
|
141
|
+
updateQuery.date_string = requestData.date;
|
|
142
|
+
}
|
|
140
143
|
|
|
141
144
|
if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
|
|
142
145
|
await PCLQusestion.questionAnswers.forEach( ( section ) => {
|
|
@@ -233,15 +236,15 @@ export async function startChecklist( req, res ) {
|
|
|
233
236
|
},
|
|
234
237
|
} );
|
|
235
238
|
let getupdatedchecklist = await processedchecklist.aggregate( findQuery );
|
|
236
|
-
let bucket = JSON.parse( process.env.BUCKET );
|
|
239
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
237
240
|
getupdatedchecklist[0].questionAnswers.forEach( ( section ) => {
|
|
238
241
|
section.questions.forEach( async ( question ) => {
|
|
239
242
|
if ( question.questionReferenceImage && question.questionReferenceImage!='' ) {
|
|
240
|
-
question.questionReferenceImage =
|
|
243
|
+
question.questionReferenceImage = `${cdnurl.TraxAnswerCDN}${question.questionReferenceImage}`;
|
|
241
244
|
}
|
|
242
245
|
question.answers.forEach( async ( answer ) => {
|
|
243
246
|
if ( answer.referenceImage != '' ) {
|
|
244
|
-
answer.referenceImage =
|
|
247
|
+
answer.referenceImage = `${cdnurl.TraxAnswerCDN}${answer.referenceImage}`;
|
|
245
248
|
}
|
|
246
249
|
} );
|
|
247
250
|
} );
|
|
@@ -316,7 +319,7 @@ export async function startChecklist( req, res ) {
|
|
|
316
319
|
return res.sendError( 'something went wrong please try again', 500 );
|
|
317
320
|
}
|
|
318
321
|
} catch ( e ) {
|
|
319
|
-
|
|
322
|
+
console.log( 'e =>', e );
|
|
320
323
|
logger.error( { function: 'startChecklist', error: e, body: req.body } );
|
|
321
324
|
return res.sendError( e, 500 );
|
|
322
325
|
}
|
|
@@ -466,19 +469,16 @@ export async function startTask( req, res ) {
|
|
|
466
469
|
} );
|
|
467
470
|
const getUpdatedTask = await processedTask.aggregate( findQuery );
|
|
468
471
|
|
|
469
|
-
|
|
472
|
+
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
470
473
|
if ( !( task.checkListFrom && task.checkListFrom == 'api' ) ) {
|
|
471
|
-
const bucket = JSON.parse( process.env.BUCKET );
|
|
474
|
+
// const bucket = JSON.parse( process.env.BUCKET );
|
|
472
475
|
await Promise.all(
|
|
473
476
|
getUpdatedTask[0].questionAnswers.map( ( section ) =>
|
|
474
477
|
section.questions.map( async ( question ) => {
|
|
475
478
|
if ( question.questionReferenceImage.length > 0 ) {
|
|
476
479
|
question.questionReferenceImage = await Promise.all(
|
|
477
480
|
question.questionReferenceImage.map( async ( image ) => {
|
|
478
|
-
return
|
|
479
|
-
Bucket: bucket.sop,
|
|
480
|
-
file_path: decodeURIComponent( image ),
|
|
481
|
-
} );
|
|
481
|
+
return `${cdnurl.TraxAnswerCDN}${image}`;
|
|
482
482
|
} ),
|
|
483
483
|
);
|
|
484
484
|
}
|
|
@@ -488,10 +488,7 @@ export async function startTask( req, res ) {
|
|
|
488
488
|
if ( answer.referenceImage.length > 0 ) {
|
|
489
489
|
answer.referenceImage = await Promise.all(
|
|
490
490
|
answer.referenceImage.map( async ( image ) => {
|
|
491
|
-
return
|
|
492
|
-
Bucket: bucket.sop,
|
|
493
|
-
file_path: decodeURIComponent( image ),
|
|
494
|
-
} );
|
|
491
|
+
return `${cdnurl.TraxAnswerCDN}${image}`;
|
|
495
492
|
} ),
|
|
496
493
|
);
|
|
497
494
|
}
|
|
@@ -1087,12 +1084,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1087
1084
|
try {
|
|
1088
1085
|
let requestData = req.body;
|
|
1089
1086
|
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 } );
|
|
1087
|
+
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1, redoEdit: 1 } );
|
|
1091
1088
|
let reqAnswers = requestData.questionAnswers;
|
|
1092
1089
|
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1093
1090
|
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1094
1091
|
|
|
1095
1092
|
if ( requestData.submittype == 'submit' ) {
|
|
1093
|
+
if ( getChecklistQA?.redoEdit ) {
|
|
1094
|
+
requestData.submittype = 'draft';
|
|
1095
|
+
}
|
|
1096
1096
|
reqAnswers.forEach( ( reqA ) => {
|
|
1097
1097
|
if ( ![ 'multiplechoicemultiple', 'multipleImage', 'image/video' ].includes( reqA?.answerType ) && ( reqA.answerType == 'dropDown' && !reqA.allowMultiple ) ) {
|
|
1098
1098
|
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
@@ -1179,24 +1179,29 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1179
1179
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1180
1180
|
let qaans = qaAnswers[j].answers;
|
|
1181
1181
|
let yn = [];
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
if (
|
|
1185
|
-
if (
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
splitImgUrl.
|
|
1191
|
-
|
|
1182
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1183
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1184
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1185
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1186
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1187
|
+
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1188
|
+
if ( validateAns.length ) {
|
|
1189
|
+
let splitImgUrl = validateAns.split( '/' );
|
|
1190
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1191
|
+
splitImgUrl.splice( 0, 3 );
|
|
1192
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1193
|
+
}
|
|
1192
1194
|
}
|
|
1193
1195
|
}
|
|
1196
|
+
} else {
|
|
1197
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1198
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1194
1199
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1200
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1201
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1202
|
+
}
|
|
1203
|
+
yn.push( qaans[k] );
|
|
1198
1204
|
}
|
|
1199
|
-
yn.push( qaans[k] );
|
|
1200
1205
|
}
|
|
1201
1206
|
}
|
|
1202
1207
|
let structure = {};
|
|
@@ -1236,39 +1241,44 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1236
1241
|
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
|
|
1237
1242
|
let qaans = qaAnswers[j].answers;
|
|
1238
1243
|
let ms = [];
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
if (
|
|
1242
|
-
if (
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
splitImgUrl.
|
|
1248
|
-
|
|
1244
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1245
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1246
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1247
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1248
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1249
|
+
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1250
|
+
if ( validationAnswer.length ) {
|
|
1251
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1252
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1253
|
+
splitImgUrl.splice( 0, 3 );
|
|
1254
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1255
|
+
}
|
|
1249
1256
|
}
|
|
1250
1257
|
}
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1258
|
+
} else {
|
|
1259
|
+
if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
|
|
1260
|
+
qaans[k]['validationImage']=[];
|
|
1261
|
+
if ( requestSection[i].validationImage.length ) {
|
|
1262
|
+
for ( let image of requestSection[i].validationImage ) {
|
|
1263
|
+
let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
|
|
1264
|
+
if ( validationAnswer.length ) {
|
|
1265
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1266
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1267
|
+
splitImgUrl.splice( 0, 3 );
|
|
1268
|
+
qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1265
1272
|
}
|
|
1266
1273
|
}
|
|
1274
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1275
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1267
1276
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1277
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1278
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1279
|
+
}
|
|
1280
|
+
ms.push( qaans[k] );
|
|
1270
1281
|
}
|
|
1271
|
-
ms.push( qaans[k] );
|
|
1272
1282
|
}
|
|
1273
1283
|
}
|
|
1274
1284
|
let structure = {};
|
|
@@ -1309,30 +1319,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1309
1319
|
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
|
|
1310
1320
|
let qaans = qaAnswers[j].answers;
|
|
1311
1321
|
let mcmo = [];
|
|
1312
|
-
|
|
1313
|
-
let
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
if (
|
|
1317
|
-
if ( separatedArray[s].
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1322
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1323
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1324
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1325
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1326
|
+
if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
|
|
1327
|
+
if ( ( getChecklistQA?.redoEdit && qaans[k].redo == separatedArray[s].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1328
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1329
|
+
if ( separatedArray[s].validationAnswer ) {
|
|
1330
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1331
|
+
if ( validationAnswer.length ) {
|
|
1332
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1333
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1334
|
+
splitImgUrl.splice( 0, 3 );
|
|
1335
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1324
1338
|
}
|
|
1339
|
+
} else {
|
|
1340
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1341
|
+
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1342
|
+
}
|
|
1343
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1344
|
+
qaans[k].runAIData = separatedArray[s].runAIData;
|
|
1325
1345
|
}
|
|
1326
1346
|
}
|
|
1327
|
-
|
|
1328
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1329
|
-
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1347
|
+
mcmo.push( qaans[k] );
|
|
1330
1348
|
}
|
|
1331
|
-
|
|
1332
|
-
mcmo.push( qaans[k] );
|
|
1333
1349
|
}
|
|
1334
1350
|
}
|
|
1335
1351
|
}
|
|
1352
|
+
qaAnswers[j].answers.forEach( ( ele ) => {
|
|
1353
|
+
if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1354
|
+
ele.redo = false;
|
|
1355
|
+
}
|
|
1356
|
+
} );
|
|
1357
|
+
|
|
1336
1358
|
let structure = {};
|
|
1337
1359
|
structure.qno = qaAnswers[j].qno;
|
|
1338
1360
|
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
@@ -1371,37 +1393,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1371
1393
|
} else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
|
|
1372
1394
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1373
1395
|
let mcmi = [];
|
|
1396
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1374
1397
|
// for (let k = 0; k < qaans.length; k++) {
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1398
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1399
|
+
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1400
|
+
let newAnswer = {};
|
|
1401
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1402
|
+
if ( validationAnswer.length ) {
|
|
1403
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1404
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1405
|
+
splitImgUrl.splice( 0, 3 );
|
|
1406
|
+
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1407
|
+
}
|
|
1384
1408
|
}
|
|
1385
|
-
}
|
|
1386
1409
|
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1410
|
+
newAnswer.answeroptionNumber = 0;
|
|
1411
|
+
newAnswer.sopFlag = false;
|
|
1412
|
+
newAnswer.validation = false;
|
|
1413
|
+
newAnswer.validationType = '';
|
|
1414
|
+
newAnswer.referenceImage = '';
|
|
1415
|
+
newAnswer.allowUploadfromGallery = false;
|
|
1416
|
+
newAnswer.descriptivetype = '';
|
|
1417
|
+
newAnswer.showLinked = false;
|
|
1418
|
+
newAnswer.linkedQuestion = 0;
|
|
1419
|
+
newAnswer.nestedQuestion = [];
|
|
1420
|
+
newAnswer.index = s;
|
|
1421
|
+
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1422
|
+
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1423
|
+
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1424
|
+
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1425
|
+
newAnswer.answerType = separatedArray[s].answerType;
|
|
1426
|
+
}
|
|
1427
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1428
|
+
newAnswer.runAIData = separatedArray[s].runAIData;
|
|
1429
|
+
}
|
|
1430
|
+
mcmi.push( newAnswer );
|
|
1403
1431
|
}
|
|
1404
|
-
mcmi.push( newAnswer );
|
|
1405
1432
|
}
|
|
1406
1433
|
}
|
|
1407
1434
|
// }
|
|
@@ -1441,71 +1468,76 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1441
1468
|
newArray.push( structure );
|
|
1442
1469
|
} else {
|
|
1443
1470
|
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( '/' );
|
|
1471
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1472
|
+
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1473
|
+
let validationAnswer = '';
|
|
1474
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
1475
|
+
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1454
1476
|
}
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1477
|
+
if ( validationAnswer.length ) {
|
|
1478
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1479
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1480
|
+
splitImgUrl.splice( 0, 3 );
|
|
1481
|
+
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
let ansstructure = {
|
|
1485
|
+
answer: requestSection[i].answer,
|
|
1486
|
+
answeroptionNumber: 1,
|
|
1487
|
+
sopFlag: false,
|
|
1488
|
+
validation: false,
|
|
1489
|
+
validationType: '',
|
|
1490
|
+
validationAnswer: '',
|
|
1491
|
+
referenceImage: qaAnswers[j].answers[0].referenceImage || '',
|
|
1492
|
+
multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
|
|
1493
|
+
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1494
|
+
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1495
|
+
runAI: qaAnswers[j].answers[0]?.runAI || false,
|
|
1496
|
+
runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
|
|
1497
|
+
runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
|
|
1498
|
+
};
|
|
1499
|
+
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1500
|
+
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1474
1501
|
if ( qaAnswers[j].compliance ) {
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1502
|
+
if ( qaAnswers[j].compliance ) {
|
|
1503
|
+
let ansArray = requestSection[i].answer.split( ',' );
|
|
1504
|
+
if ( ansArray.includes( '-' ) ) {
|
|
1505
|
+
ansArray = requestSection[i].answer.split( '-' );
|
|
1506
|
+
}
|
|
1507
|
+
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 ) ) {
|
|
1508
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1509
|
+
} 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 ) ) {
|
|
1510
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1511
|
+
} 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 ) {
|
|
1512
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1513
|
+
} else {
|
|
1514
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1515
|
+
}
|
|
1478
1516
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
if ( qaAnswers[j].answerType == 'linearscale' ) {
|
|
1520
|
+
if ( qaAnswers[j].compliance ) {
|
|
1521
|
+
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
1522
|
+
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1484
1523
|
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1485
1524
|
} else {
|
|
1486
1525
|
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1487
1526
|
}
|
|
1488
1527
|
}
|
|
1528
|
+
ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
|
|
1529
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1530
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1489
1531
|
}
|
|
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
|
-
}
|
|
1532
|
+
if ( qaAnswers[j].answerType == 'image' ) {
|
|
1533
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1534
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1499
1535
|
}
|
|
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;
|
|
1536
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1537
|
+
ansstructure.runAIData = requestSection[i].runAIData;
|
|
1538
|
+
}
|
|
1539
|
+
des.push( ansstructure );
|
|
1507
1540
|
}
|
|
1508
|
-
des.push( ansstructure );
|
|
1509
1541
|
}
|
|
1510
1542
|
let structure = {};
|
|
1511
1543
|
structure.qno = qaAnswers[j].qno;
|
|
@@ -1937,7 +1969,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
1937
1969
|
let des = [];
|
|
1938
1970
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1939
1971
|
let validationAnswer = '';
|
|
1940
|
-
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1972
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
1941
1973
|
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1942
1974
|
}
|
|
1943
1975
|
if ( validationAnswer.length ) {
|
|
@@ -2034,6 +2066,102 @@ function QuestionFlag( req, res ) {
|
|
|
2034
2066
|
}
|
|
2035
2067
|
}
|
|
2036
2068
|
|
|
2069
|
+
async function updateRecurringFlagTracker( processedChecklist, questionAnswers, currentDateTime ) {
|
|
2070
|
+
try {
|
|
2071
|
+
if ( !processedChecklist?.sourceCheckList_id ) return;
|
|
2072
|
+
|
|
2073
|
+
const isUserBased = processedChecklist?.coverage === 'user';
|
|
2074
|
+
const storeId = isUserBased ? '' : ( processedChecklist?.store_id || '' );
|
|
2075
|
+
const userId = isUserBased ? ( processedChecklist?.userId ? String( processedChecklist.userId ) : ( processedChecklist?.userEmail || '' ) ) : '';
|
|
2076
|
+
if ( !isUserBased && !storeId ) return;
|
|
2077
|
+
if ( isUserBased && !userId ) return;
|
|
2078
|
+
|
|
2079
|
+
const today = currentDateTime ? currentDateTime.format( 'YYYY-MM-DD' ) : dayjs().format( 'YYYY-MM-DD' );
|
|
2080
|
+
const yesterday = dayjs( today, 'YYYY-MM-DD' ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
|
|
2081
|
+
|
|
2082
|
+
const trackerKeyBase = {
|
|
2083
|
+
client_id: processedChecklist.client_id,
|
|
2084
|
+
sourceCheckList_id: processedChecklist.sourceCheckList_id,
|
|
2085
|
+
...( isUserBased ) ? { user_id: userId } : { store_id: storeId },
|
|
2086
|
+
};
|
|
2087
|
+
|
|
2088
|
+
const existingRows = await recurringFlagTracker.find( trackerKeyBase, { section_id: 1, qno: 1, consecutiveCount: 1, lastFlaggedDate: 1 } );
|
|
2089
|
+
const existingMap = new Map();
|
|
2090
|
+
for ( const r of existingRows ) {
|
|
2091
|
+
existingMap.set( `${r.section_id || ''}::${r.qno || ''}`, r );
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
const ops = [];
|
|
2095
|
+
|
|
2096
|
+
( questionAnswers || [] ).forEach( ( section ) => {
|
|
2097
|
+
( section?.questions || [] ).forEach( ( question ) => {
|
|
2098
|
+
const sectionId = section?.section_id || '';
|
|
2099
|
+
const qno = question?.qno || '';
|
|
2100
|
+
if ( qno === '' ) return;
|
|
2101
|
+
|
|
2102
|
+
const flaggedNow = Array.isArray( question?.userAnswer ) && question.userAnswer.some( ( a ) => a?.sopFlag === true );
|
|
2103
|
+
const key = `${sectionId}::${qno}`;
|
|
2104
|
+
const existing = existingMap.get( key );
|
|
2105
|
+
console.log( flaggedNow, 'test' );
|
|
2106
|
+
if ( flaggedNow ) {
|
|
2107
|
+
let newCount;
|
|
2108
|
+
if ( !existing ) {
|
|
2109
|
+
newCount = 1;
|
|
2110
|
+
} else if ( existing.lastFlaggedDate === today ) {
|
|
2111
|
+
// Multi-submit on same day: already counted, no-op.
|
|
2112
|
+
return;
|
|
2113
|
+
} else if ( existing.lastFlaggedDate === yesterday ) {
|
|
2114
|
+
newCount = ( existing.consecutiveCount || 0 ) + 1;
|
|
2115
|
+
} else {
|
|
2116
|
+
// Gap broke the streak — fresh start.
|
|
2117
|
+
newCount = 1;
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
ops.push( {
|
|
2121
|
+
updateOne: {
|
|
2122
|
+
filter: { ...trackerKeyBase, section_id: sectionId, qno },
|
|
2123
|
+
update: {
|
|
2124
|
+
$set: {
|
|
2125
|
+
coverage: isUserBased ? 'user' : 'store',
|
|
2126
|
+
checkListName: processedChecklist.checkListName,
|
|
2127
|
+
storeName: isUserBased ? '' : ( processedChecklist.storeName || '' ),
|
|
2128
|
+
userName: processedChecklist.userName || '',
|
|
2129
|
+
userEmail: processedChecklist.userEmail || '',
|
|
2130
|
+
sectionName: section?.sectionName || '',
|
|
2131
|
+
qname: question?.qname || '',
|
|
2132
|
+
consecutiveCount: newCount,
|
|
2133
|
+
lastFlaggedDate: today,
|
|
2134
|
+
lastSubmittedBy: processedChecklist.userName || processedChecklist.userEmail || '--',
|
|
2135
|
+
lastSubmissionDate: currentDateTime ? currentDateTime.format( 'hh:mm A, DD MMM YYYY' ) : today,
|
|
2136
|
+
},
|
|
2137
|
+
},
|
|
2138
|
+
upsert: true,
|
|
2139
|
+
},
|
|
2140
|
+
} );
|
|
2141
|
+
} else if ( existing && ( existing.consecutiveCount || 0 ) > 0 ) {
|
|
2142
|
+
// Question answered correctly today — break the streak.
|
|
2143
|
+
ops.push( {
|
|
2144
|
+
updateOne: {
|
|
2145
|
+
filter: { ...trackerKeyBase, section_id: sectionId, qno },
|
|
2146
|
+
update: { $set: { lastFlaggedDate: today } },
|
|
2147
|
+
},
|
|
2148
|
+
} );
|
|
2149
|
+
}
|
|
2150
|
+
} );
|
|
2151
|
+
} );
|
|
2152
|
+
if ( ops.length ) {
|
|
2153
|
+
try {
|
|
2154
|
+
let data = await recurringFlagTracker.bulkWrite( ops, { ordered: false } );
|
|
2155
|
+
console.log( 'recurringFlagTracker bulkWrite result', data );
|
|
2156
|
+
} catch ( bulkErr ) {
|
|
2157
|
+
logger.error( { function: 'updateRecurringFlagTracker.bulkWrite', code: bulkErr?.code, message: bulkErr?.message, writeErrors: bulkErr?.writeErrors } );
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
} catch ( error ) {
|
|
2161
|
+
logger.error( { function: 'updateRecurringFlagTracker', error } );
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2037
2165
|
export async function submitChecklist( req, res ) {
|
|
2038
2166
|
try {
|
|
2039
2167
|
let requestData = req.body;
|
|
@@ -2081,6 +2209,7 @@ export async function submitChecklist( req, res ) {
|
|
|
2081
2209
|
let flagCount = QuestionFlag( req, res );
|
|
2082
2210
|
updateData.questionFlag = flagCount;
|
|
2083
2211
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
2212
|
+
updateData.redoEdit = false;
|
|
2084
2213
|
if ( requestData.deviceDetails && requestData.deviceDetails != '' ) {
|
|
2085
2214
|
updateData.deviceDetails =JSON.parse( requestData.deviceDetails );
|
|
2086
2215
|
}
|
|
@@ -2169,6 +2298,10 @@ export async function submitChecklist( req, res ) {
|
|
|
2169
2298
|
// };
|
|
2170
2299
|
// await detectionService.create( detectionData );
|
|
2171
2300
|
if ( requestData.submittype == 'submit' ) {
|
|
2301
|
+
console.log( checklistDetails?.recurringFlag?.notifyType?.length );
|
|
2302
|
+
if ( checklistDetails?.recurringFlag?.notifyType?.length ) {
|
|
2303
|
+
updateRecurringFlagTracker( getchecklist[0], requestData.questionAnswers, currentDateTime );
|
|
2304
|
+
}
|
|
2172
2305
|
updateOpenSearch( req.user, requestData );
|
|
2173
2306
|
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2174
2307
|
// console.log( 'openSearch', openSearch );
|
|
@@ -2349,7 +2482,8 @@ export async function submitTask( req, res ) {
|
|
|
2349
2482
|
'storeResponseTime': currentDateTime.format( 'HH:mm:ss - MMM DD, YYYY' ),
|
|
2350
2483
|
'message_mode': 'retriggered',
|
|
2351
2484
|
};
|
|
2352
|
-
sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
2485
|
+
let sqsResponse = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
2486
|
+
console.log( sqsResponse );
|
|
2353
2487
|
}
|
|
2354
2488
|
if ( !excludedChecklists.includes( checklist.checkListName ) ) {
|
|
2355
2489
|
const query1 = [
|
|
@@ -2854,6 +2988,9 @@ export async function dashboardv1( req, res ) {
|
|
|
2854
2988
|
// const { store_id, date } = req.query;
|
|
2855
2989
|
const { date } = req.query;
|
|
2856
2990
|
const userId = req.user._id;
|
|
2991
|
+
let fromDate = new Date( req.query.date );
|
|
2992
|
+
let toDate = new Date( req.query.date );
|
|
2993
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
2857
2994
|
|
|
2858
2995
|
// //Get User Based Checklist //
|
|
2859
2996
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -2870,7 +3007,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2870
3007
|
...storeMatch,
|
|
2871
3008
|
};
|
|
2872
3009
|
const buildPipeline = ( matchExtraConditions = {} ) => [
|
|
2873
|
-
{ $match: { ...baseMatch, ...matchExtraConditions } },
|
|
3010
|
+
{ $match: { $or: [ { ...baseMatch, ...matchExtraConditions }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } }, { userId }, { ...storeMatch } ] } ] } },
|
|
2874
3011
|
{
|
|
2875
3012
|
$facet: {
|
|
2876
3013
|
total: [ { $count: 'total' } ],
|
|
@@ -2890,9 +3027,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2890
3027
|
},
|
|
2891
3028
|
];
|
|
2892
3029
|
|
|
2893
|
-
|
|
2894
|
-
let toDate = new Date( req.query.date );
|
|
2895
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3030
|
+
|
|
2896
3031
|
const taskBaseMatch = {
|
|
2897
3032
|
// eslint-disable-next-line camelcase
|
|
2898
3033
|
// store_id,
|
|
@@ -2941,6 +3076,8 @@ export async function dashboardv1( req, res ) {
|
|
|
2941
3076
|
processedTask.aggregate( taskQuery ),
|
|
2942
3077
|
] );
|
|
2943
3078
|
|
|
3079
|
+
console.log( checklistResult );
|
|
3080
|
+
|
|
2944
3081
|
const checklistResultData =
|
|
2945
3082
|
checklistResult.status === 'fulfilled' ?
|
|
2946
3083
|
processResult( checklistResult.value ) :
|
|
@@ -3070,6 +3207,9 @@ export async function checklistv1( req, res ) {
|
|
|
3070
3207
|
// const { store_id, date, checklistStatus, searchValue } = req.query;
|
|
3071
3208
|
const { date, checklistStatus, searchValue } = req.query;
|
|
3072
3209
|
const userId = req.user._id;
|
|
3210
|
+
let fromDate = new Date( req.query.date );
|
|
3211
|
+
let toDate = new Date( req.query.date );
|
|
3212
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
3073
3213
|
|
|
3074
3214
|
// Get User Based Checklist //
|
|
3075
3215
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -3081,16 +3221,18 @@ export async function checklistv1( req, res ) {
|
|
|
3081
3221
|
// eslint-disable-next-line camelcase
|
|
3082
3222
|
// { store_id },
|
|
3083
3223
|
{ userId },
|
|
3084
|
-
{ date_string: date },
|
|
3224
|
+
{ $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
|
|
3085
3225
|
{ timeFlagStatus: true },
|
|
3086
3226
|
...matchExtraConditions,
|
|
3087
3227
|
clientId,
|
|
3088
3228
|
storeMatch,
|
|
3089
3229
|
];
|
|
3230
|
+
|
|
3090
3231
|
if ( checklistStatus ) {
|
|
3091
3232
|
matchConditions.push( { checklistStatus } );
|
|
3092
3233
|
}
|
|
3093
3234
|
|
|
3235
|
+
|
|
3094
3236
|
const pipeline = [
|
|
3095
3237
|
{ $match: { $and: matchConditions } },
|
|
3096
3238
|
...( searchValue ?
|
|
@@ -3143,9 +3285,7 @@ export async function checklistv1( req, res ) {
|
|
|
3143
3285
|
return pipeline;
|
|
3144
3286
|
};
|
|
3145
3287
|
|
|
3146
|
-
|
|
3147
|
-
let toDate = new Date( req.query.date );
|
|
3148
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3288
|
+
|
|
3149
3289
|
const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
|
|
3150
3290
|
const matchConditions = [
|
|
3151
3291
|
// eslint-disable-next-line camelcase
|
|
@@ -3494,7 +3634,7 @@ export async function questionList( req, res ) {
|
|
|
3494
3634
|
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
3495
3635
|
} else {
|
|
3496
3636
|
logger.info( `v5 => Checklist Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
|
|
3497
|
-
let bucket = JSON.parse( process.env.BUCKET );
|
|
3637
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3498
3638
|
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3499
3639
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3500
3640
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
@@ -3520,12 +3660,12 @@ export async function questionList( req, res ) {
|
|
|
3520
3660
|
let checkvalidation = null;
|
|
3521
3661
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3522
3662
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3523
|
-
checkvalidation =
|
|
3663
|
+
checkvalidation = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3524
3664
|
} else {
|
|
3525
3665
|
checkvalidation = answer.validationAnswer;
|
|
3526
3666
|
}
|
|
3527
3667
|
}
|
|
3528
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3668
|
+
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
|
|
3529
3669
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3530
3670
|
}
|
|
3531
3671
|
|
|
@@ -3541,23 +3681,23 @@ export async function questionList( req, res ) {
|
|
|
3541
3681
|
answer.referenceImage= `${cdnurl.TraxAnswerCDN}${answer.referenceImage}`;
|
|
3542
3682
|
}
|
|
3543
3683
|
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3544
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer =
|
|
3684
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3545
3685
|
}
|
|
3546
3686
|
}
|
|
3547
3687
|
if ( question?.userAnswer ) {
|
|
3548
3688
|
for ( let [ userAnsIndex, userAns ] of question.userAnswer.entries() ) {
|
|
3549
3689
|
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3550
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer =
|
|
3690
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${userAns.validationAnswer}`;
|
|
3551
3691
|
}
|
|
3552
3692
|
if ( userAns.validationType == 'Capture Multiple Image with description' ) {
|
|
3553
3693
|
let imageAnswers = userAns.validationImage;
|
|
3554
3694
|
userAns.validationImage = [];
|
|
3555
3695
|
for ( let image of imageAnswers ) {
|
|
3556
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationImage.push(
|
|
3696
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationImage.push( `${cdnurl.TraxAnswerCDN}${image}` );
|
|
3557
3697
|
}
|
|
3558
3698
|
}
|
|
3559
3699
|
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3560
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer
|
|
3700
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer =`${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
3561
3701
|
}
|
|
3562
3702
|
if ( userAns.referenceImage != '' ) {
|
|
3563
3703
|
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( userAns.referenceImage ), Bucket: bucket.sop } );
|
|
@@ -3864,7 +4004,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3864
4004
|
return res.sendError( 'Task Got Edited Please Fill Again', 422 );
|
|
3865
4005
|
} else {
|
|
3866
4006
|
logger.info( `v5 => Task Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Task Name: ${getchecklist[0].checkListName}` );
|
|
3867
|
-
let bucket = JSON.parse( process.env.BUCKET );
|
|
4007
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3868
4008
|
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3869
4009
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3870
4010
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
@@ -3875,13 +4015,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3875
4015
|
if ( Array.isArray( questionReferenceImage ) ) {
|
|
3876
4016
|
questionReferenceImage = questionReferenceImage.filter( ( item ) => item != '' );
|
|
3877
4017
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = await Promise.all(
|
|
3878
|
-
questionReferenceImage.map( async ( image ) => image ?
|
|
4018
|
+
questionReferenceImage.map( async ( image ) => image ? `${cdnurl.TraxAnswerCDN}${image}` : '' ),
|
|
3879
4019
|
);
|
|
3880
4020
|
} else if ( questionReferenceImage !== '' ) {
|
|
3881
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage =
|
|
3882
|
-
file_path: decodeURIComponent( questionReferenceImage ),
|
|
3883
|
-
Bucket: bucket.sop,
|
|
3884
|
-
} );
|
|
4021
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = `${cdnurl.TraxAnswerCDN}${questionReferenceImage}`;
|
|
3885
4022
|
}
|
|
3886
4023
|
}
|
|
3887
4024
|
|
|
@@ -3892,13 +4029,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3892
4029
|
if ( Array.isArray( referenceImage ) ) {
|
|
3893
4030
|
referenceImage = referenceImage.filter( ( item ) => item != '' );
|
|
3894
4031
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = await Promise.all(
|
|
3895
|
-
referenceImage.map( async ( image ) => image ?
|
|
4032
|
+
referenceImage.map( async ( image ) => image ? `${cdnurl.TraxAnswerCDN}${image}` : '' ),
|
|
3896
4033
|
);
|
|
3897
4034
|
} else if ( referenceImage !== '' ) {
|
|
3898
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage =
|
|
3899
|
-
file_path: decodeURIComponent( referenceImage ),
|
|
3900
|
-
Bucket: bucket.sop,
|
|
3901
|
-
} );
|
|
4035
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = `${cdnurl.TraxAnswerCDN}${referenceImage}`;
|
|
3902
4036
|
}
|
|
3903
4037
|
}
|
|
3904
4038
|
|
|
@@ -3906,7 +4040,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3906
4040
|
let checkvalidation = null;
|
|
3907
4041
|
if ( answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3908
4042
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3909
|
-
checkvalidation =
|
|
4043
|
+
checkvalidation = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3910
4044
|
} else {
|
|
3911
4045
|
checkvalidation = answer.validationAnswer;
|
|
3912
4046
|
}
|
|
@@ -3915,10 +4049,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3915
4049
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3916
4050
|
}
|
|
3917
4051
|
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3918
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer =
|
|
3919
|
-
file_path: decodeURIComponent( answer.validationAnswer ),
|
|
3920
|
-
Bucket: bucket.sop,
|
|
3921
|
-
} );
|
|
4052
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3922
4053
|
}
|
|
3923
4054
|
}
|
|
3924
4055
|
|
|
@@ -3929,25 +4060,16 @@ export async function taskQuestionList( req, res ) {
|
|
|
3929
4060
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].linearType = question.answers[0].linearType;
|
|
3930
4061
|
}
|
|
3931
4062
|
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3932
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer =
|
|
3933
|
-
file_path: decodeURIComponent( userAns.validationAnswer ),
|
|
3934
|
-
Bucket: bucket.sop,
|
|
3935
|
-
} );
|
|
4063
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${userAns.validationAnswer}`;
|
|
3936
4064
|
}
|
|
3937
4065
|
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && rawAnswer != '' ) {
|
|
3938
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer =
|
|
3939
|
-
file_path: decodeURIComponent( rawAnswer ),
|
|
3940
|
-
Bucket: bucket.sop,
|
|
3941
|
-
} );
|
|
4066
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = `${cdnurl.TraxAnswerCDN}${rawAnswer}`;
|
|
3942
4067
|
}
|
|
3943
4068
|
if ( question.answerType == 'image/video' && rawAnswer != '' ) {
|
|
3944
4069
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = `${cdnurl.TraxAnswerCDN}${rawAnswer}`;
|
|
3945
4070
|
}
|
|
3946
4071
|
if ( userAns.referenceImage != '' ) {
|
|
3947
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage =
|
|
3948
|
-
file_path: decodeURIComponent( userAns.referenceImage ),
|
|
3949
|
-
Bucket: bucket.sop,
|
|
3950
|
-
} );
|
|
4072
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = `${cdnurl.TraxAnswerCDN}${userAns.referenceImage}`;
|
|
3951
4073
|
}
|
|
3952
4074
|
if ( question.answerType == 'multiplechoicemultiple' || ( question.answerType == 'dropdown' && question.allowMultiple ) ) {
|
|
3953
4075
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == rawAnswer );
|