tango-app-api-trax 3.8.19 → 3.8.20-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 +336 -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
|
@@ -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
|
}
|
|
@@ -671,7 +668,7 @@ export async function sopMobilechecklistQuestionValidatorv1( req, res, next ) {
|
|
|
671
668
|
validationCount++;
|
|
672
669
|
}
|
|
673
670
|
} else {
|
|
674
|
-
if ( ( !
|
|
671
|
+
if ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) {
|
|
675
672
|
validationCount++;
|
|
676
673
|
}
|
|
677
674
|
}
|
|
@@ -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;
|
|
@@ -1557,6 +1589,18 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1557
1589
|
|
|
1558
1590
|
requestData.questionAnswers = sectionFormat;
|
|
1559
1591
|
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
1592
|
+
|
|
1593
|
+
if ( requestData.submittype == 'submit' ) {
|
|
1594
|
+
for ( let section of sectionFormat ) {
|
|
1595
|
+
for ( let question of section.questions ) {
|
|
1596
|
+
let mustValidate = !question.linkType || ( question.linkType && question.linkquestionenabled );
|
|
1597
|
+
if ( mustValidate && ( !question.userAnswer || !question.userAnswer.length ) ) {
|
|
1598
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1560
1604
|
next();
|
|
1561
1605
|
} catch ( error ) {
|
|
1562
1606
|
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
@@ -1937,7 +1981,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
1937
1981
|
let des = [];
|
|
1938
1982
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1939
1983
|
let validationAnswer = '';
|
|
1940
|
-
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1984
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
1941
1985
|
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1942
1986
|
}
|
|
1943
1987
|
if ( validationAnswer.length ) {
|
|
@@ -2034,6 +2078,102 @@ function QuestionFlag( req, res ) {
|
|
|
2034
2078
|
}
|
|
2035
2079
|
}
|
|
2036
2080
|
|
|
2081
|
+
async function updateRecurringFlagTracker( processedChecklist, questionAnswers, currentDateTime ) {
|
|
2082
|
+
try {
|
|
2083
|
+
if ( !processedChecklist?.sourceCheckList_id ) return;
|
|
2084
|
+
|
|
2085
|
+
const isUserBased = processedChecklist?.coverage === 'user';
|
|
2086
|
+
const storeId = isUserBased ? '' : ( processedChecklist?.store_id || '' );
|
|
2087
|
+
const userId = isUserBased ? ( processedChecklist?.userId ? String( processedChecklist.userId ) : ( processedChecklist?.userEmail || '' ) ) : '';
|
|
2088
|
+
if ( !isUserBased && !storeId ) return;
|
|
2089
|
+
if ( isUserBased && !userId ) return;
|
|
2090
|
+
|
|
2091
|
+
const today = currentDateTime ? currentDateTime.format( 'YYYY-MM-DD' ) : dayjs().format( 'YYYY-MM-DD' );
|
|
2092
|
+
const yesterday = dayjs( today, 'YYYY-MM-DD' ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
|
|
2093
|
+
|
|
2094
|
+
const trackerKeyBase = {
|
|
2095
|
+
client_id: processedChecklist.client_id,
|
|
2096
|
+
sourceCheckList_id: processedChecklist.sourceCheckList_id,
|
|
2097
|
+
...( isUserBased ) ? { user_id: userId } : { store_id: storeId },
|
|
2098
|
+
};
|
|
2099
|
+
|
|
2100
|
+
const existingRows = await recurringFlagTracker.find( trackerKeyBase, { section_id: 1, qno: 1, consecutiveCount: 1, lastFlaggedDate: 1 } );
|
|
2101
|
+
const existingMap = new Map();
|
|
2102
|
+
for ( const r of existingRows ) {
|
|
2103
|
+
existingMap.set( `${r.section_id || ''}::${r.qno || ''}`, r );
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
const ops = [];
|
|
2107
|
+
|
|
2108
|
+
( questionAnswers || [] ).forEach( ( section ) => {
|
|
2109
|
+
( section?.questions || [] ).forEach( ( question ) => {
|
|
2110
|
+
const sectionId = section?.section_id || '';
|
|
2111
|
+
const qno = question?.qno || '';
|
|
2112
|
+
if ( qno === '' ) return;
|
|
2113
|
+
|
|
2114
|
+
const flaggedNow = Array.isArray( question?.userAnswer ) && question.userAnswer.some( ( a ) => a?.sopFlag === true );
|
|
2115
|
+
const key = `${sectionId}::${qno}`;
|
|
2116
|
+
const existing = existingMap.get( key );
|
|
2117
|
+
console.log( flaggedNow, 'test' );
|
|
2118
|
+
if ( flaggedNow ) {
|
|
2119
|
+
let newCount;
|
|
2120
|
+
if ( !existing ) {
|
|
2121
|
+
newCount = 1;
|
|
2122
|
+
} else if ( existing.lastFlaggedDate === today ) {
|
|
2123
|
+
// Multi-submit on same day: already counted, no-op.
|
|
2124
|
+
return;
|
|
2125
|
+
} else if ( existing.lastFlaggedDate === yesterday ) {
|
|
2126
|
+
newCount = ( existing.consecutiveCount || 0 ) + 1;
|
|
2127
|
+
} else {
|
|
2128
|
+
// Gap broke the streak — fresh start.
|
|
2129
|
+
newCount = 1;
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
ops.push( {
|
|
2133
|
+
updateOne: {
|
|
2134
|
+
filter: { ...trackerKeyBase, section_id: sectionId, qno },
|
|
2135
|
+
update: {
|
|
2136
|
+
$set: {
|
|
2137
|
+
coverage: isUserBased ? 'user' : 'store',
|
|
2138
|
+
checkListName: processedChecklist.checkListName,
|
|
2139
|
+
storeName: isUserBased ? '' : ( processedChecklist.storeName || '' ),
|
|
2140
|
+
userName: processedChecklist.userName || '',
|
|
2141
|
+
userEmail: processedChecklist.userEmail || '',
|
|
2142
|
+
sectionName: section?.sectionName || '',
|
|
2143
|
+
qname: question?.qname || '',
|
|
2144
|
+
consecutiveCount: newCount,
|
|
2145
|
+
lastFlaggedDate: today,
|
|
2146
|
+
lastSubmittedBy: processedChecklist.userName || processedChecklist.userEmail || '--',
|
|
2147
|
+
lastSubmissionDate: currentDateTime ? currentDateTime.format( 'hh:mm A, DD MMM YYYY' ) : today,
|
|
2148
|
+
},
|
|
2149
|
+
},
|
|
2150
|
+
upsert: true,
|
|
2151
|
+
},
|
|
2152
|
+
} );
|
|
2153
|
+
} else if ( existing && ( existing.consecutiveCount || 0 ) > 0 ) {
|
|
2154
|
+
// Question answered correctly today — break the streak.
|
|
2155
|
+
ops.push( {
|
|
2156
|
+
updateOne: {
|
|
2157
|
+
filter: { ...trackerKeyBase, section_id: sectionId, qno },
|
|
2158
|
+
update: { $set: { lastFlaggedDate: today } },
|
|
2159
|
+
},
|
|
2160
|
+
} );
|
|
2161
|
+
}
|
|
2162
|
+
} );
|
|
2163
|
+
} );
|
|
2164
|
+
if ( ops.length ) {
|
|
2165
|
+
try {
|
|
2166
|
+
let data = await recurringFlagTracker.bulkWrite( ops, { ordered: false } );
|
|
2167
|
+
console.log( 'recurringFlagTracker bulkWrite result', data );
|
|
2168
|
+
} catch ( bulkErr ) {
|
|
2169
|
+
logger.error( { function: 'updateRecurringFlagTracker.bulkWrite', code: bulkErr?.code, message: bulkErr?.message, writeErrors: bulkErr?.writeErrors } );
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
} catch ( error ) {
|
|
2173
|
+
logger.error( { function: 'updateRecurringFlagTracker', error } );
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2037
2177
|
export async function submitChecklist( req, res ) {
|
|
2038
2178
|
try {
|
|
2039
2179
|
let requestData = req.body;
|
|
@@ -2081,6 +2221,7 @@ export async function submitChecklist( req, res ) {
|
|
|
2081
2221
|
let flagCount = QuestionFlag( req, res );
|
|
2082
2222
|
updateData.questionFlag = flagCount;
|
|
2083
2223
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
2224
|
+
updateData.redoEdit = false;
|
|
2084
2225
|
if ( requestData.deviceDetails && requestData.deviceDetails != '' ) {
|
|
2085
2226
|
updateData.deviceDetails =JSON.parse( requestData.deviceDetails );
|
|
2086
2227
|
}
|
|
@@ -2169,6 +2310,10 @@ export async function submitChecklist( req, res ) {
|
|
|
2169
2310
|
// };
|
|
2170
2311
|
// await detectionService.create( detectionData );
|
|
2171
2312
|
if ( requestData.submittype == 'submit' ) {
|
|
2313
|
+
console.log( checklistDetails?.recurringFlag?.notifyType?.length );
|
|
2314
|
+
if ( checklistDetails?.recurringFlag?.notifyType?.length ) {
|
|
2315
|
+
updateRecurringFlagTracker( getchecklist[0], requestData.questionAnswers, currentDateTime );
|
|
2316
|
+
}
|
|
2172
2317
|
updateOpenSearch( req.user, requestData );
|
|
2173
2318
|
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2174
2319
|
// console.log( 'openSearch', openSearch );
|
|
@@ -2349,7 +2494,8 @@ export async function submitTask( req, res ) {
|
|
|
2349
2494
|
'storeResponseTime': currentDateTime.format( 'HH:mm:ss - MMM DD, YYYY' ),
|
|
2350
2495
|
'message_mode': 'retriggered',
|
|
2351
2496
|
};
|
|
2352
|
-
sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
2497
|
+
let sqsResponse = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
|
|
2498
|
+
console.log( sqsResponse );
|
|
2353
2499
|
}
|
|
2354
2500
|
if ( !excludedChecklists.includes( checklist.checkListName ) ) {
|
|
2355
2501
|
const query1 = [
|
|
@@ -2854,6 +3000,9 @@ export async function dashboardv1( req, res ) {
|
|
|
2854
3000
|
// const { store_id, date } = req.query;
|
|
2855
3001
|
const { date } = req.query;
|
|
2856
3002
|
const userId = req.user._id;
|
|
3003
|
+
let fromDate = new Date( req.query.date );
|
|
3004
|
+
let toDate = new Date( req.query.date );
|
|
3005
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
2857
3006
|
|
|
2858
3007
|
// //Get User Based Checklist //
|
|
2859
3008
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -2870,7 +3019,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2870
3019
|
...storeMatch,
|
|
2871
3020
|
};
|
|
2872
3021
|
const buildPipeline = ( matchExtraConditions = {} ) => [
|
|
2873
|
-
{ $match: { ...baseMatch, ...matchExtraConditions } },
|
|
3022
|
+
{ $match: { $or: [ { ...baseMatch, ...matchExtraConditions }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } }, { userId }, { ...storeMatch } ] } ] } },
|
|
2874
3023
|
{
|
|
2875
3024
|
$facet: {
|
|
2876
3025
|
total: [ { $count: 'total' } ],
|
|
@@ -2890,9 +3039,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2890
3039
|
},
|
|
2891
3040
|
];
|
|
2892
3041
|
|
|
2893
|
-
|
|
2894
|
-
let toDate = new Date( req.query.date );
|
|
2895
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3042
|
+
|
|
2896
3043
|
const taskBaseMatch = {
|
|
2897
3044
|
// eslint-disable-next-line camelcase
|
|
2898
3045
|
// store_id,
|
|
@@ -2941,6 +3088,8 @@ export async function dashboardv1( req, res ) {
|
|
|
2941
3088
|
processedTask.aggregate( taskQuery ),
|
|
2942
3089
|
] );
|
|
2943
3090
|
|
|
3091
|
+
console.log( checklistResult );
|
|
3092
|
+
|
|
2944
3093
|
const checklistResultData =
|
|
2945
3094
|
checklistResult.status === 'fulfilled' ?
|
|
2946
3095
|
processResult( checklistResult.value ) :
|
|
@@ -3070,6 +3219,9 @@ export async function checklistv1( req, res ) {
|
|
|
3070
3219
|
// const { store_id, date, checklistStatus, searchValue } = req.query;
|
|
3071
3220
|
const { date, checklistStatus, searchValue } = req.query;
|
|
3072
3221
|
const userId = req.user._id;
|
|
3222
|
+
let fromDate = new Date( req.query.date );
|
|
3223
|
+
let toDate = new Date( req.query.date );
|
|
3224
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
3073
3225
|
|
|
3074
3226
|
// Get User Based Checklist //
|
|
3075
3227
|
const clientId = { client_id: req.user.clientId };
|
|
@@ -3081,16 +3233,18 @@ export async function checklistv1( req, res ) {
|
|
|
3081
3233
|
// eslint-disable-next-line camelcase
|
|
3082
3234
|
// { store_id },
|
|
3083
3235
|
{ userId },
|
|
3084
|
-
{ date_string: date },
|
|
3236
|
+
{ $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
|
|
3085
3237
|
{ timeFlagStatus: true },
|
|
3086
3238
|
...matchExtraConditions,
|
|
3087
3239
|
clientId,
|
|
3088
3240
|
storeMatch,
|
|
3089
3241
|
];
|
|
3242
|
+
|
|
3090
3243
|
if ( checklistStatus ) {
|
|
3091
3244
|
matchConditions.push( { checklistStatus } );
|
|
3092
3245
|
}
|
|
3093
3246
|
|
|
3247
|
+
|
|
3094
3248
|
const pipeline = [
|
|
3095
3249
|
{ $match: { $and: matchConditions } },
|
|
3096
3250
|
...( searchValue ?
|
|
@@ -3143,9 +3297,7 @@ export async function checklistv1( req, res ) {
|
|
|
3143
3297
|
return pipeline;
|
|
3144
3298
|
};
|
|
3145
3299
|
|
|
3146
|
-
|
|
3147
|
-
let toDate = new Date( req.query.date );
|
|
3148
|
-
toDate.setDate( toDate.getDate() + 1 );
|
|
3300
|
+
|
|
3149
3301
|
const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
|
|
3150
3302
|
const matchConditions = [
|
|
3151
3303
|
// eslint-disable-next-line camelcase
|
|
@@ -3494,7 +3646,7 @@ export async function questionList( req, res ) {
|
|
|
3494
3646
|
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
3495
3647
|
} else {
|
|
3496
3648
|
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 );
|
|
3649
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3498
3650
|
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3499
3651
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3500
3652
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
@@ -3520,12 +3672,12 @@ export async function questionList( req, res ) {
|
|
|
3520
3672
|
let checkvalidation = null;
|
|
3521
3673
|
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3522
3674
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3523
|
-
checkvalidation =
|
|
3675
|
+
checkvalidation = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3524
3676
|
} else {
|
|
3525
3677
|
checkvalidation = answer.validationAnswer;
|
|
3526
3678
|
}
|
|
3527
3679
|
}
|
|
3528
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3680
|
+
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
|
|
3529
3681
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3530
3682
|
}
|
|
3531
3683
|
|
|
@@ -3541,23 +3693,23 @@ export async function questionList( req, res ) {
|
|
|
3541
3693
|
answer.referenceImage= `${cdnurl.TraxAnswerCDN}${answer.referenceImage}`;
|
|
3542
3694
|
}
|
|
3543
3695
|
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3544
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer =
|
|
3696
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3545
3697
|
}
|
|
3546
3698
|
}
|
|
3547
3699
|
if ( question?.userAnswer ) {
|
|
3548
3700
|
for ( let [ userAnsIndex, userAns ] of question.userAnswer.entries() ) {
|
|
3549
3701
|
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3550
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer =
|
|
3702
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${userAns.validationAnswer}`;
|
|
3551
3703
|
}
|
|
3552
3704
|
if ( userAns.validationType == 'Capture Multiple Image with description' ) {
|
|
3553
3705
|
let imageAnswers = userAns.validationImage;
|
|
3554
3706
|
userAns.validationImage = [];
|
|
3555
3707
|
for ( let image of imageAnswers ) {
|
|
3556
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationImage.push(
|
|
3708
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationImage.push( `${cdnurl.TraxAnswerCDN}${image}` );
|
|
3557
3709
|
}
|
|
3558
3710
|
}
|
|
3559
3711
|
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3560
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer
|
|
3712
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer =`${cdnurl.TraxAnswerCDN}${userAns.answer}`;
|
|
3561
3713
|
}
|
|
3562
3714
|
if ( userAns.referenceImage != '' ) {
|
|
3563
3715
|
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( userAns.referenceImage ), Bucket: bucket.sop } );
|
|
@@ -3864,7 +4016,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3864
4016
|
return res.sendError( 'Task Got Edited Please Fill Again', 422 );
|
|
3865
4017
|
} else {
|
|
3866
4018
|
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 );
|
|
4019
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3868
4020
|
let cdnurl = JSON.parse( process.env.CDNURL );
|
|
3869
4021
|
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3870
4022
|
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
@@ -3875,13 +4027,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3875
4027
|
if ( Array.isArray( questionReferenceImage ) ) {
|
|
3876
4028
|
questionReferenceImage = questionReferenceImage.filter( ( item ) => item != '' );
|
|
3877
4029
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = await Promise.all(
|
|
3878
|
-
questionReferenceImage.map( async ( image ) => image ?
|
|
4030
|
+
questionReferenceImage.map( async ( image ) => image ? `${cdnurl.TraxAnswerCDN}${image}` : '' ),
|
|
3879
4031
|
);
|
|
3880
4032
|
} else if ( questionReferenceImage !== '' ) {
|
|
3881
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage =
|
|
3882
|
-
file_path: decodeURIComponent( questionReferenceImage ),
|
|
3883
|
-
Bucket: bucket.sop,
|
|
3884
|
-
} );
|
|
4033
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = `${cdnurl.TraxAnswerCDN}${questionReferenceImage}`;
|
|
3885
4034
|
}
|
|
3886
4035
|
}
|
|
3887
4036
|
|
|
@@ -3892,13 +4041,10 @@ export async function taskQuestionList( req, res ) {
|
|
|
3892
4041
|
if ( Array.isArray( referenceImage ) ) {
|
|
3893
4042
|
referenceImage = referenceImage.filter( ( item ) => item != '' );
|
|
3894
4043
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = await Promise.all(
|
|
3895
|
-
referenceImage.map( async ( image ) => image ?
|
|
4044
|
+
referenceImage.map( async ( image ) => image ? `${cdnurl.TraxAnswerCDN}${image}` : '' ),
|
|
3896
4045
|
);
|
|
3897
4046
|
} else if ( referenceImage !== '' ) {
|
|
3898
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage =
|
|
3899
|
-
file_path: decodeURIComponent( referenceImage ),
|
|
3900
|
-
Bucket: bucket.sop,
|
|
3901
|
-
} );
|
|
4047
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = `${cdnurl.TraxAnswerCDN}${referenceImage}`;
|
|
3902
4048
|
}
|
|
3903
4049
|
}
|
|
3904
4050
|
|
|
@@ -3906,7 +4052,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3906
4052
|
let checkvalidation = null;
|
|
3907
4053
|
if ( answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3908
4054
|
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3909
|
-
checkvalidation =
|
|
4055
|
+
checkvalidation = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3910
4056
|
} else {
|
|
3911
4057
|
checkvalidation = answer.validationAnswer;
|
|
3912
4058
|
}
|
|
@@ -3915,10 +4061,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
3915
4061
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3916
4062
|
}
|
|
3917
4063
|
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
|
-
} );
|
|
4064
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${answer.validationAnswer}`;
|
|
3922
4065
|
}
|
|
3923
4066
|
}
|
|
3924
4067
|
|
|
@@ -3929,25 +4072,16 @@ export async function taskQuestionList( req, res ) {
|
|
|
3929
4072
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].linearType = question.answers[0].linearType;
|
|
3930
4073
|
}
|
|
3931
4074
|
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
|
-
} );
|
|
4075
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = `${cdnurl.TraxAnswerCDN}${userAns.validationAnswer}`;
|
|
3936
4076
|
}
|
|
3937
4077
|
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
|
-
} );
|
|
4078
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = `${cdnurl.TraxAnswerCDN}${rawAnswer}`;
|
|
3942
4079
|
}
|
|
3943
4080
|
if ( question.answerType == 'image/video' && rawAnswer != '' ) {
|
|
3944
4081
|
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = `${cdnurl.TraxAnswerCDN}${rawAnswer}`;
|
|
3945
4082
|
}
|
|
3946
4083
|
if ( userAns.referenceImage != '' ) {
|
|
3947
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage =
|
|
3948
|
-
file_path: decodeURIComponent( userAns.referenceImage ),
|
|
3949
|
-
Bucket: bucket.sop,
|
|
3950
|
-
} );
|
|
4084
|
+
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = `${cdnurl.TraxAnswerCDN}${userAns.referenceImage}`;
|
|
3951
4085
|
}
|
|
3952
4086
|
if ( question.answerType == 'multiplechoicemultiple' || ( question.answerType == 'dropdown' && question.allowMultiple ) ) {
|
|
3953
4087
|
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == rawAnswer );
|