tango-app-api-trax 3.8.22 → 3.8.23-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.
@@ -118,7 +118,7 @@ export async function startChecklist( req, res ) {
118
118
  $and: [
119
119
  { _id: new ObjectId( requestData.processedcheckListId ) },
120
120
  { userId: req.user._id },
121
- { date_string: requestData.date },
121
+ { $or: [ { date_string: requestData.date }, { redoStatus: true } ] },
122
122
  ],
123
123
  },
124
124
  } );
@@ -137,7 +137,9 @@ export async function startChecklist( req, res ) {
137
137
  let updateQuery = {};
138
138
  updateQuery._id = new ObjectId( requestData.processedcheckListId );
139
139
  updateQuery.userId = req.user._id;
140
- updateQuery.date_string = requestData.date;
140
+ if ( getBeforeChecklist?.[0]?.date_string == dayjs().format( 'YYYY-MM-DD' ) ) {
141
+ updateQuery.date_string = requestData.date;
142
+ }
141
143
 
142
144
  if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
143
145
  await PCLQusestion.questionAnswers.forEach( ( section ) => {
@@ -317,7 +319,7 @@ export async function startChecklist( req, res ) {
317
319
  return res.sendError( 'something went wrong please try again', 500 );
318
320
  }
319
321
  } catch ( e ) {
320
- // console.log( 'e =>', e );
322
+ console.log( 'e =>', e );
321
323
  logger.error( { function: 'startChecklist', error: e, body: req.body } );
322
324
  return res.sendError( e, 500 );
323
325
  }
@@ -467,7 +469,7 @@ export async function startTask( req, res ) {
467
469
  } );
468
470
  const getUpdatedTask = await processedTask.aggregate( findQuery );
469
471
 
470
-
472
+ let cdnurl = JSON.parse( process.env.CDNURL );
471
473
  if ( !( task.checkListFrom && task.checkListFrom == 'api' ) ) {
472
474
  // const bucket = JSON.parse( process.env.BUCKET );
473
475
  await Promise.all(
@@ -661,12 +663,12 @@ export async function sopMobilechecklistQuestionValidatorv1( req, res, next ) {
661
663
  let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
662
664
  if ( sectionQuestion.length ) {
663
665
  if ( requestData.submittype == 'submit' ) {
664
- if ( ( [ 'multipleImage', 'multiplechoicemultiple' ].includes( question.answerType ) || ( question.answerType =='dropdown' && question.allowMultiple ) ) ) {
666
+ if ( ( [ 'multipleImage', 'multiplechoicemultiple', 'image/video' ].includes( question.answerType ) || ( question.answerType =='dropdown' && question.allowMultiple ) ) ) {
665
667
  if ( ( !sectionQuestion[0].linkType || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled ) ) && ( sectionQuestion[0].Multianswer == null || sectionQuestion[0].Multianswer == '' || !sectionQuestion[0].Multianswer.length ) ) {
666
668
  validationCount++;
667
669
  }
668
670
  } else {
669
- if ( ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( question.answerType ) && ( question.answerType =='dropdown' && !question.allowMultiple ) ) && ( ( !sectionQuestion[0].linkType && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) || ( sectionQuestion[0].linkType && sectionQuestion[0].linkquestionenabled && ( sectionQuestion[0].answer == null || sectionQuestion[0].answer == '' ) ) ) ) {
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 == '' ) ) ) {
670
672
  validationCount++;
671
673
  }
672
674
  }
@@ -1082,12 +1084,15 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1082
1084
  try {
1083
1085
  let requestData = req.body;
1084
1086
  requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
1085
- 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 } );
1086
1088
  let reqAnswers = requestData.questionAnswers;
1087
1089
  logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
1088
1090
  let CLQAnswers = getChecklistQA.questionAnswers;
1089
1091
 
1090
1092
  if ( requestData.submittype == 'submit' ) {
1093
+ if ( getChecklistQA?.redoEdit ) {
1094
+ requestData.submittype = 'draft';
1095
+ }
1091
1096
  reqAnswers.forEach( ( reqA ) => {
1092
1097
  if ( ![ 'multiplechoicemultiple', 'multipleImage', 'image/video' ].includes( reqA?.answerType ) && ( reqA.answerType == 'dropDown' && !reqA.allowMultiple ) ) {
1093
1098
  if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
@@ -1172,26 +1177,31 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1172
1177
  for ( let j = 0; j < qaAnswers.length; j++ ) {
1173
1178
  if ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) {
1174
1179
  if ( qaAnswers[j].answerType == 'yes/no' ) {
1175
- let qaans = qaAnswers[j].answers;
1180
+ let qaans = JSON.stringify( JSON.parse( qaAnswers[j].answers ) );
1176
1181
  let yn = [];
1177
- for ( let k = 0; k < qaans.length; k++ ) {
1178
- if ( requestSection[i].answer == qaans[k].answer ) {
1179
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1180
- if ( requestSection[i].validationAnswer ) {
1181
- let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1182
- if ( validateAns.length ) {
1183
- let splitImgUrl = validateAns.split( '/' );
1184
- if ( splitImgUrl.length > 1 ) {
1185
- splitImgUrl.splice( 0, 3 );
1186
- qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
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
+ }
1187
1194
  }
1188
1195
  }
1196
+ } else {
1197
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1198
+ qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1189
1199
  }
1190
- } else {
1191
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1192
- qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1200
+ if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
1201
+ qaans[k].runAIData = requestSection[i].runAIData;
1202
+ }
1203
+ yn.push( qaans[k] );
1193
1204
  }
1194
- yn.push( qaans[k] );
1195
1205
  }
1196
1206
  }
1197
1207
  let structure = {};
@@ -1203,7 +1213,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1203
1213
  structure.runAI = qaAnswers[j].runAI;
1204
1214
  structure.runAIDescription = qaAnswers[j].runAIDescription;
1205
1215
  structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
1206
- structure.remarks = requestSection[i].remarks;
1216
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1217
+ structure.remarks = requestSection[i].remarks;
1218
+ }
1207
1219
  structure.answers = qaAnswers[j].answers;
1208
1220
  structure.userAnswer = yn;
1209
1221
  structure.linkType = qaAnswers[j].linkType;
@@ -1229,41 +1241,46 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1229
1241
  };
1230
1242
  newArray.push( structure );
1231
1243
  } else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
1232
- let qaans = qaAnswers[j].answers;
1244
+ let qaans = JSON.stringify( JSON.parse( qaAnswers[j].answers ) );
1233
1245
  let ms = [];
1234
- for ( let k = 0; k < qaans.length; k++ ) {
1235
- if ( requestSection[i].answer == qaans[k].answer ) {
1236
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1237
- if ( requestSection[i].validationAnswer ) {
1238
- let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1239
- if ( validationAnswer.length ) {
1240
- let splitImgUrl = validationAnswer.split( '/' );
1241
- if ( splitImgUrl.length > 1 ) {
1242
- splitImgUrl.splice( 0, 3 );
1243
- qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1246
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1247
+ for ( let k = 0; k < qaans.length; k++ ) {
1248
+ if ( requestSection[i].answer == qaans[k].answer ) {
1249
+ if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1250
+ if ( requestSection[i].validationAnswer ) {
1251
+ let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
1252
+ if ( validationAnswer.length ) {
1253
+ let splitImgUrl = validationAnswer.split( '/' );
1254
+ if ( splitImgUrl.length > 1 ) {
1255
+ splitImgUrl.splice( 0, 3 );
1256
+ qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1257
+ }
1244
1258
  }
1245
1259
  }
1246
- }
1247
- } else {
1248
- if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
1249
- qaans[k]['validationImage']=[];
1250
- if ( requestSection[i].validationImage.length ) {
1251
- for ( let image of requestSection[i].validationImage ) {
1252
- let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
1253
- if ( validationAnswer.length ) {
1254
- let splitImgUrl = validationAnswer.split( '/' );
1255
- if ( splitImgUrl.length > 1 ) {
1256
- splitImgUrl.splice( 0, 3 );
1257
- qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
1258
- }
1259
- };
1260
+ } else {
1261
+ if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
1262
+ qaans[k]['validationImage']=[];
1263
+ if ( requestSection[i].validationImage.length ) {
1264
+ for ( let image of requestSection[i].validationImage ) {
1265
+ let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
1266
+ if ( validationAnswer.length ) {
1267
+ let splitImgUrl = validationAnswer.split( '/' );
1268
+ if ( splitImgUrl.length > 1 ) {
1269
+ splitImgUrl.splice( 0, 3 );
1270
+ qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
1271
+ }
1272
+ };
1273
+ }
1260
1274
  }
1261
1275
  }
1276
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1277
+ qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1262
1278
  }
1263
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1264
- qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1279
+ if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
1280
+ qaans[k].runAIData = requestSection[i].runAIData;
1281
+ }
1282
+ ms.push( qaans[k] );
1265
1283
  }
1266
- ms.push( qaans[k] );
1267
1284
  }
1268
1285
  }
1269
1286
  let structure = {};
@@ -1275,7 +1292,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1275
1292
  structure.runAI = qaAnswers[j].runAI;
1276
1293
  structure.runAIDescription = qaAnswers[j].runAIDescription;
1277
1294
  structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
1278
- structure.remarks = requestSection[i].remarks;
1295
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1296
+ structure.remarks = requestSection[i].remarks;
1297
+ }
1279
1298
  structure.answers = qaAnswers[j].answers;
1280
1299
  structure.userAnswer = ms;
1281
1300
  structure.linkType = qaAnswers[j].linkType;
@@ -1302,32 +1321,44 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1302
1321
  };
1303
1322
  newArray.push( structure );
1304
1323
  } else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
1305
- let qaans = qaAnswers[j].answers;
1324
+ let qaans = JSON.stringify( JSON.parse( qaAnswers[j].answers ) );
1306
1325
  let mcmo = [];
1307
- for ( let k = 0; k < qaans.length; k++ ) {
1308
- let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
1309
- for ( let s = 0; s < separatedArray.length; s++ ) {
1310
- if ( separatedArray[s].answer == qaans[k].answer ) {
1311
- if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1312
- if ( separatedArray[s].validationAnswer ) {
1313
- let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
1314
- if ( validationAnswer.length ) {
1315
- let splitImgUrl = validationAnswer.split( '/' );
1316
- if ( splitImgUrl.length > 1 ) {
1317
- splitImgUrl.splice( 0, 3 );
1318
- qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1326
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1327
+ for ( let k = 0; k < qaans.length; k++ ) {
1328
+ let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
1329
+ for ( let s = 0; s < separatedArray.length; s++ ) {
1330
+ if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
1331
+ if ( ( getChecklistQA?.redoEdit && qaans[k].redo == separatedArray[s].redo ) || !getChecklistQA?.redoEdit ) {
1332
+ if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
1333
+ if ( separatedArray[s].validationAnswer ) {
1334
+ let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
1335
+ if ( validationAnswer.length ) {
1336
+ let splitImgUrl = validationAnswer.split( '/' );
1337
+ if ( splitImgUrl.length > 1 ) {
1338
+ splitImgUrl.splice( 0, 3 );
1339
+ qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
1340
+ }
1341
+ }
1319
1342
  }
1343
+ } else {
1344
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1345
+ qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
1346
+ }
1347
+ if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
1348
+ qaans[k].runAIData = separatedArray[s].runAIData;
1320
1349
  }
1321
1350
  }
1322
- } else {
1323
- // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1324
- qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
1351
+ mcmo.push( qaans[k] );
1325
1352
  }
1326
-
1327
- mcmo.push( qaans[k] );
1328
1353
  }
1329
1354
  }
1330
1355
  }
1356
+ qaAnswers[j].answers.forEach( ( ele ) => {
1357
+ if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1358
+ ele.redo = false;
1359
+ }
1360
+ } );
1361
+
1331
1362
  let structure = {};
1332
1363
  structure.qno = qaAnswers[j].qno;
1333
1364
  structure.uniqueqno = qaAnswers[j].uniqueqno;
@@ -1337,7 +1368,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1337
1368
  structure.runAI = qaAnswers[j].runAI;
1338
1369
  structure.runAIDescription = qaAnswers[j].runAIDescription;
1339
1370
  structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
1340
- structure.remarks = requestSection[i].remarks;
1371
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1372
+ structure.remarks = requestSection[i].remarks;
1373
+ }
1341
1374
  structure.answers = qaAnswers[j].answers;
1342
1375
  structure.userAnswer = mcmo;
1343
1376
  structure.linkType = qaAnswers[j].linkType;
@@ -1366,37 +1399,42 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1366
1399
  } else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
