tango-app-api-trax 3.2.0-beta.9 → 3.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.2.0-beta.9",
3
+ "version": "3.2.1",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -349,18 +349,39 @@ export async function redoChecklist( req, res ) {
349
349
  let question = checklistDetails.questionAnswers;
350
350
 
351
351
 
352
- let sectionIndex = question.findIndex( ( sec ) => sec.section_id == req.body.payload.section_id );
352
+ let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
353
353
  if ( sectionIndex == -1 ) {
354
354
  return res.sendError( 'section is not found', 400 );
355
355
  }
356
356
 
357
- let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
357
+ let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
358
+
359
+ let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
360
+ // if ( checklistDetails.client_id == '458' ) {
361
+ data.answers.forEach( ( item ) => {
362
+ if ( item.showLinked ) {
363
+ item.nestedQuestion.forEach( ( ele ) => {
364
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
365
+ let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
366
+ question[sectionIndex].questions[eleIndex] = element;
367
+ question[sectionIndex].questions[eleIndex].userAnswer = [];
368
+ question[sectionIndex].questions[eleIndex].remarks = '';
369
+ } );
370
+ }
371
+ } );
372
+ // data.answers.forEach( ( item ) => {
373
+ // if ( item.showLinked ) {
374
+ // item.nestedQuestion = [];
375
+ // item.showLinked = false;
376
+ // item.linkedQuestion = 0;
377
+ // }
378
+ // } );
379
+ // }
358
380
  let userAnswer = data.userAnswer;
359
381
 
360
-
361
- question[sectionIndex].questions[req.body.payload.qno - 1] = data;
362
- question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
363
- question[sectionIndex].questions[req.body.payload.qno - 1].remarks = '';
382
+ question[sectionIndex].questions[findQuestion] = data;
383
+ question[sectionIndex].questions[findQuestion].userAnswer = [];
384
+ question[sectionIndex].questions[findQuestion].remarks = '';
364
385
  checklistDetails.questionAnswers = question;
365
386
  let updateData = {
366
387
  checklistStatus: 'open',
@@ -384,7 +405,7 @@ export async function redoChecklist( req, res ) {
384
405
  checklistDescription: req.body.payload.checklistDescription,
385
406
  sectionId: req.body.payload.section_id,
386
407
  sectionName: question[sectionIndex].sectionName,
387
- questionName: question[sectionIndex].questions[req.body.payload.qno - 1].qname,
408
+ questionName: question[sectionIndex].questions[findQuestion].qname,
388
409
  action: 'redo',
389
410
  store_id: checklistDetails.store_id,
390
411
  storeName: checklistDetails.storeName,
@@ -394,7 +415,7 @@ export async function redoChecklist( req, res ) {
394
415
  userAnswer: userAnswer,
395
416
  initiatedBy: req.user.userName,
396
417
  initiatedTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
397
- answerType: question[sectionIndex].questions[req.body.payload.qno - 1].answerType,
418
+ answerType: question[sectionIndex].questions[findQuestion].answerType,
398
419
  submitedBy: checklistDetails.userName,
399
420
  submitTime: checklistDetails.submitTime,
400
421
  };
@@ -433,7 +454,7 @@ export async function getLogs( req, res ) {
433
454
  let result = await checklistLogs.find( {
434
455
  checklistId: new mongoose.Types.ObjectId( req.body.checklistId ),
435
456
  processedChecklistId: new mongoose.Types.ObjectId( req.body.processedChecklistId ),
436
- sectionId: new mongoose.Types.ObjectId( req.body.section_id ),
457
+ sectionName: req.body.sectionName,
437
458
  questionName: req.body.qname,
438
459
  action: 'redo',
439
460
  } );
@@ -881,7 +881,8 @@ export async function pushNotification( req, res ) {
881
881
  let query = [ {
882
882
  $match: {
883
883
  date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
884
- $expr: { $gt: [ { $size: '$remainder' }, 0 ] },
884
+ // $expr: { $gt: [ { $size: '$remainder' }, 0 ] },
885
+ $expr: { $gt: [ { $size: { $ifNull: [ '$remainder', [] ] } }, 0 ] },
885
886
  checklistStatus: { $ne: 'submit' },
886
887
  checkListType: { $in: [ 'custom' ] },
887
888
  timeFlag: 0,
@@ -180,7 +180,14 @@ export async function startChecklist( req, res ) {
180
180
  startTime: { $ifNull: [ '$startTime', '' ] },
181
181
  submitTime: { $ifNull: [ '$submitTime', '' ] },
182
182
  allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
183
- allowedStoreLocation: { $ifNull: [ '$checallowedStoreLocationkListName', false ] },
183
+ // allowedStoreLocation: { $ifNull: [ '$checallowedStoreLocationkListName', false ] },
184
+ allowedStoreLocation: {
185
+ $cond: {
186
+ if: { $eq: [ '$client_id', '11' ] },
187
+ then: false,
188
+ else: { $ifNull: [ '$allowedStoreLocation', false ] },
189
+ },
190
+ },
184
191
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
185
192
  redoStatus: { $ifNull: [ '$redoStatus', '' ] },
186
193
  },
@@ -344,7 +351,14 @@ export async function startTask( req, res ) {
344
351
  startTime: { $ifNull: [ '$startTime', '' ] },
345
352
  submitTime: { $ifNull: [ '$submitTime', '' ] },
346
353
  allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
347
- allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', false ] },
354
+ // allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', false ] },
355
+ allowedStoreLocation: {
356
+ $cond: {
357
+ if: { $eq: [ '$client_id', '11' ] },
358
+ then: false,
359
+ else: { $ifNull: [ '$allowedStoreLocation', false ] },
360
+ },
361
+ },
348
362
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
349
363
  redoStatus: { $ifNull: [ '$redoStatus', '' ] },
350
364
  },
@@ -675,6 +689,10 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
675
689
  structure.parentanswer = requestSection[i].parentanswer;
676
690
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
677
691
  structure.descriptivetype = qaAnswers[j].descriptivetype;
692
+ if ( qaAnswers[j]?.taskId ) {
693
+ structure.taskId = qaAnswers[j]?.taskId;
694
+ structure.task = true;
695
+ }
678
696
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
679
697
  structure.redo = false;
680
698
  } else if ( requestData.submittype === 'draft' ) {
@@ -701,7 +719,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
701
719
  }
702
720
  }
703
721
  } else {
704
- qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
722
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
705
723
  qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
706
724
  }
707
725
  ms.push( qaans[k] );
@@ -722,6 +740,10 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
722
740
  structure.parentanswer = requestSection[i].parentanswer;
723
741
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
724
742
  structure.descriptivetype = qaAnswers[j].descriptivetype;
743
+ if ( qaAnswers[j]?.taskId ) {
744
+ structure.taskId = qaAnswers[j]?.taskId;
745
+ structure.task = true;
746
+ }
725
747
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
726
748
  structure.redo = false;
727
749
  } else if ( requestData.submittype === 'draft' ) {
@@ -750,7 +772,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
750
772
  }
751
773
  }
752
774
  } else {
753
- qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
775
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
754
776
  qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
755
777
  }
756
778
 
@@ -773,6 +795,10 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
773
795
  structure.parentanswer = requestSection[i].parentanswer;
774
796
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
775
797
  structure.descriptivetype = qaAnswers[j].descriptivetype;
798
+ if ( qaAnswers[j]?.taskId ) {
799
+ structure.taskId = qaAnswers[j]?.taskId;
800
+ structure.task = true;
801
+ }
776
802
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
777
803
  structure.redo = false;
778
804
  } else if ( requestData.submittype === 'draft' ) {
@@ -829,6 +855,10 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
829
855
  structure.parentanswer = requestSection[i].parentanswer;
830
856
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
831
857
  structure.descriptivetype = qaAnswers[j].descriptivetype;
858
+ if ( qaAnswers[j]?.taskId ) {
859
+ structure.taskId = qaAnswers[j]?.taskId;
860
+ structure.task = true;
861
+ }
832
862
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
833
863
  structure.redo = false;
834
864
  } else if ( requestData.submittype === 'draft' ) {
@@ -883,6 +913,10 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
883
913
  structure.parentanswer = requestSection[i].parentanswer;
884
914
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
885
915
  structure.descriptivetype = qaAnswers[j].descriptivetype;
916
+ if ( qaAnswers[j]?.taskId ) {
917
+ structure.taskId = qaAnswers[j]?.taskId;
918
+ structure.task = true;
919
+ }
886
920
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
887
921
  structure.redo = false;
888
922
  } else if ( requestData.submittype === 'draft' ) {
@@ -1019,7 +1053,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1019
1053
  }
1020
1054
  }
