tango-app-api-trax 3.4.1-beta-2 → 3.5.0-ai-2

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { logger } from 'tango-app-api-middleware';
3
+ import { logger, insertOpenSearchData } from 'tango-app-api-middleware';
4
4
  import * as storeService from '../services/store.service.js';
5
5
  import * as groupService from '../services/group.service.js';
6
6
  import * as clusterService from '../services/cluster.service.js';
@@ -14,6 +14,12 @@ import dayjs from 'dayjs';
14
14
  import { aggregateTeams, findteams } from '../services/teams.service.js';
15
15
  import { aggregate } from '../services/user.service.js';
16
16
  // import axios from 'axios';
17
+ import timeZone from 'dayjs/plugin/timezone.js';
18
+ import customParseFormat from 'dayjs/plugin/customParseFormat.js';
19
+
20
+ dayjs.extend( customParseFormat );
21
+ dayjs.extend( timeZone );
22
+
17
23
  async function LamdaServiceCall( url, data ) {
18
24
  try {
19
25
  const requestOptions = {
@@ -282,15 +288,24 @@ export async function approveChecklist( req, res ) {
282
288
  if ( req.body?.storeId?.length ) {
283
289
  query['store_id'] = { $in: req.body.storeId };
284
290
  }
285
- let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1 } );
291
+ let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1, checkListName: 1 } );
286
292
  if ( !checklistDetails.length ) {
287
293
  return res.sendError( 'No data found', 204 );
288
294
  }
289
295
  let idList = checklistDetails.filter( ( ele ) => ele.checklistStatus == 'submit' ).map( ( item ) => item._id );
290
296
  if ( idList.length ) {
291
- let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
297
+ let approvalUpdateData = {
298
+ approvalStatus: true,
299
+ approvalTime: new Date(),
300
+ // approvalTime_string: dayjs().format( 'hh:mm A, DD MMM YYYY' ),
301
+ approvalTime_string: dayjs().tz( 'Asia/Kolkata' ).format( 'hh:mm A, DD MMM YYYY' ),
302
+ approvalByName: req.user.userName,
303
+ approvalByEmail: req.user.email,
304
+ };
305
+ let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList }, approvalStatus: false }, approvalUpdateData );
292
306
  if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
293
307
  let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
308
+ let storeNames = inputstores.map( ( data ) => data.storeName );
294
309
 
295
310
 
296
311
  let params = {
@@ -303,6 +318,10 @@ export async function approveChecklist( req, res ) {
303
318
  },
304
319
  'upsert': {
305
320
  approvalStatus: true,
321
+ approvalTime: new Date(),
322
+ approvalTime_string: dayjs().tz( 'Asia/Kolkata' ).format( 'hh:mm A, DD MMM YYYY' ),
323
+ approvalByName: req.user.userName,
324
+ approvalByEmail: req.user.email,
306
325
  },
307
326
  };
308
327
 
@@ -315,8 +334,28 @@ export async function approveChecklist( req, res ) {
315
334
  };
316
335
  let url = JSON.parse( process.env.LAMBDAURL );
317
336
  let searchResponse = await fetch( url.approveChecklist, requestOptions );
318
-
319
- console.log( searchResponse.ok );
337
+ let logData= {
338
+ 'client_id': checklistDetails[0].client_id,
339
+ 'createAt': new Date(),
340
+ 'sourceCheckList_id': req.body.sourceCheckList_id,
341
+ 'checkListName': checklistDetails[0].checkListName,
342
+ 'fromCheckListName': '',
343
+ 'type': 'checklist',
344
+ 'action': 'approved',
345
+ 'storeName': '',
346
+ 'store_id': '',
347
+ 'createdByEmail': req.user.email,
348
+ 'createdBy': req.user._id,
349
+ 'coverage': checklistDetails[0].coverage,
350
+ 'logDetails': {
351
+ 'approved': storeNames,
352
+ },
353
+ 'userType': req.user.userType,
354
+ };
355
+ console.log( 'logData', logData );
356
+ let urlopensearch = JSON.parse( process.env.OPENSEARCH );
357
+ insertOpenSearchData( urlopensearch.traxActivityLog, logData );
358
+ // console.log( searchResponse.ok );
320
359
  if ( searchResponse.ok ) {
321
360
  let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
322
361
  if ( pendingstores && pendingstores.length > 0 ) {
@@ -332,6 +371,7 @@ export async function approveChecklist( req, res ) {
332
371
  return res.sendError( `${redoList.length} stores has not been approved since those stores are not submitted`, 400 );
333
372
  }
334
373
  } catch ( e ) {
374
+ // console.log( 'e', e );
335
375
  logger.error( { function: 'approveChecklist', error: e } );
336
376
  return res.sendError( e, 500 );
337
377
  }
@@ -350,7 +390,7 @@ export async function redoChecklist( req, res ) {
350
390
  }
351
391
 
352
392
 
353
- let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1 } );
393
+ let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1, coverage: 1, userEmail: 1 } );
354
394
  if ( !checklistDetails ) {
355
395
  return res.sendError( 'No data found', 204 );
356
396
  }