1367
1400
  let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
1368
1401
  let mcmi = [];
1402
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1369
1403
  // for (let k = 0; k < qaans.length; k++) {
1370
- for ( let s = 0; s < separatedArray.length; s++ ) {
1371
- if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
1372
- let newAnswer = {};
1373
- let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
1374
- if ( validationAnswer.length ) {
1375
- let splitImgUrl = validationAnswer.split( '/' );
1376
- if ( splitImgUrl.length > 1 ) {
1377
- splitImgUrl.splice( 0, 3 );
1378
- newAnswer.answer = splitImgUrl.join( '/' ) || '';
1404
+ for ( let s = 0; s < separatedArray.length; s++ ) {
1405
+ if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
1406
+ let newAnswer = {};
1407
+ let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
1408
+ if ( validationAnswer.length ) {
1409
+ let splitImgUrl = validationAnswer.split( '/' );
1410
+ if ( splitImgUrl.length > 1 ) {
1411
+ splitImgUrl.splice( 0, 3 );
1412
+ newAnswer.answer = splitImgUrl.join( '/' ) || '';
1413
+ }
1379
1414
  }
1380
- }
1381
1415
 
1382
- newAnswer.answeroptionNumber = 0;
1383
- newAnswer.sopFlag = false;
1384
- newAnswer.validation = false;
1385
- newAnswer.validationType = '';
1386
- newAnswer.referenceImage = '';
1387
- newAnswer.allowUploadfromGallery = false;
1388
- newAnswer.descriptivetype = '';
1389
- newAnswer.showLinked = false;
1390
- newAnswer.linkedQuestion = 0;
1391
- newAnswer.nestedQuestion = [];
1392
- newAnswer.index = s;
1393
- newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
1394
- newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
1395
- newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
1396
- if ( qaAnswers[j].answerType == 'image/video' ) {
1397
- newAnswer.answerType = separatedArray[s].answerType;
1416
+ newAnswer.answeroptionNumber = 0;
1417
+ newAnswer.sopFlag = false;
1418
+ newAnswer.validation = false;
1419
+ newAnswer.validationType = '';
1420
+ newAnswer.referenceImage = '';
1421
+ newAnswer.allowUploadfromGallery = false;
1422
+ newAnswer.descriptivetype = '';
1423
+ newAnswer.showLinked = false;
1424
+ newAnswer.linkedQuestion = 0;
1425
+ newAnswer.nestedQuestion = [];
1426
+ newAnswer.index = s;
1427
+ newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
1428
+ newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
1429
+ newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
1430
+ if ( qaAnswers[j].answerType == 'image/video' ) {
1431
+ newAnswer.answerType = separatedArray[s].answerType;
1432
+ }
1433
+ if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
1434
+ newAnswer.runAIData = separatedArray[s].runAIData;
1435
+ }
1436
+ mcmi.push( newAnswer );
1398
1437
  }
1399
- mcmi.push( newAnswer );
1400
1438
  }
1401
1439
  }