1021
1055
  } else {
1022
- qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1056
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1023
1057
  qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1024
1058
  }
1025
1059
  yn.push( qaans[k] );
@@ -1040,6 +1074,10 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1040
1074
  structure.parentanswer = requestSection[i].parentanswer;
1041
1075
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1042
1076
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1077
+ if ( qaAnswers[j]?.taskId ) {
1078
+ structure.taskId = qaAnswers[j]?.taskId;
1079
+ structure.task = true;
1080
+ }
1043
1081
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1044
1082
  structure.redo = false;
1045
1083
  } else if ( requestData.submittype === 'draft' ) {
@@ -1066,7 +1104,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1066
1104
  }
1067
1105
  }
1068
1106
  } else {
1069
- qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1107
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1070
1108
  qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
1071
1109
  }
1072
1110
  ms.push( qaans[k] );
@@ -1087,6 +1125,10 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1087
1125
  structure.parentanswer = requestSection[i].parentanswer;
1088
1126
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1089
1127
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1128
+ if ( qaAnswers[j]?.taskId ) {
1129
+ structure.taskId = qaAnswers[j]?.taskId;
1130
+ structure.task = true;
1131
+ }
1090
1132
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1091
1133
  structure.redo = false;
1092
1134
  } else if ( requestData.submittype === 'draft' ) {
@@ -1115,7 +1157,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1115
1157
  }