@@ -399,7 +439,7 @@ export async function redoChecklist( req, res ) {
399
439
  };
400
440
 
401
441
  let response = await processedChecklist.updateOne( { _id: req.body.payload._id }, updateData );
402
- console.log( response );
442
+ // console.log( response );
403
443
  if ( response.modifiedCount || response.matchedCount ) {
404
444
  let storeTimeZone = await storeService.findOne( { storeName: checklistDetails.storeName }, { 'storeProfile.timeZone': 1 } );
405
445
  let currentDateTime;
@@ -439,8 +479,28 @@ export async function redoChecklist( req, res ) {
439
479
  };
440
480
  let url = JSON.parse( process.env.LAMBDAURL );
441
481
  let searchResponse = await fetch( url.redoChecklist, requestOptions );
442
- console.log( searchResponse.ok );
443
-
482
+ // console.log( searchResponse.ok );
483
+ let logData= {
484
+ 'client_id': checklistDetails.client_id,
485
+ 'createAt': new Date(),
486
+ 'sourceCheckList_id': checklistDetails.sourceCheckList_id,
487
+ 'checkListName': checklistDetails.checkListName,
488
+ 'fromCheckListName': checklistDetails.checkListName,
489
+ 'type': 'checklist',
490
+ 'action': checklistDetails.redoStatus?'multiredo': 'redo',
491
+ 'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
492
+ 'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
493
+ 'userName': checklistDetails.userName,
494
+ 'userEmail': checklistDetails.userEmail,
495
+ 'createdByEmail': req.user.email,
496
+ 'createdBy': req.user.userName,
497
+ 'coverage': checklistDetails.coverage,
498
+ 'logDetails': {},
499
+ 'userType': req.user.userType,
500
+ };
501
+ let urlopensearch = JSON.parse( process.env.OPENSEARCH );
502
+ console.log( 'logData', logData );
503
+ insertOpenSearchData( urlopensearch.traxActivityLog, logData );
444
504
  if ( searchResponse.ok ) {
445
505
  return res.sendSuccess( 'Question redo successfully' );
446
506
  } else {
@@ -455,6 +515,150 @@ export async function redoChecklist( req, res ) {
455
515
  }
456
516
  }
457
517
 
518
+ export async function redomultiChecklist( req, res ) {
519
+ try {
520
+ let inputData = req.body.payload.coverage==='user'?req.body.payload.userEmail:req.body.payload.storeName;
521
+
522
+
523
+ for ( let originalData of inputData ) {
524
+ if ( !originalData.checklistId ) {
525
+ return res.sendError( 'Id is Required', 400 );
526
+ }
527
+ if ( !originalData.section_id ) {
528
+ return res.sendError( 'Section id is Required', 400 );
529
+ }
530
+ if ( !req.body.payload.qno ) {
531
+ return res.sendError( 'Question number is Required', 400 );
532
+ }
533
+
534
+
535
+ let checklistDetails = await processedChecklist.findOne( { _id: originalData.checklistId }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1 } );
536
+ if ( !checklistDetails ) {
537
+ return res.sendError( 'No data found', 204 );
538
+ }
539
+ let question = checklistDetails.questionAnswers;
540
+
541
+
542
+ let sectionIndex = question.findIndex( ( sec ) => sec.sectionName == req.body.payload.sectionName );
543
+ if ( sectionIndex == -1 ) {
544
+ return res.sendError( 'section is not found', 400 );
545
+ }
546
+
547
+ let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
548
+
549
+ let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
550
+ // if ( checklistDetails.client_id == '458' ) {
551
+ data.answers.forEach( ( item ) => {
552
+ if ( item.showLinked ) {
553
+ item.nestedQuestion.forEach( ( ele ) => {
554
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
555
+ let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
556
+ question[sectionIndex].questions[eleIndex] = element;
557
+ question[sectionIndex].questions[eleIndex].userAnswer = [];
558
+ question[sectionIndex].questions[eleIndex].remarks = '';
559
+ } );
560
+ }
561
+ } );
562
+ // data.answers.forEach( ( item ) => {
563
+ // if ( item.showLinked ) {
564
+ // item.nestedQuestion = [];
565
+ // item.showLinked = false;
566
+ // item.linkedQuestion = 0;
567
+ // }
568
+ // } );
569
+ // }
570
+ let userAnswer = data.userAnswer;
571
+
572
+ question[sectionIndex].questions[findQuestion] = data;
573
+ question[sectionIndex].questions[findQuestion].userAnswer = [];
574
+ question[sectionIndex].questions[findQuestion].remarks = '';
575
+ checklistDetails.questionAnswers = question;
576
+ let updateData = {
577
+ checklistStatus: 'open',
578
+ redoStatus: true,
579
+ reinitiateStatus: true,
580
+ questionAnswers: question,
581
+ };
582
+
583
+ let response = await processedChecklist.updateOne( { _id: originalData.checklistId }, updateData );
584
+ // console.log( response );
585
+ if ( response.modifiedCount || response.matchedCount ) {
586
+ let storeTimeZone = await storeService.findOne( { storeName: checklistDetails.storeName }, { 'storeProfile.timeZone': 1 } );
587
+ let currentDateTime;
588
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
589
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
590
+ } else {
591
+ currentDateTime = dayjs();
592
+ }
593
+ data = {
594
+ checklistId: checklistDetails.sourceCheckList_id,
595
+ checkListName: checklistDetails.checkListName,
596
+ checklistDescription: req.body.payload.checklistDescription,
597
+ sectionId: originalData.section_id,
598
+ sectionName: question[sectionIndex].sectionName,
599
+ questionName: question[sectionIndex].questions[findQuestion].qname,
600
+ action: 'redo',
601
+ store_id: checklistDetails?.store_id?checklistDetails?.store_id:'',
602
+ storeName: checklistDetails?.storeName?checklistDetails?.storeName:'',
603
+ client_id: checklistDetails.client_id,
604
+ processedChecklistId: checklistDetails._id,
605
+ type: checklistDetails.checkListType,
606
+ userAnswer: userAnswer,
607
+ initiatedBy: req.user.userName,
608
+ initiatedTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
609
+ answerType: question[sectionIndex].questions[findQuestion].answerType,
610
+ submitedBy: checklistDetails.userName,
611
+ submitTime: checklistDetails.submitTime,
612
+ };
613
+ await checklistLogs.create( data );
614
+
615
+
616
+ req.body.payload._id=originalData.checklistId;
617
+ req.body.payload.section_id=originalData.section_id;
618
+ req.body.payload.uniqueNo=originalData.uniqueNo;
619
+ // console.log( req.body );
620
+
621
+
622
+ const requestOptions = {
623
+ method: 'POST',
624
+ headers: {
625
+ 'Content-Type': 'application/json',
626
+ },
627
+ body: JSON.stringify( req.body ),
628
+ };
629
+ let url = JSON.parse( process.env.LAMBDAURL );
630
+ let searchResponse = await fetch( url.redoChecklist, requestOptions );
631
+ console.log( searchResponse.ok );
632
+ let logData= {
633
+ 'client_id': checklistDetails.client_id,
634
+ 'createAt': new Date(),
635
+ 'sourceCheckList_id': checklistDetails.sourceCheckList_id,
636
+ 'checkListName': checklistDetails.checkListName,
637
+ 'fromCheckListName': checklistDetails.checkListName,
638
+ 'type': 'checklist',
639
+ 'action': checklistDetails.redoStatus?'multiredo': 'redo',
640
+ 'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
641
+ 'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
642
+ 'userName': checklistDetails.userName,
643
+ 'userEmail': checklistDetails.userEmail,
644
+ 'createdByEmail': req.user.email,
645
+ 'createdBy': req.user.userName,
646
+ 'coverage': checklistDetails.coverage,
647
+ 'logDetails': {},
648
+ 'userType': req.user.userType,
649
+ };
650
+ let urlopensearch = JSON.parse( process.env.OPENSEARCH );
651
+ console.log( 'logData', logData );
652
+ insertOpenSearchData( urlopensearch.traxActivityLog, logData );
653
+ }
654
+ }
655
+ return res.sendSuccess( 'Question redo successfully' );
656
+ } catch ( e ) {
657
+ logger.error( { function: 'redomultiChecklist', error: e } );
658
+ return res.sendError( e, 500 );
659
+ }
660
+ }
661
+
458
662
 