1402
1440
  // }
@@ -1409,7 +1447,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1409
1447
  structure.runAI = qaAnswers[j].runAI;
1410
1448
  structure.runAIDescription = qaAnswers[j].runAIDescription;
1411
1449
  structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
1412
- structure.remarks = requestSection[i].remarks;
1450
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1451
+ structure.remarks = requestSection[i].remarks;
1452
+ }
1413
1453
  structure.answers = qaAnswers[j].answers;
1414
1454
  structure.userAnswer = mcmi;
1415
1455
  structure.linkType = qaAnswers[j].linkType;
@@ -1436,71 +1476,76 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1436
1476
  newArray.push( structure );
1437
1477
  } else {
1438
1478
  let des = [];
1439
- if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
1440
- let validationAnswer = '';
1441
- if ( requestSection[i].answer.split( '?' ).length > 1 ) {
1442
- validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
1443
- }
1444
- if ( validationAnswer.length ) {
1445
- let splitImgUrl = validationAnswer.split( '/' );
1446
- if ( splitImgUrl.length > 1 ) {
1447
- splitImgUrl.splice( 0, 3 );
1448
- requestSection[i].answer = splitImgUrl.join( '/' );
1479
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1480
+ if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
1481
+ let validationAnswer = '';
1482
+ if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
1483
+ validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
1449
1484
  }
1450
- }
1451
- let ansstructure = {
1452
- answer: requestSection[i].answer,
1453
- answeroptionNumber: 1,
1454
- sopFlag: false,
1455
- validation: false,
1456
- validationType: '',
1457
- validationAnswer: '',
1458
- referenceImage: qaAnswers[j].answers[0].referenceImage || '',
1459
- multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
1460
- showLinked: qaAnswers[j].answers[0].showLinked,
1461
- linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
1462
- runAI: qaAnswers[j].answers[0]?.runAI || false,
1463
- runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
1464
- runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
1465
- };
1466
- if ( qaAnswers[j].answerType == 'date' ) {
1467
- ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
1468
- if ( qaAnswers[j].compliance ) {
1485
+ if ( validationAnswer.length ) {
1486
+ let splitImgUrl = validationAnswer.split( '/' );
1487
+ if ( splitImgUrl.length > 1 ) {
1488
+ splitImgUrl.splice( 0, 3 );
1489
+ requestSection[i].answer = splitImgUrl.join( '/' );
1490
+ }
1491
+ }
1492
+ let ansstructure = {
1493
+ answer: requestSection[i].answer,
1494
+ answeroptionNumber: 1,
1495
+ sopFlag: false,
1496
+ validation: false,
1497
+ validationType: '',
1498
+ validationAnswer: '',
1499
+ referenceImage: qaAnswers[j].answers[0].referenceImage || '',
1500
+ multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
1501
+ showLinked: qaAnswers[j].answers[0].showLinked,
1502
+ linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
1503
+ runAI: qaAnswers[j].answers[0]?.runAI || false,
1504
+ runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
1505
+ runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
1506
+ };
1507
+ if ( qaAnswers[j].answerType == 'date' ) {
1508
+ ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
1469
1509
  if ( qaAnswers[j].compliance ) {
1470
- let ansArray = requestSection[i].answer.split( ',' );
1471
- if ( ansArray.includes( '-' ) ) {
1472
- ansArray = requestSection[i].answer.split( '-' );
1510
+ if ( qaAnswers[j].compliance ) {
1511
+ let ansArray = requestSection[i].answer.split( ',' );
1512
+ if ( ansArray.includes( '-' ) ) {
1513
+ ansArray = requestSection[i].answer.split( '-' );
1514
+ }
1515
+ 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 ) ) {
1516
+ ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1517
+ } 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 ) ) {
1518
+ ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1519
+ } 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 ) {
1520
+ ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1521
+ } else {
1522
+ ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
1523
+ }
1473
1524
  }
1474
- 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 ) ) {
1475
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1476
- } 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 ) ) {
1477
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1478
- } 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 ) {
1525
+ }
1526
+ }
1527
+ if ( qaAnswers[j].answerType == 'linearscale' ) {
1528
+ if ( qaAnswers[j].compliance ) {
1529
+ let linearAnswer = requestSection[i].answer.split( 'to' );
1530
+ if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
1479
1531
  ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1480
1532
  } else {
1481
1533
  ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
1482
1534
  }
1483
1535
  }
