tango-app-api-trax 3.8.17 → 3.8.18-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 +338 -203
- 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 +84 -37
- 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 );
|
|
@@ -2340,8 +2473,17 @@ export async function submitTask( req, res ) {
|
|
|
2340
2473
|
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
2341
2474
|
if ( submittype === 'submit' ) {
|
|
2342
2475
|
const excludedChecklists = [ 'Store Hygiene Check' ];
|
|
2343
|
-
if ( checklist.checkListName.includes( 'Store Hygiene' ) ) {
|
|
2344
|
-
|
|
2476
|
+
if ( checklist.checkListName.includes( 'Store Hygiene' ) && checklist?.streamId ) {
|
|
2477
|
+
let sqsData = {
|
|
2478
|
+
'storeId': checklist.store_id,
|
|
2479
|
+
'streamID': checklist.streamId,
|
|
2480
|
+
'detectionTime': checklist?.questionAnswers?.[0]?.questions?.[0]?.answers?.[0]?.detectionTime,
|
|
2481
|
+
'date': checklist.date_string,
|
|
2482
|
+
'storeResponseTime': currentDateTime.format( 'HH:mm:ss - MMM DD, YYYY' ),
|
|
2483
|
+
'message_mode': 'retriggered',
|
|
2484
|
+
};
|
|
2485
|
+
let sqsResponse = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
2486
|
+
console.log( sqsResponse );
|
|
2345
2487
|
}
|
|
2346
2488
|
if ( !excludedChecklists.includes( checklist.checkListName ) ) {
|
|
2347
2489
|
const query1 = [
|
|
@@ -2846,6 +2988,9 @@ export async function dashboardv1( req, res ) {
|
|
|
2846
2988
|
// const { store_id, date } = req.query;
|
|
2847
2989
|
const { date } = req.query;
|
|
2848
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 );
|
|
2849
2994
|
|
|
2850
2995
|
// //Get User Based Checklist //
|
|
2851
2996
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -2856,7 +3001,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2856
3001
|
// eslint-disable-next-line camelcase
|
|
2857
3002
|
// store_id,
|
|
2858
3003
|
userId,
|
|
2859
|
-
date_string: date,
|
|
3004
|
+
$or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ],
|
|
2860
3005
|
timeFlagStatus: true,
|
|
2861
3006
|
...clientId,
|
|
2862
3007
|
...storeMatch,
|
|
@@ -2882,9 +3027,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2882
3027
|
},
|
|
2883
3028
|
];
|
|
2884
3029
|
|
|
2885
|
-
|
|
2886
|
-
let toDate = new Date( req.query.date );
|
|
2887
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3030
|
+
|
|
2888
3031
|
const taskBaseMatch = {
|
|
2889
3032
|
// eslint-disable-next-line camelcase
|
|
2890
3033
|
// store_id,
|
|
@@ -2933,6 +3076,8 @@ export async function dashboardv1( req, res ) {
|
|
|
2933
3076
|
processedTask.aggregate( taskQuery ),
|
|
2934
3077
|
] );
|
|
2935
3078
|
|
|
3079
|
+
console.log( checklistResult );
|
|
3080
|
+
|
|
2936
3081
|
const checklistResultData =
|
|
2937
3082
|
checklistResult.status === 'fulfilled' ?
|
|
2938
3083
|
processResult( checklistResult.value ) :
|
|
@@ -3062,6 +3207,9 @@ export async function checklistv1( req, res ) {
|
|
|
3062
3207
|
// const { store_id, date, checklistStatus, searchValue } = req.query;
|
|
3063
3208
|
const { date, checklistStatus, searchValue } = req.query;
|
|
3064
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 );
|
|
3065
3213
|
|
|
3066
3214
|
// Get User Based Checklist //
|
|
3067
3215
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -3073,16 +3221,23 @@ export async function checklistv1( req, res ) {
|
|
|
3073
3221
|
// eslint-disable-next-line camelcase
|
|
3074
3222
|
// { store_id },
|
|
3075
3223
|
{ userId },
|
|
3076
|
-
{ date_string: date },
|
|
3224
|
+
// { $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
|
|
3077
3225
|
{ timeFlagStatus: true },
|
|
3078
3226
|
...matchExtraConditions,
|
|
3079
3227
|
clientId,
|
|
3080
3228
|
storeMatch,
|
|
3081
3229
|
];
|
|
3230
|
+
if ( checklistStatus != 'submit' ) {
|
|
3231
|
+
matchConditions.push( { $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] } );
|
|
3232
|
+
}
|
|
3233
|
+
if ( checklistStatus == 'submit' ) {
|
|
3234
|
+
matchConditions.push( { date_string: date } );
|
|
3235
|
+
}
|
|
3082
3236
|
if ( checklistStatus ) {
|
|
3083
3237
|
matchConditions.push( { checklistStatus } );
|
|
3084
3238
|
}
|
|
3085
3239
|
|
|
3240
|
+
|
|
3086
3241
|
const pipeline = [
|
|
3087
3242
|
{ $match: { $and: matchConditions } },
|
|
3088
3243
|
...( searchValue ?
|
|
@@ -3135,9 +3290,7 @@ export async function checklistv1( req, res ) {
|
|
|
3135
3290
|
return pipeline;
|
|
3136
3291
|
};
|
|
3137
3292
|
|
|
3138
|
-
|
|
3139
|
-
let toDate = new Date( req.query.date );
|
|
3140
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3293
|
+
|
|
3141
3294
|
const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
|
|
3142
3295
|
const matchConditions = [
|
|
3143
3296
|
// eslint-disable-next-line camelcase
|
|
@@ -3486,7 +3639,7 @@ export async function questionList( req, res ) {
|
|
|
3486
3639
|
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
3487
3640
|
} else {
|
|
3488
3641
|
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 );
|
|
3642
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3490
3643
|
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3491
3644
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3492
3645
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
@@ -3512,12 +3665,12 @@ export async function questionList( req, res ) {
|
|
|
3512
3665
|
let checkvalidation = null;
|
|
3513
3666
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3514
3667
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3515
|
-
checkvalidation =
|
|
3668
|
+
checkvalidation = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3516
3669
|
} else {
|
|
3517
3670
|
checkvalidation = answer.validationAnswer;
|
|
3518
3671
|
}
|
|
3519
3672
|
}
|
|
3520
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3673
|
+
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
|
|
3521
3674
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3522
3675
|
}
|
|
3523
3676
|
|
|
@@ -3533,23 +3686,23 @@ export async function questionList( req, res ) {
|
|
|
3533
3686
|
answer.referenceImage= `${cdnurl.TraxAnswerCDN}${answer.referenceImage}`;
|
|
3534
3687
|
}
|
|
3535
3688
|
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3536
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer =
|
|
3689
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3537
3690
|
}
|
|
3538
3691
|
}
|
|
3539
3692
|
if ( question?.userAnswer ) {
|
|
3540
3693
|
for ( let [ userAnsIndex, userAns ] of question.userAnswer.entries() ) {
|
|
3541
3694
|
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3542
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer =
|
|
3695
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${userAns.validationAnswer}`;
|
|
3543
3696
|
}
|
|
3544
3697
|
if ( userAns.validationType == 'Capture Multiple Image with description' ) {
|
|
3545
3698
|
let imageAnswers = userAns.validationImage;
|
|
3546
3699
|
userAns.validationImage = [];
|
|
3547
3700
|
for ( let image of imageAnswers ) {
|
|
3548
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationImage.push(
|
|
3701
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationImage.push( `${cdnurl.TraxAnswerCDN}${image}` );
|
|
3549
3702
|
}
|
|
3550
3703
|
}
|
|
3551
3704
|
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3552
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer
|
|
3705
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer =`${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
3553
3706
|
}
|
|
3554
3707
|
if ( userAns.referenceImage != '' ) {
|
|
3555
3708
|
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( userAns.referenceImage ), Bucket: bucket.sop } );
|
|
@@ -3856,7 +4009,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3856
4009
|
return res.sendError( 'Task Got Edited Please Fill Again', 422 );
|
|
3857
4010
|
} else {
|
|
3858
4011
|
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 );
|
|
4012
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3860
4013
|
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3861
4014
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3862
4015
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
@@ -3867,13 +4020,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3867
4020
|
if ( Array.isArray( questionReferenceImage ) ) {
|
|
3868
4021
|
questionReferenceImage = questionReferenceImage.filter( ( item ) => item != '' );
|
|
3869
4022
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = await Promise.all(
|
|
3870
|
-
questionReferenceImage.map( async ( image ) => image ?
|
|
4023
|
+
questionReferenceImage.map( async ( image ) => image ? `${cdnurl.TraxAnswerCDN}${image}` : '' ),
|
|
3871
4024
|
);
|
|
3872
4025
|
} else if ( questionReferenceImage !== '' ) {
|
|
3873
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage =
|
|
3874
|
-
file_path: decodeURIComponent( questionReferenceImage ),
|
|
3875
|
-
Bucket: bucket.sop,
|
|
3876
|
-
} );
|
|
4026
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = `${cdnurl.TraxAnswerCDN}${questionReferenceImage}`;
|
|
3877
4027
|
}
|
|
3878
4028
|
}
|
|
3879
4029
|
|
|
@@ -3884,13 +4034,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3884
4034
|
if ( Array.isArray( referenceImage ) ) {
|
|
3885
4035
|
referenceImage = referenceImage.filter( ( item ) => item != '' );
|
|
3886
4036
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = await Promise.all(
|
|
3887
|
-
referenceImage.map( async ( image ) => image ?
|
|
4037
|
+
referenceImage.map( async ( image ) => image ? `${cdnurl.TraxAnswerCDN}${image}` : '' ),
|
|
3888
4038
|
);
|
|
3889
4039
|
} else if ( referenceImage !== '' ) {
|
|
3890
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage =
|
|
3891
|
-
file_path: decodeURIComponent( referenceImage ),
|
|
3892
|
-
Bucket: bucket.sop,
|
|
3893
|
-
} );
|
|
4040
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = `${cdnurl.TraxAnswerCDN}${referenceImage}`;
|
|
3894
4041
|
}
|
|
3895
4042
|
}
|
|
3896
4043
|
|
|
@@ -3898,7 +4045,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3898
4045
|
let checkvalidation = null;
|
|
3899
4046
|
if ( answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3900
4047
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3901
|
-
checkvalidation =
|
|
4048
|
+
checkvalidation = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3902
4049
|
} else {
|
|
3903
4050
|
checkvalidation = answer.validationAnswer;
|
|
3904
4051
|
}
|
|
@@ -3907,10 +4054,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3907
4054
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3908
4055
|
}
|
|
3909
4056
|
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
|
-
} );
|
|
4057
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3914
4058
|
}
|
|
3915
4059
|
}
|
|
3916
4060
|
|
|
@@ -3921,25 +4065,16 @@ export async function taskQuestionList( req, res ) {
|
|
|
3921
4065
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].linearType = question.answers[0].linearType;
|
|
3922
4066
|
}
|
|
3923
4067
|
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
|
-
} );
|
|
4068
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${userAns.validationAnswer}`;
|
|
3928
4069
|
}
|
|
3929
4070
|
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
|
-
} );
|
|
4071
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = `${cdnurl.TraxAnswerCDN}${rawAnswer}`;
|
|
3934
4072
|
}
|
|
3935
4073
|
if ( question.answerType == 'image/video' && rawAnswer != '' ) {
|
|
3936
4074
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = `${cdnurl.TraxAnswerCDN}${rawAnswer}`;
|
|
3937
4075
|
}
|
|
3938
4076
|
if ( userAns.referenceImage != '' ) {
|
|
3939
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage =
|
|
3940
|
-
file_path: decodeURIComponent( userAns.referenceImage ),
|
|
3941
|
-
Bucket: bucket.sop,
|
|
3942
|
-
} );
|
|
4077
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = `${cdnurl.TraxAnswerCDN}${userAns.referenceImage}`;
|
|
3943
4078
|
}
|
|
3944
4079
|
if ( question.answerType == 'multiplechoicemultiple' || ( question.answerType == 'dropdown' && question.allowMultiple ) ) {
|
|
3945
4080
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == rawAnswer );
|