1116
1158
  }
1117
1159
  } else {
1118
- qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1160
+ // qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
1119
1161
  qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
1120
1162
  }
1121
1163
 
@@ -1138,6 +1180,10 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1138
1180
  structure.parentanswer = requestSection[i].parentanswer;
1139
1181
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1140
1182
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1183
+ if ( qaAnswers[j]?.taskId ) {
1184
+ structure.taskId = qaAnswers[j]?.taskId;
1185
+ structure.task = true;
1186
+ }
1141
1187
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1142
1188
  structure.redo = false;
1143
1189
  } else if ( requestData.submittype === 'draft' ) {
@@ -1194,6 +1240,10 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1194
1240
  structure.parentanswer = requestSection[i].parentanswer;
1195
1241
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1196
1242
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1243
+ if ( qaAnswers[j]?.taskId ) {
1244
+ structure.taskId = qaAnswers[j]?.taskId;
1245
+ structure.task = true;
1246
+ }
1197
1247
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1198
1248
  structure.redo = false;
1199
1249
  } else if ( requestData.submittype === 'draft' ) {
@@ -1248,6 +1298,10 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1248
1298
  structure.parentanswer = requestSection[i].parentanswer;
1249
1299
  structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
1250
1300
  structure.descriptivetype = qaAnswers[j].descriptivetype;
1301
+ if ( qaAnswers[j]?.taskId ) {
1302
+ structure.taskId = qaAnswers[j]?.taskId;
1303
+ structure.task = true;
1304
+ }
1251
1305
  if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
1252
1306
  structure.redo = false;
1253
1307
  } else if ( requestData.submittype === 'draft' ) {
@@ -2228,7 +2282,14 @@ export async function checklist( req, res ) {
2228
2282
  startTime: { $ifNull: [ '$startTime', '' ] },
2229
2283
  submitTime: { $ifNull: [ '$submitTime', '' ] },
2230
2284
  allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
2231
- allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2285
+ // allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2286
+ allowedStoreLocation: {
2287
+ $cond: {
2288
+ if: { $eq: [ '$client_id', '11' ] },
2289
+ then: false,
2290
+ else: { $ifNull: [ '$allowedStoreLocation', false ] },
2291
+ },
2292
+ },
2232
2293
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
2233
2294
  startTime_string: { $ifNull: [ '$startTime_string', '' ] },
2234
2295
  submitTime_string: { $ifNull: [ '$submitTime_string', '' ] },
@@ -2292,7 +2353,14 @@ export async function checklistv1( req, res ) {
2292
2353
  startTime: { $ifNull: [ '$startTime', '' ] },
2293
2354
  submitTime: { $ifNull: [ '$submitTime', '' ] },
2294
2355
  allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
2295
- allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2356
+ // allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2357
+ allowedStoreLocation: {
2358
+ $cond: {
2359
+ if: { $eq: [ '$client_id', '11' ] },
2360
+ then: false,
2361
+ else: { $ifNull: [ '$allowedStoreLocation', false ] },
2362
+ },
2363
+ },
2296
2364
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
2297
2365
  startTime_string: { $ifNull: [ '$startTime_string', '' ] },
2298
2366
  submitTime_string: { $ifNull: [ '$submitTime_string', '' ] },
@@ -2375,7 +2443,14 @@ export async function questionList( req, res ) {
2375
2443
  startTime: { $ifNull: [ '$startTime', '' ] },
2376
2444
  submitTime: { $ifNull: [ '$submitTime', '' ] },
2377
2445
  allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
2378
- allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2446
+ // allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2447
+ allowedStoreLocation: {
2448
+ $cond: {
2449
+ if: { $eq: [ '$client_id', '11' ] },
2450
+ then: false,
2451
+ else: { $ifNull: [ '$allowedStoreLocation', false ] },
2452
+ },
2453
+ },
2379
2454
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
2380
2455
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
2381
2456
  getchecklist: { $ifNull: [ '$getchecklist', '' ] },
@@ -2673,7 +2748,14 @@ export async function taskQuestionList( req, res ) {
2673
2748
  startTime: { $ifNull: [ '$startTime', '' ] },
2674
2749
  submitTime: { $ifNull: [ '$submitTime', '' ] },
2675
2750
  allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
2676
- allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2751
+ // allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
2752
+ allowedStoreLocation: {
2753
+ $cond: {
2754
+ if: { $eq: [ '$client_id', '11' ] },
2755
+ then: false,
2756
+ else: { $ifNull: [ '$allowedStoreLocation', false ] },
2757
+ },
2758
+ },
2677
2759
  reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
2678
2760
  questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
2679
2761
  getchecklist: { $ifNull: [ '$getchecklist', '' ] },
@@ -2866,6 +2948,11 @@ export async function uploadAnswerImage( req, res ) {
2866
2948
  let date = dayjs().format( 'YYYY-MM-DD' );
2867
2949
  let folder;
2868
2950
 
2951
+ let getChecklistDetails = await processedchecklist.findOne( { _id: input.checklistId } );
2952
+ if ( getChecklistDetails ) {
2953
+ input.type = 'custom';
2954
+ }
2955
+
2869
2956
  if ( input.type == 'custom' ) {
2870
2957
  folder = 'checklist-answers';
2871
2958
  } else {
@@ -618,9 +618,9 @@ export const flagCardsV1 = async ( req, res ) => {
618
618
  { checkListType: 1 },
619
619
  );
620
620
 
621
- if ( !publishedAiChecklists?.length ) {
622
- return res.sendError( { error: 'No Data Found' }, 204 );
623
- }
621
+ // if ( !publishedAiChecklists?.length ) {
622
+ // return res.sendError( { error: 'No Data Found' }, 204 );
623
+ // }
624
624
 
625
625
  const detectionPayload = { fromDate, toDate, storeId, clientId };
626
626
  const lambdaURL = 'https://f65azvtljclaxp6l7rnx65cdmm0lcgvp.lambda-url.ap-south-1.on.aws/';
@@ -468,6 +468,78 @@ async function createUser( data ) {
468
468
  role: 'user',
469
469
  password: '5dqFKAJj29PsV6P+kL+3Dw==',
470
470
  isActive: true,
471
+ userType: 'client',
472
+ rolespermission: [
473
+ {
474
+ featureName: 'Global',
475
+ modules: [
476
+ {
477
+ name: 'Store',
478
+ isAdd: false,
479
+ isEdit: false,
480
+
481
+ },
482
+ {
483
+ name: 'User',
484
+ isAdd: false,
485
+ isEdit: false,
486
+
487
+ },
488
+ {
489
+ name: 'Camera',
490
+ isAdd: false,
491
+ isEdit: false,
492
+
493
+ },
494
+ {
495
+ name: 'Configuration',
496
+ isAdd: false,
497
+ isEdit: false,
498
+
499
+ },
500
+ {
501
+ name: 'Subscription',
502
+ isAdd: false,
503
+ isEdit: false,
504
+
505
+ },
506
+ {
507
+ name: 'Billing',
508
+ isAdd: false,
509
+ isEdit: false,
510
+
511
+ },
512
+ ],
513
+ },
514
+ {
515
+ featurName: 'TangoEye',
516
+ modules: [
517
+ {
518
+ name: 'ZoneTag',
519
+ isAdd: false,
520
+ isEdit: false,
521
+
522
+ },
523
+ ],
524
+ },
525
+ {
526
+ featurName: 'TangoTrax',
527
+ modules: [
528
+ {
529
+ name: 'checklist',
530
+ isAdd: false,
531
+ isEdit: false,
532
+
533
+ },
534
+ {
535
+ name: 'Task',
536
+ isAdd: false,
537
+ isEdit: false,
538
+
539
+ },
540
+ ],
541
+ },
542
+ ],
471
543
  };
472
544
  let response = await userService.create( params );
473
545
  return response._id;
@@ -937,7 +1009,7 @@ export const updateConfigure =async ( req, res ) => {
937
1009
  }
938
1010
 
939
1011
  let currentDate = dayjs.utc().format();
940
- let updatedscheduleEndTimeISO = dayjs.utc( inputBody?.checkListDetails?.scheduleStartTime, 'hh:mm A' ).format( 'HH:mm:ss' );
1012
+ let updatedscheduleEndTimeISO = dayjs.utc( inputBody?.checkListDetails?.scheduleEndTime, 'hh:mm A' ).format( 'HH:mm:ss' );
941
1013
  let newUpdatedDate = dayjs.utc( updatedscheduleEndTimeISO, 'HH:mm:ss' ).format();
942
1014
 
943
1015
  if ( inputBody.submitType == 'publish' && inputBody?.showEdit && typeof inputBody?.editSubmit == 'undefined' && newUpdatedDate > currentDate ) {
@@ -1471,9 +1543,9 @@ export const validateUser = async ( req, res ) => {
1471
1543
  if ( !storeExists.length ) {
1472
1544
  storeId.push( { store: item.storeName, message: '' } );
1473
1545
  }
1474
- if ( storeExists.length && !storeExists[0]?.storeProfile?.city && !item.city ) {
1475
- storeId.push( { store: item.storeName, message: 'city is required' } );
1476
- }
1546
+ // if ( storeExists.length && !storeExists[0]?.storeProfile?.city && !item.city ) {
1547
+ // storeId.push( { store: item.storeName, message: 'city is required' } );
1548
+ // }
1477
1549
  if ( storeExists.length && storeExists[0].status != 'active' ) {
1478
1550
  storeId.push( { store: item.storeName, message: 'store is inactive' } );
1479
1551
  }
@@ -1970,7 +2042,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
1970
2042
  tokenList.push( getToken.fcmToken );
1971
2043
  }
1972
2044
  if ( !element4?.sendNotification ) {
1973
- notifyUserList.push( { token: getToken.fcmToken, storeName: element4.storeName, id: element4._id } );
2045
+ notifyUserList.push( { token: getToken?.fcmToken, storeName: element4.storeName, id: element4._id } );
1974
2046
  }
1975
2047
  if ( !getCLconfig?.allowedMultiSubmit ) {
1976
2048
  let query;
@@ -2103,6 +2175,17 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2103
2175
  getsubmitDetails[0].checklistStatus = 'inprogress';
2104
2176
  getsubmitDetails[0].date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
2105
2177
  getsubmitDetails[0].date_iso = new Date( date );
2178
+ getsubmitDetails[0].redoStatus = false;
2179
+ getsubmitDetails[0].approvalStatus = false;
2180
+ } else {
2181
+ if ( editSubmit && getsubmitDetails[0].checklistStatus == 'submit' ) {
2182
+ console.log( editSubmit );
2183
+ let user = {
2184
+ _id: getsubmitDetails[0].userId,
2185
+ clientId: getsubmitDetails[0].client_id,
2186
+ };
2187
+ updateOpenSearch( user, { processedcheckListId: getsubmitDetails[0]._id, date: getsubmitDetails[0].date_string } );
2188
+ }
2106
2189
  }
2107
2190
  let data = { ...getsubmitDetails[0]._doc };
2108
2191
  await processedchecklist.updateOne( { _id: getsubmitDetails[0]._id }, data );
@@ -2146,11 +2229,23 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2146
2229
  allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
2147
2230
  }
2148
2231
  if ( allQuestion ) {
2149
- if ( getCLconfig?.allowedMultiSubmit && processId ) {
2150
- let processedDetails = await processedchecklist.findOne( { _id: processId } );
2151
- if ( processedDetails ) {
2152
- let submitUser = allQuestion.find( ( item ) => item.userId.toString() == processedDetails.userId.toString() && item.store_id == processedDetails.store_id );
2153
- await processedchecklist.insertMany( submitUser );
2232
+ if ( getCLconfig?.allowedMultiSubmit || processId ) {
2233
+ if ( processId ) {
2234
+ let processedDetails = await processedchecklist.findOne( { _id: processId } );
2235
+ if ( processedDetails ) {
2236
+ let submitUser = allQuestion.find( ( item ) => item.userId.toString() == processedDetails.userId.toString() && item.store_id == processedDetails.store_id );
2237
+ await processedchecklist.insertMany( submitUser );
2238
+ }
2239
+ } else {
2240
+ let deleteQuery = {
2241
+ date_string: insertdata.date_string,
2242
+ date_iso: insertdata.date_iso,
2243
+ client_id: insertdata.client_id,
2244
+ checkListId: updatedchecklist._id,
2245
+ checklistStatus: { $nin: [ 'submit' ] },
2246
+ };
2247
+ await processedchecklist.deleteMany( deleteQuery );
2248
+ await processedchecklist.insertMany( allQuestion );
2154
2249
  }
2155
2250
  } else {
2156
2251
  let unAssignedList = allQuestion.reduce( ( acc, item ) => {
@@ -2172,6 +2267,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2172
2267
  }
2173
2268
  }
2174
2269
 
2270
+
2175
2271
  Promise.all( allQuestion.map( async ( ele ) => {
2176
2272
  await processedchecklist.updateOne( { date_string: insertdata.date_string, date_iso: insertdata.date_iso, client_id: insertdata.client_id, checkListId: updatedchecklist._id, userEmail: ele.userEmail, store_id: ele.store_id }, ele );
2177
2273
  } ) );
@@ -2197,6 +2293,55 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2197
2293
  }
2198
2294
  }
2199
2295
 
2296
+ async function updateOpenSearch( user, data ) {
2297
+ let findQuery = [ {
2298
+ $match: {
2299
+ $and: [
2300
+ { _id: new ObjectId( data.processedcheckListId ) },
2301
+ { userId: user._id },
2302
+ { date_string: data.date },
2303
+ ],
2304
+ },
2305
+ } ];
2306
+
2307
+ let getchecklist = await processedchecklist.aggregate( findQuery );
2308
+ if ( getchecklist.length ) {
2309
+ let logInsertData = {
2310
+ store_id: getchecklist[0].store_id,
2311
+ storeName: getchecklist[0].storeName,
2312
+ action: 'Republish OpenSearch insert Triggered',
2313
+ checklistId: getchecklist[0].sourceCheckList_id,
2314
+ processedChecklistId: getchecklist[0]._id,
2315
+ checkListName: getchecklist[0].checkListName,
2316
+ type: getchecklist[0].checkListType,
2317
+ client_id: user.clientId,
2318
+ };
2319
+ await checklistLogs.create( logInsertData );
2320
+ const requestOptions = {
2321
+ method: 'POST',
2322
+ headers: {
2323
+ 'Content-Type': 'application/json',
2324
+ },
2325
+ body: JSON.stringify( { doc: { ...getchecklist[0] } } ),
2326
+ };
2327
+ let url = JSON.parse( process.env.LAMBDAURL );
2328
+ let searchResponse = await fetch( url.submitChecklist, requestOptions );
2329
+ if ( searchResponse.ok ) {
2330
+ let logInsertData = {
2331
+ store_id: getchecklist[0].store_id,
2332
+ storeName: getchecklist[0].storeName,
2333
+ action: 'Republish OpenSearch inserted Successfully',
2334
+ checklistId: getchecklist[0].sourceCheckList_id,
2335
+ processedChecklistId: getchecklist[0]._id,
2336
+ checkListName: getchecklist[0].checkListName,
2337
+ type: getchecklist[0].checkListType,
2338
+ client_id: user.clientId,
2339
+ };
2340
+ await checklistLogs.create( logInsertData );
2341
+ }
2342
+ }
2343
+ }
2344
+
2200
2345
  export const aiChecklist = async ( req, res ) => {
2201
2346
  try {
2202
2347
  let storeDetails = await storeService.count( { clientId: req.query.clientId, status: 'active' } );
@@ -3552,8 +3552,9 @@ export async function sendAlert( req, res ) {
3552
3552
  let query = {
3553
3553
  date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
3554
3554
  ...( inputBody?.sourceCheckList_id ) ? { sourceCheckList_id: new mongoose.Types.ObjectId( inputBody.sourceCheckList_id ) } : { _id: { $in: inputBody.id } },
3555
- timeFlag: 0,
3556
- ...( inputBody?.checklistStatus && inputBody?.checklistStatus != 'all' ) ? { checklistStatus: inputBody.status } : { checklistStatus: { $ne: 'submit' } },
3555
+ // timeFlag: 0,
3556
+ // ...( inputBody?.checklistStatus && inputBody?.checklistStatus != 'all' ) ? { checklistStatus: inputBody.status } : { checklistStatus: { $ne: 'submit' } },
3557
+ ...( inputBody?.checklistStatus && ( inputBody?.checklistStatus == 'all' || inputBody?.checklistStatus == 'redo' ) ) ? { checklistStatus: { $ne: 'submit' } } : { checklistStatus: inputBody.checklistStatus },
3557
3558
  };
3558
3559
 
3559
3560
  query = [ { $match: query } ];