1536
+ ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
1537
+ ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1538
+ ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1484
1539
  }
1485
- }
1486
- if ( qaAnswers[j].answerType == 'linearscale' ) {
1487
- if ( qaAnswers[j].compliance ) {
1488
- let linearAnswer = requestSection[i].answer.split( 'to' );
1489
- if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
1490
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
1491
- } else {
1492
- ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
1493
- }
1540
+ if ( qaAnswers[j].answerType == 'image' ) {
1541
+ ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1542
+ ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1494
1543
  }
1495
- ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
1496
- ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1497
- ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1498
- }
1499
- if ( qaAnswers[j].answerType == 'image' ) {
1500
- ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
1501
- ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
1544
+ if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
1545
+ ansstructure.runAIData = requestSection[i].runAIData;
1546
+ }
1547
+ des.push( ansstructure );
1502
1548
  }
1503
- des.push( ansstructure );
1504
1549
  }
1505
1550
  let structure = {};
1506
1551
  structure.qno = qaAnswers[j].qno;
@@ -1511,7 +1556,9 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1511
1556
  structure.runAI = qaAnswers[j].runAI;
1512
1557
  structure.runAIDescription = qaAnswers[j].runAIDescription;
1513
1558
  structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
1514
- structure.remarks = requestSection[i].remarks;
1559
+ if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
1560
+ structure.remarks = requestSection[i].remarks;
1561
+ }
1515
1562
  structure.answers = qaAnswers[j].answers;