459
663
  export async function getLogs( req, res ) {
460
664
  try {
@@ -286,6 +286,7 @@ export async function PCLconfigCreation( req, res ) {
286
286
  insertdata.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
287
287
  insertdata.allowedMultiSubmit = getCLconfig.allowedMultiSubmit;
288
288
  insertdata.rawImageUpload = getCLconfig.rawImageUpload || false;
289
+ insertdata.rawVideoUpload = getCLconfig.rawVideoUpload || false;
289
290
  let collectSections = [];
290
291
  let sectionQuery = [];
291
292
  sectionQuery.push( {
@@ -295,7 +296,7 @@ export async function PCLconfigCreation( req, res ) {
295
296
  },
296
297
  } );
297
298
  let getSections = await CLquestions.aggregate( sectionQuery );
298
- if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection' ].includes( getCLconfig.checkListType ) ) {
299
+ if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo','vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
299
300
  if ( getSections.length ) {
300
301
  for ( let element3 of getSections ) {
301
302
  let collectQuestions = {};
@@ -562,6 +563,7 @@ export async function PCLconfigCreation( req, res ) {
562
563
  // element4.isPlano = getCLconfig?.isPlano;
563
564
  // }
564
565
  element4.rawImageUpload = getCLconfig?.rawImageUpload || false;
566
+ element4.rawVideoUpload = getCLconfig?.rawVideoUpload || false;
565
567
  }
566
568
  if ( userIdList.length ) {
567
569
  allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
@@ -589,11 +591,11 @@ export async function PCLconfigCreation( req, res ) {
589
591
  // }
590
592
  }
591
593
  } else {
592
- if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection' ].includes( getCLconfig.checkListType ) ) {
594
+ if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo','vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
593
595
  let storeNameList = allQuestion.map( ( item ) => item.store_id );
594
- let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
596
+ let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
595
597
  let storeList = storeDetails.map( ( store ) => store.storeId );
596
- if ( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
598
+ if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) {
597
599
  allQuestion = allQuestion.filter( ( ele ) => storeList.includes( ele?.store_id ) );
598
600
  } else {
599
601
  allQuestion = storeDetails.map( ( item ) => {
@@ -627,7 +629,7 @@ export async function PCLconfigCreation( req, res ) {
627
629
  client_id: getCLconfig.client_id,
628
630
  aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => store.store_id ) : [],
629
631
  };
630
- if ( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
632
+ if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) {
631
633
  let processData = {
632
634
  aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => {
633
635
  return { storeName: store.storeName, storeId: store.store_id, events: store.events };
@@ -852,6 +854,7 @@ async function insertData( requestData ) {
852
854
  insertdata.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
853
855
  insertdata.allowedMultiSubmit = getCLconfig.allowedMultiSubmit;
854
856
  insertdata.rawImageUpload = getCLconfig.rawImageUpload || false;
857
+ insertdata.rawVideoUpload = getCLconfig.rawVideoUpload || false;
855
858
  let collectSections = [];
856
859
  let sectionQuery = [];
857
860
  sectionQuery.push( {
@@ -861,7 +864,7 @@ async function insertData( requestData ) {
861
864
  },
862
865
  } );
863
866
  let getSections = await CLquestions.aggregate( sectionQuery );
864
- if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection' ].includes( getCLconfig.checkListType ) ) {
867
+ if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo','vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
865
868
  if ( getSections.length ) {
866
869
  for ( let element3 of getSections ) {
867
870
  let collectQuestions = {};
@@ -1128,6 +1131,7 @@ async function insertData( requestData ) {
1128
1131
  // element4.isPlano = getCLconfig?.isPlano;
1129
1132
  // }
1130
1133
  element4.rawImageUpload = getCLconfig?.rawImageUpload || false;
1134
+ element4.rawVideoUpload = getCLconfig?.rawVideoUpload || false;
1131
1135
  }
1132
1136
  if ( userIdList.length ) {
1133
1137
  allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
@@ -1154,11 +1158,11 @@ async function insertData( requestData ) {
1154
1158
  // }
1155
1159
  }
1156
1160
  } else {
1157
- if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection' ].includes( getCLconfig.checkListType ) ) {
1161
+ if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo','vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
1158
1162
  let storeNameList = allQuestion.map( ( item ) => item.store_id );
1159
- let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
1163
+ let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
1160
1164
  let storeList = storeDetails.map( ( store ) => store.storeId );
1161
- if ( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
1165
+ if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) {
1162
1166
  allQuestion = allQuestion.filter( ( ele ) => storeList.includes( ele?.store_id ) );
1163
1167
  } else {
1164
1168
  allQuestion = storeDetails.map( ( item ) => {
@@ -1192,7 +1196,7 @@ async function insertData( requestData ) {
1192
1196
  client_id: getCLconfig.client_id,
1193
1197
  aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => store.store_id ) : [],
1194
1198
  };
1195
- if ( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
1199
+ if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) {
1196
1200
  let processData = {
1197
1201
  aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => {
1198
1202
  return { storeName: store.storeName, storeId: store.store_id, events: store.events };
@@ -2013,15 +2017,15 @@ export async function getPDFCSVChecklistDetails( req, res ) {
2013
2017
 
2014
2018
  export async function AiPushNotificationAlert( req, res ) {
2015
2019
  try {
2016
- console.log( req.body );
2020
+ // console.log( req.body );
2017
2021
  let findAichecklist = await PCLconfig.findOne( { checkListType: req.body.checkListType, client_id: req.body.clientId, date_string: req.body.Date }, { aiConfig: 1 } );
2018
2022
  if ( findAichecklist.aiConfig&&findAichecklist.aiConfig.alerts&&findAichecklist.aiConfig.alerts.users&&findAichecklist.aiConfig.alerts.users.length>0 ) {
2019
- console.log( findAichecklist.aiConfig.alerts.users );
2023
+ // console.log( findAichecklist.aiConfig.alerts.users );
2020
2024
  for ( let user of findAichecklist.aiConfig.alerts.users ) {
2021
2025
  let findOneUser = await userService.findOne( { email: user }, { fcmToken: 1 } );
2022
- console.log( findOneUser );
2026
+ // console.log( findOneUser );
2023
2027
  if ( findOneUser&&findOneUser.fcmToken&&findOneUser.fcmToken!='' ) {
2024
- console.log( findOneUser.fcmToken );
2028
+ // console.log( findOneUser.fcmToken );
2025
2029
  try {
2026
2030
  await sendPushNotification( req.body.title, req.body.description, findOneUser.fcmToken );
2027
2031
  } catch ( e ) {
@@ -2309,3 +2313,35 @@ export async function internalAISendPushNotification( req, res ) {
2309
2313
  else res.sendError( e, 500 );
2310
2314
  }
2311
2315
  };
2316
+
2317
+ export async function getLiveChecklistClients( req, res ) {
2318
+ try {
2319
+ let inputData = req.body;
2320
+ let query = [
2321
+ {
2322
+ $match: {
2323
+ isdeleted: false,
2324
+ publish: true,
2325
+ client_id: {
2326
+ $nin: inputData.ignoreClientId,
2327
+ $exists: true,
2328
+ $ne: null,
2329
+ },
2330
+ },
2331
+ },
2332
+ { $group: { _id: '$client_id' } },
2333
+ { $sort: { _id: 1 } },
2334
+ { $group: { _id: null, client_ids: { $push: '$_id' } } },
2335
+ ];
2336
+
2337
+ let getchecklistsData = await CLconfig.aggregate( query );
2338
+ if ( getchecklistsData && getchecklistsData.length >0 ) {
2339
+ return res.sendSuccess( { liveChecklistClients: getchecklistsData[0].client_ids } );
2340
+ } else {
2341
+ return res.sendError( 'Checklist Not Available', 204 );
2342
+ }
2343
+ } catch ( error ) {
2344
+ if ( error.name === 'ValidationError' ) res.sendBadRequest( error );
2345
+ else res.sendError( error, 500 );
2346
+ }
2347
+ }