1516
1563
  structure.userAnswer = des;
1517
1564
  structure.linkType = qaAnswers[j].linkType;
@@ -1552,6 +1599,18 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1552
1599
 
1553
1600
  requestData.questionAnswers = sectionFormat;
1554
1601
  logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
1602
+
1603
+ if ( requestData.submittype == 'submit' ) {
1604
+ for ( let section of sectionFormat ) {
1605
+ for ( let question of section.questions ) {
1606
+ let mustValidate = !question.linkType || ( question.linkType && question.linkquestionenabled );
1607
+ if ( mustValidate && ( !question.userAnswer || !question.userAnswer.length ) ) {
1608
+ return res.sendError( 'Please Fill All Fields', 400 );
1609
+ }
1610
+ }
1611
+ }
1612
+ }
1613
+
1555
1614
  next();
1556
1615
  } catch ( error ) {
1557
1616
  logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
@@ -1932,7 +1991,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
1932
1991
  let des = [];
1933
1992
  if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
1934
1993
  let validationAnswer = '';
1935
- if ( requestSection[i].answer.split( '?' ).length > 1 ) {
1994
+ if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
1936
1995
  validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
1937
1996
  }
1938
1997
  if ( validationAnswer.length ) {
@@ -2031,7 +2090,13 @@ function QuestionFlag( req, res ) {
2031
2090
 
2032
2091
  async function updateRecurringFlagTracker( processedChecklist, questionAnswers, currentDateTime ) {
2033
2092
  try {
2034
- if ( !processedChecklist?.store_id || !processedChecklist?.sourceCheckList_id ) return;
2093
+ if ( !processedChecklist?.sourceCheckList_id ) return;
2094
+
2095
+ const isUserBased = processedChecklist?.coverage === 'user';
2096
+ const storeId = isUserBased ? '' : ( processedChecklist?.store_id || '' );
2097
+ const userId = isUserBased ? ( processedChecklist?.userId ? String( processedChecklist.userId ) : ( processedChecklist?.userEmail || '' ) ) : '';
2098
+ if ( !isUserBased && !storeId ) return;
2099
+ if ( isUserBased && !userId ) return;
2035
2100
 
2036
2101
  const today = currentDateTime ? currentDateTime.format( 'YYYY-MM-DD' ) : dayjs().format( 'YYYY-MM-DD' );
2037
2102
  const yesterday = dayjs( today, 'YYYY-MM-DD' ).subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
@@ -2039,7 +2104,7 @@ async function updateRecurringFlagTracker( processedChecklist, questionAnswers,
2039
2104
  const trackerKeyBase = {
2040
2105
  client_id: processedChecklist.client_id,
2041
2106
  sourceCheckList_id: processedChecklist.sourceCheckList_id,
2042
- store_id: processedChecklist.store_id,
2107
+ ...( isUserBased ) ? { user_id: userId } : { store_id: storeId },
2043
2108
  };
2044
2109
 
2045
2110
  const existingRows = await recurringFlagTracker.find( trackerKeyBase, { section_id: 1, qno: 1, consecutiveCount: 1, lastFlaggedDate: 1 } );
@@ -2059,7 +2124,7 @@ async function updateRecurringFlagTracker( processedChecklist, questionAnswers,
2059
2124
  const flaggedNow = Array.isArray( question?.userAnswer ) && question.userAnswer.some( ( a ) => a?.sopFlag === true );
2060
2125
  const key = `${sectionId}::${qno}`;
2061
2126
  const existing = existingMap.get( key );
2062
-
2127
+ console.log( flaggedNow, 'test' );
2063
2128
  if ( flaggedNow ) {
2064
2129
  let newCount;
2065
2130
  if ( !existing ) {
@@ -2079,8 +2144,11 @@ async function updateRecurringFlagTracker( processedChecklist, questionAnswers,
2079
2144
  filter: { ...trackerKeyBase, section_id: sectionId, qno },
2080
2145
  update: {
2081
2146
  $set: {
2147
+ coverage: isUserBased ? 'user' : 'store',
2082
2148
  checkListName: processedChecklist.checkListName,
2083
- storeName: processedChecklist.storeName,
2149
+ storeName: isUserBased ? '' : ( processedChecklist.storeName || '' ),
2150
+ userName: processedChecklist.userName || '',
2151
+ userEmail: processedChecklist.userEmail || '',
2084
2152
  sectionName: section?.sectionName || '',
2085
2153
  qname: question?.qname || '',
2086
2154
  consecutiveCount: newCount,
@@ -2103,9 +2171,13 @@ async function updateRecurringFlagTracker( processedChecklist, questionAnswers,
2103
2171
  }
2104
2172
  } );
2105
2173
  } );
2106
-
2107
2174
  if ( ops.length ) {
2108
- await recurringFlagTracker.bulkWrite( ops );
2175
+ try {
2176
+ let data = await recurringFlagTracker.bulkWrite( ops, { ordered: false } );
2177
+ console.log( 'recurringFlagTracker bulkWrite result', data );
2178
+ } catch ( bulkErr ) {
2179
+ logger.error( { function: 'updateRecurringFlagTracker.bulkWrite', code: bulkErr?.code, message: bulkErr?.message, writeErrors: bulkErr?.writeErrors } );
2180
+ }
2109
2181
  }
2110
2182
  } catch ( error ) {
2111
2183
  logger.error( { function: 'updateRecurringFlagTracker', error } );
@@ -2159,6 +2231,9 @@ export async function submitChecklist( req, res ) {
2159
2231
  let flagCount = QuestionFlag( req, res );
2160
2232
  updateData.questionFlag = flagCount;
2161
2233
  updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
2234
+ if ( getchecklist?.[0]?.redoEdit != undefined ) {
2235
+ updateData.redoEdit = false;
2236
+ }
2162
2237
  if ( requestData.deviceDetails && requestData.deviceDetails != '' ) {
2163
2238
  updateData.deviceDetails =JSON.parse( requestData.deviceDetails );
2164
2239
  }
@@ -2247,7 +2322,10 @@ export async function submitChecklist( req, res ) {
2247
2322
  // };
2248
2323
  // await detectionService.create( detectionData );
2249
2324
  if ( requestData.submittype == 'submit' ) {
2250
- updateRecurringFlagTracker( getchecklist[0], requestData.questionAnswers, currentDateTime );
2325
+ console.log( checklistDetails?.recurringFlag?.notifyType?.length );
2326
+ if ( checklistDetails?.recurringFlag?.notifyType?.length ) {
2327
+ updateRecurringFlagTracker( getchecklist[0], requestData.questionAnswers, currentDateTime );
2328
+ }
2251
2329
  updateOpenSearch( req.user, requestData );
2252
2330
  let openSearch = JSON.parse( process.env.OPENSEARCH );
2253
2331
  // console.log( 'openSearch', openSearch );
@@ -2428,7 +2506,8 @@ export async function submitTask( req, res ) {
2428
2506
  'storeResponseTime': currentDateTime.format( 'HH:mm:ss - MMM DD, YYYY' ),
2429
2507
  'message_mode': 'retriggered',
2430
2508
  };
2431
- sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
2509
+ let sqsResponse = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).storeHygiene}`, JSON.stringify( sqsData ) );
2510
+ console.log( sqsResponse );
2432
2511
  }
2433
2512
  if ( !excludedChecklists.includes( checklist.checkListName ) ) {
2434
2513
  const query1 = [
@@ -2933,6 +3012,9 @@ export async function dashboardv1( req, res ) {
2933
3012
  // const { store_id, date } = req.query;
2934
3013
  const { date } = req.query;
2935
3014
  const userId = req.user._id;
3015
+ let fromDate = new Date( req.query.date );
3016
+ let toDate = new Date( req.query.date );
3017
+ toDate.setDate( toDate.getDate() + 1 );
2936
3018
 
2937
3019
  // //Get User Based Checklist //
2938
3020
  const clientId = { client_id: req.user.clientId };
@@ -2949,7 +3031,7 @@ export async function dashboardv1( req, res ) {
2949
3031
  ...storeMatch,
2950
3032
  };
2951
3033
  const buildPipeline = ( matchExtraConditions = {} ) => [
2952
- { $match: { ...baseMatch, ...matchExtraConditions } },
3034
+ { $match: { $or: [ { ...baseMatch, ...matchExtraConditions }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } }, { userId }, { ...storeMatch } ] } ] } },
2953
3035
  {
2954
3036
  $facet: {
2955
3037
  total: [ { $count: 'total' } ],
@@ -2969,9 +3051,7 @@ export async function dashboardv1( req, res ) {
2969
3051
  },
2970
3052
  ];
2971
3053
 
2972
- let fromDate = new Date( req.query.date );
2973
- let toDate = new Date( req.query.date );
2974
- toDate.setDate( toDate.getDate() + 1 );
3054
+
2975
3055
  const taskBaseMatch = {
2976
3056
  // eslint-disable-next-line camelcase
2977
3057
  // store_id,
@@ -3020,6 +3100,8 @@ export async function dashboardv1( req, res ) {
3020
3100
  processedTask.aggregate( taskQuery ),
3021
3101
  ] );
3022
3102
 
3103
+ console.log( checklistResult );
3104
+
3023
3105
  const checklistResultData =
3024
3106
  checklistResult.status === 'fulfilled' ?
3025
3107
  processResult( checklistResult.value ) :
@@ -3149,6 +3231,9 @@ export async function checklistv1( req, res ) {
3149
3231
  // const { store_id, date, checklistStatus, searchValue } = req.query;
3150
3232
  const { date, checklistStatus, searchValue } = req.query;
3151
3233
  const userId = req.user._id;
3234
+ let fromDate = new Date( req.query.date );
3235
+ let toDate = new Date( req.query.date );
3236
+ toDate.setDate( toDate.getDate() + 1 );
3152
3237
 
3153
3238
  // Get User Based Checklist //
3154
3239
  const clientId = { client_id: req.user.clientId };
@@ -3160,16 +3245,18 @@ export async function checklistv1( req, res ) {
3160
3245
  // eslint-disable-next-line camelcase
3161
3246
  // { store_id },
3162
3247
  { userId },
3163
- { date_string: date },
3248
+ { $or: [ { date_string: date }, { $and: [ { redoStatus: true }, { scheduleStartTime_iso: { $lt: toDate } }, { scheduleEndTime_iso: { $gte: fromDate } } ] } ] },
3164
3249
  { timeFlagStatus: true },
3165
3250
  ...matchExtraConditions,
3166
3251
  clientId,
3167
3252
  storeMatch,
3168
3253
  ];
3254
+
3169
3255
  if ( checklistStatus ) {
3170
3256
  matchConditions.push( { checklistStatus } );
3171
3257
  }
3172
3258
 
3259
+
3173
3260
  const pipeline = [
3174
3261
  { $match: { $and: matchConditions } },
3175
3262
  ...( searchValue ?
@@ -3222,9 +3309,7 @@ export async function checklistv1( req, res ) {
3222
3309
  return pipeline;
3223
3310
  };
3224
3311
 
3225
- let fromDate = new Date( req.query.date );
3226
- let toDate = new Date( req.query.date );
3227
- toDate.setDate( toDate.getDate() + 1 );
3312
+
3228
3313
  const taskBuildPipeline = ( matchExtraConditions = [], projectExtraConditions = {} ) => {
3229
3314
  const matchConditions = [
3230
3315
  // eslint-disable-next-line camelcase
@@ -3604,7 +3689,7 @@ export async function questionList( req, res ) {
3604
3689
  checkvalidation = answer.validationAnswer;
3605
3690
  }
3606
3691
  }
3607
- Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
3692
+ Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation, ...( answer.redo && { redo: answer.redo } ) } );
3608
3693
  getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
3609
3694
  }
3610
3695