tango-app-api-task 3.5.0-alpha-7 → 3.6.0-task-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-task",
3
- "version": "3.5.0-alpha-7",
3
+ "version": "3.6.0-task-1",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "mongodb": "^6.10.0",
26
26
  "nodemon": "^3.1.7",
27
27
  "npm": "^10.9.2",
28
- "tango-api-schema": "^2.2.108",
29
- "tango-app-api-middleware": "^3.1.58",
28
+ "tango-api-schema": "^2.2.147",
29
+ "tango-app-api-middleware": "^3.1.77",
30
30
  "winston": "^3.17.0",
31
31
  "winston-daily-rotate-file": "^5.0.0"
32
32
  },
@@ -90,6 +90,7 @@ export async function createUpdateTask( req, res ) {
90
90
  createdByName: req.user.userName,
91
91
  questionCount: questionCount,
92
92
  client_id: req.body?.clientId,
93
+ checkListFrom: 'manage',
93
94
  };
94
95
  if ( inputBody._id ) {
95
96
  query = { _id: inputBody._id, client_id: req.body?.clientId };
@@ -1274,6 +1275,7 @@ export async function insertSingleProcessData( checklistId, answerTypechange, in
1274
1275
  insertdata.approver = getCLconfig?.approver || [];
1275
1276
  insertdata.restrictAttendance = getCLconfig?.restrictAttendance;
1276
1277
  insertdata.coverage = getCLconfig?.coverage;
1278
+ insertdata.checkListFrom = getCLconfig?.checkListFrom;
1277
1279
  let collectSections = [];
1278
1280
  let sectionQuery = [];
1279
1281
  sectionQuery.push( {
@@ -1316,7 +1318,7 @@ export async function insertSingleProcessData( checklistId, answerTypechange, in
1316
1318
 
1317
1319
  const dateArray = getDaysBeforeEndDate( endDate );
1318
1320
 
1319
- for ( const dateVal of dateArray ) {
1321
+ for ( const dateVal of [ dateArray[0] ] ) {
1320
1322
  const insertdataquery = {
1321
1323
  date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
1322
1324
  date_iso: dayjs( dateVal ).toDate(),
@@ -1520,6 +1522,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
1520
1522
  element4.remainder = getCLconfig?.remainder || [];
1521
1523
  element4.restrictAttendance = getCLconfig?.restrictAttendance;
1522
1524
  element4.coverage = getCLconfig?.coverage;
1525
+ element4.checkListFrom = getCLconfig?.checkListFrom;
1523
1526
  if ( inputBody && inputBody?.streamId ) {
1524
1527
  element4.streamId = inputBody?.streamId;
1525
1528
  }
@@ -1905,6 +1908,7 @@ export async function createChecklistTask( req, res ) {
1905
1908
  locationCount: 1,
1906
1909
  ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
1907
1910
  coverage: checklistDetails?.coverage || 'store',
1911
+ checkListFrom: 'gallery',
1908
1912
  };
1909
1913
 
1910
1914
  if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.user.role ) ) ) {
@@ -2133,6 +2137,7 @@ export async function createChecklistMultiTask( req, res ) {
2133
2137
  locationCount: 1,
2134
2138
  ...( originaldata?.checkListId ) ? { referenceCheckListId: originaldata?.checkListId } : {},
2135
2139
  coverage: checklistDetails?.coverage || 'store',
2140
+ checkListFrom: 'gallery',
2136
2141
  };
2137
2142
 
2138
2143
  if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.user.role ) ) ) {
@@ -2863,6 +2868,7 @@ export const taskList = async ( req, res ) => {
2863
2868
  checkListType: { $in: [ 'task', 'checklistTask', 'cctv' ] },
2864
2869
  client_id: req.query.clientId,
2865
2870
  isdeleted: false,
2871
+ checkListFrom: { $nin: [ 'api' ] },
2866
2872
  },
2867
2873
  },
2868
2874
  );
@@ -2892,6 +2898,7 @@ export const taskList = async ( req, res ) => {
2892
2898
  checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
2893
2899
  priorityType: 1,
2894
2900
  scheduleEndTimeISO: 1,
2901
+ checkListFrom: 1,
2895
2902
  },
2896
2903
  },
2897
2904
  );
@@ -3249,27 +3256,25 @@ export async function teamMigrations( req, res ) {
3249
3256
  }
3250
3257
  export async function clusterMigrations( req, res ) {
3251
3258
  try {
3252
- let input = [
3253
-
3254
- ];
3259
+ let input =[];
3255
3260
  for ( let user of input ) {
3256
- let userexits = await userService.findOne( { email: user.AOMsmailID } );
3261
+ let userexits = await userService.findOne( { 'email': user.clusterEmail, 'clientId': '11' } );
3257
3262
  if ( userexits ) {
3258
- let findStore = await storeService.findOne( { storeName: user.FacilityCode } );
3263
+ let findStore = await storeService.findOne( { 'storeName': user.storeName, 'clientId': '11' } );
3259
3264
  if ( findStore ) {
3260
- let clusterExists = await clusterServices.findOneCluster( { clusterName: user.AomName } );
3265
+ let clusterExists = await clusterServices.findOneCluster( { 'clusterName': user.clusterName, 'clientId': '11' } );
3261
3266
  if ( clusterExists ) {
3262
3267
  let data = {
3263
3268
  storeId: findStore.storeId,
3264
3269
  store: findStore._id,
3265
3270
  };
3266
- let updatecluster = await clusterServices.updateCluster( { clusterName: user.AomName }, { $push: { stores: data } } );
3271
+ let updatecluster = await clusterServices.updateCluster( { 'clusterName': user.clusterName, 'clientId': '11' }, { $push: { stores: data } } );
3267
3272
  console.log( updatecluster );
3268
3273
  } else {
3269
3274
  let payload = {
3270
- 'clusterName': user.AomName,
3275
+ 'clusterName': user.clusterName,
3271
3276
  'clientId': '11',
3272
- 'description': user.AomName,
3277
+ 'description': user.clusterName,
3273
3278
  'stores': [
3274
3279
  {
3275
3280
  storeId: findStore.storeId,
@@ -3450,7 +3455,7 @@ export async function createAiChecklist( req, res ) {
3450
3455
  return res.sendError( e, 500 );
3451
3456
  }
3452
3457
  }
3453
- export async function StoreHygienetask( req, res ) {
3458
+ export async function StoreHygienetaskOld( req, res ) {
3454
3459
  try {
3455
3460
  let inputBody = req.body;
3456
3461
 
@@ -3676,7 +3681,7 @@ export async function StoreHygienetask( req, res ) {
3676
3681
  return res.sendError( e, 500 );
3677
3682
  }
3678
3683
  }
3679
- export async function eyeTesttask( req, res ) {
3684
+ export async function eyeTesttaskOld( req, res ) {
3680
3685
  try {
3681
3686
  let inputBody = req.body;
3682
3687
  inputBody.clientId = 11;
@@ -3901,6 +3906,7 @@ export async function eyeTesttask( req, res ) {
3901
3906
  return res.sendError( e, 500 );
3902
3907
  }
3903
3908
  }
3909
+
3904
3910
  export async function createAiTask( req, res ) {
3905
3911
  try {
3906
3912
  let inputBody = req.body;
@@ -4745,6 +4751,8 @@ export async function commonAiTask( req, res ) {
4745
4751
  publishDate: new Date(),
4746
4752
  locationCount: 1,
4747
4753
  ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
4754
+ coverage: 'store',
4755
+ checkListFrom: 'api',
4748
4756
  };
4749
4757
  data['approver'] = userAdmin;
4750
4758
  let answer = await findAnswer( inputBody?.answerType );
@@ -5362,3 +5370,622 @@ export async function userMigrations( req, res ) {
5362
5370
  return res.sendError( error, 500 );
5363
5371
  }
5364
5372
  }
5373
+
5374
+ export async function StoreHygienetask( req, res ) {
5375
+ try {
5376
+ let inputBody = req.body;
5377
+
5378
+ inputBody.clientId = 11;
5379
+ inputBody.taskDescription = '';
5380
+ let userId;
5381
+ let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
5382
+ if ( !storeDetails ) {
5383
+ return res.sendError( 'Store Not Found', 500 );
5384
+ }
5385
+
5386
+ let url = JSON.parse( process.env.LAMBDAURL );
5387
+ let dailychecklistId = new mongoose.Types.ObjectId( url.dailystoreChecklistId );
5388
+ let KSAchecklistId = new mongoose.Types.ObjectId( url.KSAchecklist );
5389
+ let UAEchecklistId = new mongoose.Types.ObjectId( url.UAEchecklist );
5390
+ let singaporechecklistId = new mongoose.Types.ObjectId( url.singaporechecklist );
5391
+
5392
+ let finduser = await checklistassignconfigModel.findOne( { checkListId: { $in: [ dailychecklistId, KSAchecklistId, UAEchecklistId, singaporechecklistId ] }, store_id: storeDetails.storeId } );
5393
+ if ( !finduser ) {
5394
+ return res.sendError( 'No user Found For this store', 500 );
5395
+ }
5396
+
5397
+ userId = finduser.userId;
5398
+ inputBody.userName = finduser.userName;
5399
+ inputBody.userEmail = finduser.userEmail;
5400
+ let teamList = await findteams( { users: { $elemMatch: { email: finduser.userEmail } } } );
5401
+
5402
+ inputBody.approver = '';
5403
+ for ( let team of teamList ) {
5404
+ for ( let user of team.Teamlead ) {
5405
+ inputBody.approver = user.email + ',' + inputBody.approver;
5406
+ }
5407
+ }
5408
+ inputBody.approver = inputBody.approver.replace( /,$/, '' );
5409
+ let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
5410
+ let time = inputBody?.scheduleEndTime || '11:59 PM';
5411
+ let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
5412
+ let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
5413
+ let userDetails = await userService.findOne( { _id: new mongoose.Types.ObjectId( finduser.userId ) } );
5414
+ if ( userDetails && userDetails.fcmToken ) {
5415
+ const fcmToken = userDetails.fcmToken;
5416
+ await sendPushNotification( title, description, fcmToken );
5417
+ }
5418
+ const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
5419
+ const currentTime = dayjs.utc();
5420
+ if ( inputDateTime.isBefore( currentTime ) ) {
5421
+ return res.sendError( 'The input date-time is before the current time.', 500 );
5422
+ }
5423
+
5424
+ let approverList = inputBody?.approver.split( ',' );
5425
+ let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
5426
+ if ( userAdmin && userAdmin.length === 0 ) {
5427
+ userAdmin = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
5428
+ }
5429
+
5430
+ let creator = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true } );
5431
+ if ( creator && creator.length === 0 ) {
5432
+ return res.sendError( 'Invalid Creator Details', 500 );
5433
+ }
5434
+
5435
+ if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
5436
+ return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
5437
+ }
5438
+
5439
+ let answer = await findAnswer( inputBody?.answerType );
5440
+ if ( answer.length == 0 ) {
5441
+ return res.sendError( 'please enter Valid AnswerType', 500 );
5442
+ }
5443
+
5444
+ // Check this Task Already Exist////
5445
+ let checkTask = await taskService.findOne( { checkListName: inputBody.taskName } );
5446
+ if ( checkTask ) {
5447
+ let singleInsert = await insertStoreHygienetaskSingleProcessedTask( checkTask, inputBody, date, time, storeDetails, finduser, answer );
5448
+ if ( singleInsert ) {
5449
+ return res.sendSuccess( 'Task created successfully' );
5450
+ } else {
5451
+ return res.sendError( 'something went wrong, please try again', 500 );
5452
+ }
5453
+ } else {
5454
+ let data = {
5455
+ // checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}-${inputBody.zoneName ? inputBody.zoneName : ''})`,
5456
+ checkListName: inputBody.taskName,
5457
+ checkListDescription: inputBody.taskDescription,
5458
+ createdBy: creator[0]._id,
5459
+ createdByName: creator[0].userName,
5460
+ publish: true,
5461
+ questionCount: 1,
5462
+ storeCount: 1,
5463
+ scheduleDate: date,
5464
+ scheduleEndTime: time,
5465
+ scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
5466
+ priorityType: 'high',
5467
+ client_id: inputBody.clientId,
5468
+ checkListType: 'task',
5469
+ publishDate: new Date(),
5470
+ locationCount: 1,
5471
+ ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
5472
+ coverage: 'store',
5473
+ checkListFrom: 'api',
5474
+ };
5475
+ data['approver'] = userAdmin;
5476
+
5477
+ if ( inputBody?.answerType === 'multiplechoicesingle' || inputBody?.answerType === 'multiplechoicemultiple' ) {
5478
+ if ( inputBody?.options && inputBody?.options.length > 0 ) {
5479
+ let optionsResult = [];
5480
+ let optionList = inputBody?.options.split( ',' );
5481
+ for ( let option of optionList ) {
5482
+ let optiondata = {
5483
+ 'answer': '',
5484
+ 'sopFlag': false,
5485
+ 'validation': false,
5486
+ 'validationType': '',
5487
+ 'referenceImage': [],
5488
+ 'runAI': false,
5489
+ 'allowUploadfromGallery': false,
5490
+ 'descriptivetype': '',
5491
+ 'showLinked': false,
5492
+ 'linkedQuestion': 0,
5493
+ 'nestedQuestion': [],
5494
+ };
5495
+ optiondata.answer = option;
5496
+ optionsResult.push( optiondata );
5497
+ }
5498
+ answer = optionsResult;
5499
+ } else {
5500
+ return res.sendError( 'please enter Valid Options', 500 );
5501
+ }
5502
+ }
5503
+
5504
+ let response = await taskService.create( data );
5505
+ if ( response?.approver.length ) {
5506
+ let inputData = [];
5507
+ response?.approver.forEach( ( ele ) => {
5508
+ inputData.push( {
5509
+ userEmail: ele.email,
5510
+ checkListId: response._id,
5511
+ type: 'task',
5512
+ client_id: inputBody.clientId,
5513
+ checkListName: data?.checkListName || '',
5514
+ } );
5515
+ } );
5516
+ await traxApprover.insertMany( inputData );
5517
+ }
5518
+
5519
+ if ( response?._id ) {
5520
+ let question = [
5521
+ {
5522
+ 'qno': 1,
5523
+ 'qname': inputBody.question,
5524
+ 'answerType': inputBody?.answerType || 'yes/no',
5525
+ 'runAI': false,
5526
+ 'runAIDescription': '',
5527
+ 'allowUploadfromGallery': false,
5528
+ 'linkType': false,
5529
+ 'questionReferenceImage': [],
5530
+ 'answers': answer,
5531
+ 'descriptivetype': 'text',
5532
+ },
5533
+ ];
5534
+
5535
+ let images = [];
5536
+ for ( let imgpath of req.body.referenceImage ) {
5537
+ let configURL = JSON.parse( process.env.BUCKET );
5538
+ let inputData = {
5539
+ Bucket: configURL.aiTraxoutput,
5540
+ Key: imgpath,
5541
+ };
5542
+ let output = await getObject( inputData );
5543
+ let image = {
5544
+ data: output.Body,
5545
+ name: imgpath,
5546
+ mimetype: output.ContentType,
5547
+ };
5548
+ let uplaodedImage = await uploadmultiImage( image );
5549
+ let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
5550
+ let url = imgUrl.split( '/' );
5551
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
5552
+ url.splice( 0, 3 );
5553
+ }
5554
+ images.push( url.join( '/' ) );
5555
+ }
5556
+ question[0].questionReferenceImage = images;
5557
+
5558
+ if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
5559
+ answer[0].referenceImage = question[0].questionReferenceImage;
5560
+ }
5561
+
5562
+ question = {
5563
+ checkListId: response?._id,
5564
+ question: question,
5565
+ section: 'Section 1',
5566
+ checkList: data.checkListName,
5567
+ client_id: inputBody.clientId,
5568
+ };
5569
+ await taskQuestionService.create( question );
5570
+
5571
+ let userDetails = {
5572
+ userName: inputBody.userName,
5573
+ userEmail: inputBody.userEmail,
5574
+ store_id: storeDetails.storeId,
5575
+ storeName: storeDetails.storeName,
5576
+ city: storeDetails?.storeProfile?.city,
5577
+ checkFlag: true,
5578
+ checkListId: response?._id,
5579
+ checkListName: data.checkListName,
5580
+ client_id: inputBody.clientId,
5581
+ userId: userId,
5582
+ assignId: storeDetails?._id,
5583
+ };
5584
+ await taskAssignService.create( userDetails );
5585
+ await insertSingleProcessData( response?._id );
5586
+ return res.sendSuccess( 'Task created successfully' );
5587
+ }
5588
+ }
5589
+ } catch ( e ) {
5590
+ console.log( 'e =>', e );
5591
+ logger.error( { function: 'StoreHygienetask', error: e } );
5592
+ return res.sendError( e, 500 );
5593
+ }
5594
+ }
5595
+
5596
+ export async function eyeTesttask( req, res ) {
5597
+ try {
5598
+ let inputBody = req.body;
5599
+ inputBody.clientId = 11;
5600
+ inputBody.taskDescription = '';
5601
+ let userId;
5602
+ let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
5603
+ console.log( 'storeDetails =>', storeDetails );
5604
+ if ( !storeDetails ) {
5605
+ return res.sendError( 'Store Not Found', 500 );
5606
+ }
5607
+
5608
+ let url = JSON.parse( process.env.LAMBDAURL );
5609
+ let dailychecklistId = new mongoose.Types.ObjectId( url.dailystoreChecklistId );
5610
+ let KSAchecklistId = new mongoose.Types.ObjectId( url.KSAchecklist );
5611
+ let UAEchecklistId = new mongoose.Types.ObjectId( url.UAEchecklist );
5612
+ let singaporechecklistId = new mongoose.Types.ObjectId( url.singaporechecklist );
5613
+
5614
+ let finduser = await checklistassignconfigModel.findOne( { checkListId: { $in: [ dailychecklistId, KSAchecklistId, UAEchecklistId, singaporechecklistId ] }, store_id: storeDetails.storeId } );
5615
+
5616
+ if ( !finduser ) {
5617
+ return res.sendError( 'No user Found For this store', 500 );
5618
+ }
5619
+
5620
+ userId = finduser.userId;
5621
+ inputBody.userName = finduser.userName;
5622
+ inputBody.userEmail = finduser.userEmail;
5623
+ let teamList = await findteams( { users: { $elemMatch: { email: finduser.userEmail } } } );
5624
+
5625
+ inputBody.approver = '';
5626
+ for ( let team of teamList ) {
5627
+ for ( let user of team.Teamlead ) {
5628
+ inputBody.approver = user.email + ',' + inputBody.approver;
5629
+ }
5630
+ }
5631
+ inputBody.approver = inputBody.approver.replace( /,$/, '' );
5632
+
5633
+ let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
5634
+ let time = inputBody?.scheduleEndTime || '11:59 PM';
5635
+ let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
5636
+ let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
5637
+ let userDetails = await userService.findOne( { _id: new mongoose.Types.ObjectId( finduser.userId ) } );
5638
+ if ( userDetails && userDetails.fcmToken ) {
5639
+ const fcmToken = userDetails.fcmToken;
5640
+ await sendPushNotification( title, description, fcmToken );
5641
+ }
5642
+ const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
5643
+ const currentTime = dayjs.utc();
5644
+ if ( inputDateTime.isBefore( currentTime ) ) {
5645
+ return res.sendError( 'The input date-time is before the current time.', 500 );
5646
+ }
5647
+
5648
+ let approverList = inputBody?.approver.split( ',' );
5649
+ let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
5650
+
5651
+ if ( userAdmin && userAdmin.length === 0 ) {
5652
+ userAdmin = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
5653
+ }
5654
+
5655
+ let creator = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true } );
5656
+ if ( creator && creator.length === 0 ) {
5657
+ return res.sendError( 'Invalid Creator Details', 500 );
5658
+ }
5659
+
5660
+ if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
5661
+ return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
5662
+ }
5663
+
5664
+ let answer = await findAnswer( inputBody?.answerType );
5665
+ if ( answer.length == 0 ) {
5666
+ return res.sendError( 'please enter Valid AnswerType', 500 );
5667
+ }
5668
+
5669
+ // Check this Task Already Exist////
5670
+ let checkTask = await taskService.findOne( { checkListName: inputBody.taskName } );
5671
+ if ( checkTask ) {
5672
+ let singleInsert = await insertEyetestSingleProcessedTask( checkTask, inputBody, date, time, storeDetails, finduser, answer, req );
5673
+ if ( singleInsert ) {
5674
+ return res.sendSuccess( 'Task created successfully' );
5675
+ } else {
5676
+ return res.sendError( 'something went wrong, please try again', 500 );
5677
+ }
5678
+ } else {
5679
+ let data = {
5680
+ // checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )})`,
5681
+ checkListName: inputBody.taskName,
5682
+ checkListDescription: inputBody.taskDescription,
5683
+ createdBy: creator[0]._id,
5684
+ createdByName: creator[0].userName,
5685
+ publish: true,
5686
+ questionCount: 1,
5687
+ storeCount: 1,
5688
+ scheduleDate: date,
5689
+ scheduleEndTime: time,
5690
+ scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
5691
+ priorityType: 'high',
5692
+ client_id: inputBody.clientId,
5693
+ checkListType: 'task',
5694
+ publishDate: new Date(),
5695
+ locationCount: 1,
5696
+ ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
5697
+ };
5698
+ data['approver'] = userAdmin;
5699
+
5700
+ if ( inputBody?.answerType === 'multiplechoicesingle' || inputBody?.answerType === 'multiplechoicemultiple' ) {
5701
+ if ( inputBody?.options && inputBody?.options.length > 0 ) {
5702
+ let optionsResult = [];
5703
+ let optionList = inputBody?.options.split( ',' );
5704
+ for ( let option of optionList ) {
5705
+ let optiondata = {
5706
+ 'answer': '',
5707
+ 'sopFlag': false,
5708
+ 'validation': false,
5709
+ 'validationType': '',
5710
+ 'referenceImage': [],
5711
+ 'runAI': false,
5712
+ 'allowUploadfromGallery': false,
5713
+ 'descriptivetype': '',
5714
+ 'showLinked': false,
5715
+ 'linkedQuestion': 0,
5716
+ 'nestedQuestion': [],
5717
+ };
5718
+ optiondata.answer = option;
5719
+ optionsResult.push( optiondata );
5720
+ }
5721
+ answer = optionsResult;
5722
+ } else {
5723
+ return res.sendError( 'please enter Valid Options', 500 );
5724
+ }
5725
+ }
5726
+
5727
+ let response = await taskService.create( data );
5728
+ if ( response?.approver.length ) {
5729
+ let inputData = [];
5730
+ response?.approver.forEach( ( ele ) => {
5731
+ inputData.push( {
5732
+ userEmail: ele.email,
5733
+ checkListId: response._id,
5734
+ type: 'task',
5735
+ client_id: inputBody.clientId,
5736
+ checkListName: data?.checkListName || '',
5737
+ } );
5738
+ } );
5739
+ await traxApprover.insertMany( inputData );
5740
+ }
5741
+
5742
+ if ( response?._id ) {
5743
+ let question = [
5744
+ {
5745
+ 'qno': 1,
5746
+ 'qname': inputBody.question,
5747
+ 'answerType': inputBody?.answerType || 'yes/no',
5748
+ 'runAI': false,
5749
+ 'runAIDescription': '',
5750
+ 'allowUploadfromGallery': false,
5751
+ 'linkType': false,
5752
+ 'questionReferenceImage': [],
5753
+ 'answers': answer,
5754
+ 'descriptivetype': 'text',
5755
+ },
5756
+ ];
5757
+
5758
+ if ( req.files && req.files.referenceImage && req.files.referenceImage.length ) {
5759
+ let images = [];
5760
+ for ( let image of req.files.referenceImage ) {
5761
+ let uplaodedImage = await uploadmultiImage( image );
5762
+ let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
5763
+ let url = imgUrl.split( '/' );
5764
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
5765
+ url.splice( 0, 3 );
5766
+ }
5767
+ images.push( url.join( '/' ) );
5768
+ }
5769
+ question[0].questionReferenceImage = images;
5770
+ } else {
5771
+ let images = [];
5772
+ if ( req.files && req.files.referenceImage ) {
5773
+ let uplaodedImage = await uploadmultiImage( req.files.referenceImage );
5774
+ let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
5775
+ let url = imgUrl.split( '/' );
5776
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
5777
+ url.splice( 0, 3 );
5778
+ }
5779
+ images.push( url.join( '/' ) );
5780
+ question[0].questionReferenceImage = images;
5781
+ }
5782
+ }
5783
+
5784
+ if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
5785
+ answer[0].referenceImage = question[0].questionReferenceImage;
5786
+ }
5787
+
5788
+ question = {
5789
+ checkListId: response?._id,
5790
+ question: question,
5791
+ section: 'Section 1',
5792
+ checkList: data.checkListName,
5793
+ client_id: inputBody.clientId,
5794
+ };
5795
+ await taskQuestionService.create( question );
5796
+
5797
+ let userDetails = {
5798
+ userName: inputBody.userName,
5799
+ userEmail: inputBody.userEmail,
5800
+ store_id: storeDetails.storeId,
5801
+ storeName: storeDetails.storeName,
5802
+ city: storeDetails?.storeProfile?.city,
5803
+ checkFlag: true,
5804
+ checkListId: response?._id,
5805
+ checkListName: data.checkListName,
5806
+ client_id: inputBody.clientId,
5807
+ userId: userId,
5808
+ assignId: storeDetails?._id,
5809
+ };
5810
+ await taskAssignService.create( userDetails );
5811
+ await insertSingleProcessData( response?._id, true, inputBody );
5812
+ return res.sendSuccess( 'Task created successfully' );
5813
+ }
5814
+ }
5815
+ } catch ( e ) {
5816
+ logger.error( { function: 'eyeTesttask', error: e } );
5817
+ return res.sendError( e, 500 );
5818
+ }
5819
+ }
5820
+
5821
+ async function insertStoreHygienetaskSingleProcessedTask( checkTask, inputBody, date, time, storeDetails, finduser, answer ) {
5822
+ try {
5823
+ let getquestion = await taskQuestionService.findOne( { checkListId: checkTask._id } );
5824
+ let getolddata = await taskProcessedService.findOne( { sourceCheckList_id: checkTask._id } );
5825
+
5826
+ // Question Patten Making
5827
+ let question = [
5828
+ {
5829
+ 'qno': 1,
5830
+ 'qname': inputBody.question,
5831
+ 'answerType': inputBody?.answerType || 'yes/no',
5832
+ 'runAI': false,
5833
+ 'runAIDescription': '',
5834
+ 'allowUploadfromGallery': false,
5835
+ 'linkType': false,
5836
+ 'questionReferenceImage': [],
5837
+ 'answers': answer,
5838
+ 'descriptivetype': 'text',
5839
+ },
5840
+ ];
5841
+
5842
+ let images = [];
5843
+ for ( let imgpath of inputBody.referenceImage ) {
5844
+ let configURL = JSON.parse( process.env.BUCKET );
5845
+ let inputData = {
5846
+ Bucket: configURL.aiTraxoutput,
5847
+ Key: imgpath,
5848
+ };
5849
+ let output = await getObject( inputData );
5850
+ let image = {
5851
+ data: output.Body,
5852
+ name: imgpath,
5853
+ mimetype: output.ContentType,
5854
+ };
5855
+ let uplaodedImage = await uploadmultiImage( image );
5856
+ let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
5857
+ let url = imgUrl.split( '/' );
5858
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
5859
+ url.splice( 0, 3 );
5860
+ }
5861
+ images.push( url.join( '/' ) );
5862
+ }
5863
+ question[0].questionReferenceImage = images;
5864
+
5865
+ if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
5866
+ answer[0].referenceImage = question[0].questionReferenceImage;
5867
+ }
5868
+
5869
+ let questions = {
5870
+ questions: question,
5871
+ sectionName: getquestion.section,
5872
+ section_id: getquestion._id,
5873
+ };
5874
+
5875
+ let newData = getolddata.toObject();
5876
+ delete newData._id;
5877
+ newData.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
5878
+ newData.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
5879
+ newData.scheduleStartTime_iso = date;
5880
+ newData.scheduleEndTime_iso = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format();
5881
+ newData.store_id = storeDetails.storeId;
5882
+ newData.storeName = storeDetails.storeName;
5883
+ newData.country = storeDetails.storeProfile.country;
5884
+ newData.userId = finduser.userId;
5885
+ newData.userName = finduser.userName;
5886
+ newData.userEmail = finduser.userEmail;
5887
+ newData.checklistStatus = 'open';
5888
+ newData.timeFlagStatus = true;
5889
+ newData.checkListFrom = 'api';
5890
+ newData.createdAt = new Date();
5891
+ newData.updatedAt = new Date();
5892
+ newData.questionAnswers = [ questions ];
5893
+ let insertprocessdata = await taskProcessedService.insert( newData );
5894
+ if ( insertprocessdata ) {
5895
+ return true;
5896
+ } else {
5897
+ return false;
5898
+ }
5899
+ } catch ( error ) {
5900
+ logger.error( { error: error, function: 'insertSingleProcessedTask' } );
5901
+ return false;
5902
+ }
5903
+ }
5904
+
5905
+ async function insertEyetestSingleProcessedTask( checkTask, inputBody, date, time, storeDetails, finduser, answer, req ) {
5906
+ try {
5907
+ let getquestion = await taskQuestionService.findOne( { checkListId: checkTask._id } );
5908
+ let getolddata = await taskProcessedService.findOne( { sourceCheckList_id: checkTask._id } );
5909
+
5910
+ // Question Patten Making
5911
+ let question = [
5912
+ {
5913
+ 'qno': 1,
5914
+ 'qname': inputBody.question,
5915
+ 'answerType': inputBody?.answerType || 'yes/no',
5916
+ 'runAI': false,
5917
+ 'runAIDescription': '',
5918
+ 'allowUploadfromGallery': false,
5919
+ 'linkType': false,
5920
+ 'questionReferenceImage': [],
5921
+ 'answers': answer,
5922
+ 'descriptivetype': 'text',
5923
+ },
5924
+ ];
5925
+
5926
+ if ( req.files && req.files.referenceImage && req.files.referenceImage.length ) {
5927
+ let images = [];
5928
+ for ( let image of req.files.referenceImage ) {
5929
+ let uplaodedImage = await uploadmultiImage( image );
5930
+ let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
5931
+ let url = imgUrl.split( '/' );
5932
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
5933
+ url.splice( 0, 3 );
5934
+ }
5935
+ images.push( url.join( '/' ) );
5936
+ }
5937
+ question[0].questionReferenceImage = images;
5938
+ } else {
5939
+ let images = [];
5940
+ if ( req.files && req.files.referenceImage ) {
5941
+ let uplaodedImage = await uploadmultiImage( req.files.referenceImage );
5942
+ let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
5943
+ let url = imgUrl.split( '/' );
5944
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
5945
+ url.splice( 0, 3 );
5946
+ }
5947
+ images.push( url.join( '/' ) );
5948
+
5949
+ question[0].questionReferenceImage = images;
5950
+ }
5951
+ }
5952
+
5953
+ if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
5954
+ answer[0].referenceImage = question[0].questionReferenceImage;
5955
+ }
5956
+
5957
+ let questions = {
5958
+ questions: question,
5959
+ sectionName: getquestion.section,
5960
+ section_id: getquestion._id,
5961
+ };
5962
+
5963
+ let newData = getolddata.toObject();
5964
+ delete newData._id;
5965
+ newData.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
5966
+ newData.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
5967
+ newData.scheduleStartTime_iso = date;
5968
+ newData.scheduleEndTime_iso = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format();
5969
+ newData.store_id = storeDetails.storeId;
5970
+ newData.storeName = storeDetails.storeName;
5971
+ newData.country = storeDetails.storeProfile.country;
5972
+ newData.userId = finduser.userId;
5973
+ newData.userName = finduser.userName;
5974
+ newData.userEmail = finduser.userEmail;
5975
+ newData.checklistStatus = 'open';
5976
+ newData.timeFlagStatus = true;
5977
+ newData.checkListFrom = 'api';
5978
+ newData.createdAt = new Date();
5979
+ newData.updatedAt = new Date();
5980
+ newData.questionAnswers = [ questions ];
5981
+ let insertprocessdata = await taskProcessedService.insert( newData );
5982
+ if ( insertprocessdata ) {
5983
+ return true;
5984
+ } else {
5985
+ return false;
5986
+ }
5987
+ } catch ( error ) {
5988
+ logger.error( { error: error, function: 'insertSingleProcessedTask' } );
5989
+ return false;
5990
+ }
5991
+ }
@@ -51,9 +51,10 @@ export const overallCardsV1 = async ( req, res ) => {
51
51
  let requestData = req.body;
52
52
  let fromDate = new Date( requestData.fromDate );
53
53
  let toDate = new Date( requestData.toDate );
54
- let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
55
- toDate = new Date( toDate.getTime() - userTimezoneOffset );
56
- toDate.setUTCHours( 23, 59, 59, 59 );
54
+ toDate.setDate( toDate.getDate() + 1 );
55
+ // let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
56
+ // toDate = new Date( toDate.getTime() - userTimezoneOffset );
57
+ // toDate.setUTCHours( 23, 59, 59, 59 );
57
58
  let findQuery = [];
58
59
  let findAndQuery = [];
59
60
 
@@ -63,7 +64,9 @@ export const overallCardsV1 = async ( req, res ) => {
63
64
  // End: Get User Based Checklist////
64
65
 
65
66
  findAndQuery.push(
66
- { date_iso: { $gte: fromDate, $lte: toDate } },
67
+ // { date_iso: { $gte: fromDate, $lte: toDate } },
68
+ { scheduleStartTime_iso: { $lt: toDate } },
69
+ { scheduleEndTime_iso: { $gte: fromDate } },
67
70
  { client_id: requestData.clientId },
68
71
  // { store_id: { $in: requestData.storeId } },
69
72
  { $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ] },
@@ -228,6 +231,9 @@ export const taskTableV1 = async ( req, res ) => {
228
231
  export const taskInfoTableV1 = async ( req, res ) => {
229
232
  try {
230
233
  let requestData = req.body;
234
+ let fromDate = new Date( requestData.fromDate );
235
+ let toDate = new Date( requestData.toDate );
236
+ toDate.setDate( toDate.getDate() + 1 );
231
237
  let result = {};
232
238
 
233
239
  let findQuery = [];
@@ -239,7 +245,9 @@ export const taskInfoTableV1 = async ( req, res ) => {
239
245
  // End: Get User Based Checklist////
240
246
 
241
247
  findAndQuery.push(
242
- { date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
248
+ // { date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
249
+ { scheduleStartTime_iso: { $lt: toDate } },
250
+ { scheduleEndTime_iso: { $gte: fromDate } },
243
251
  { client_id: requestData.clientId },
244
252
  { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
245
253
  // { store_id: { $in: requestData.storeId } },
@@ -271,36 +279,36 @@ export const taskInfoTableV1 = async ( req, res ) => {
271
279
 
272
280
  findQuery.push( { $sort: { date_iso: -1, userName: 1 } } );
273
281
 
274
- findQuery.push(
275
- {
276
- $group: {
277
- _id: { userEmail: '$userEmail', storeId: '$store_id', checklistStatus: '$checklistStatus' },
278
- checkListName: { $first: '$checkListName' },
279
- createdByName: { $first: '$createdByName' },
280
- userName: { $first: '$userName' },
281
- userEmail: { $first: '$userEmail' },
282
- checklistStatus: { $first: '$checklistStatus' },
283
- submitTime_string: { $first: '$submitTime_string' },
284
- storeName: { $first: '$storeName' },
285
- checkListType: { $first: '$checkListType' },
286
- scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
287
- date_iso: { $first: '$date_iso' },
288
- store_id: { $first: '$store_id' },
289
- timeFlag: { $first: '$timeFlag' },
290
- date_string: { $first: '$date_string' },
291
- sourceCheckList_id: { $first: '$sourceCheckList_id' },
292
- reinitiateStatus: { $first: '$reinitiateStatus' },
293
- scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
294
- processedchecklistId: { $first: '$_id' },
295
- redoStatus: { $first: '$redoStatus' },
296
- priorityType: { $first: '$priorityType' },
297
- allowedStoreLocation: { $first: '$allowedStoreLocation' },
298
- restrictAttendance: { $first: '$restrictAttendance' },
299
- approvalByEmail: { $first: '$approvalByEmail' },
300
- approvalTime_string: { $first: '$approvalTime_string' },
301
- },
302
- },
303
- );
282
+ // findQuery.push(
283
+ // {
284
+ // $group: {
285
+ // _id: { userEmail: '$userEmail', storeId: '$store_id', checklistStatus: '$checklistStatus' },
286
+ // checkListName: { $first: '$checkListName' },
287
+ // createdByName: { $first: '$createdByName' },
288
+ // userName: { $first: '$userName' },
289
+ // userEmail: { $first: '$userEmail' },
290
+ // checklistStatus: { $first: '$checklistStatus' },
291
+ // submitTime_string: { $first: '$submitTime_string' },
292
+ // storeName: { $first: '$storeName' },
293
+ // checkListType: { $first: '$checkListType' },
294
+ // scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
295
+ // date_iso: { $first: '$date_iso' },
296
+ // store_id: { $first: '$store_id' },
297
+ // timeFlag: { $first: '$timeFlag' },
298
+ // date_string: { $first: '$date_string' },
299
+ // sourceCheckList_id: { $first: '$sourceCheckList_id' },
300
+ // reinitiateStatus: { $first: '$reinitiateStatus' },
301
+ // scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
302
+ // processedchecklistId: { $first: '$_id' },
303
+ // redoStatus: { $first: '$redoStatus' },
304
+ // priorityType: { $first: '$priorityType' },
305
+ // allowedStoreLocation: { $first: '$allowedStoreLocation' },
306
+ // restrictAttendance: { $first: '$restrictAttendance' },
307
+ // approvalByEmail: { $first: '$approvalByEmail' },
308
+ // approvalTime_string: { $first: '$approvalTime_string' },
309
+ // },
310
+ // },
311
+ // );
304
312
 
305
313
  findQuery.push( {
306
314
  $project: {
@@ -331,6 +339,12 @@ export const taskInfoTableV1 = async ( req, res ) => {
331
339
  },
332
340
  } );
333
341
 
342
+ if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
343
+ findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
344
+ } else {
345
+ findQuery.push( { $sort: { userEmail: 1 } } );
346
+ }
347
+
334
348
  findQuery.push( {
335
349
  $project: {
336
350
  _id: 0,
@@ -377,11 +391,6 @@ export const taskInfoTableV1 = async ( req, res ) => {
377
391
  },
378
392
  } );
379
393
 
380
- if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
381
- findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
382
- } else {
383
- findQuery.push( { $sort: { userEmail: 1 } } );
384
- }
385
394
 
386
395
  let limit = parseInt( requestData?.limit ) || 10;
387
396
  let skip = limit * ( requestData?.offset -1 ) || 0;
@@ -399,6 +408,7 @@ export const taskInfoTableV1 = async ( req, res ) => {
399
408
  } );
400
409
 
401
410
  let taskInfoData = await processedTaskService.aggregate( findQuery );
411
+ console.log( 'taskInfoData =>', taskInfoData.length );
402
412
 
403
413
  if ( !taskInfoData[0].data.length ) {
404
414
  return res.sendError( 'no data found', 204 );
@@ -429,7 +439,7 @@ export const taskInfoTableV1 = async ( req, res ) => {
429
439
  }
430
440
  return res.sendSuccess( result );
431
441
  } catch ( error ) {
432
- // console.log( 'error =>', error );
442
+ console.log( 'error =>', error );
433
443
  logger.error( { error: error, message: req.query, function: 'taskInfo' } );
434
444
  return res.sendError( { error: error }, 500 );
435
445
  }
@@ -763,6 +773,9 @@ export const taskDropdownListV1 = async ( req, res ) => {
763
773
  // { isdeleted: false },
764
774
  );
765
775
  findQuery.push( { $match: { $and: findAndQuery } }, { $sort: { date_iso: -1 } } );
776
+
777
+ findQuery.push( { $match: { $or: [ { checkListName: 'Store Hygiene Check' }, { checkListName: 'EyeTest QR Verification' } ] } } );
778
+
766
779
  findQuery.push(
767
780
  {
768
781
  $group: {
@@ -1026,11 +1039,12 @@ export async function taskDetails( req, res ) {
1026
1039
  // let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
1027
1040
  // let getUserEmails = await getChecklistUsers( loginUser );
1028
1041
  // End: Get User Based Checklist////
1029
-
1030
- let toDate = new Date( req.body.toDate );
1031
- let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
1032
- toDate = new Date( toDate.getTime() - userTimezoneOffset );
1033
- toDate.setUTCHours( 23, 59, 59, 59 );
1042
+ let fromDate = new Date( requestData.fromDate );
1043
+ let toDate = new Date( requestData.toDate );
1044
+ toDate.setDate( toDate.getDate() + 1 );
1045
+ // let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
1046
+ // toDate = new Date( toDate.getTime() - userTimezoneOffset );
1047
+ // toDate.setUTCHours( 23, 59, 59, 59 );
1034
1048
  let limit = req.body?.limit || 10;
1035
1049
  let page = req.body?.offset ? ( req.body.offset * req.body.limit ) : 0;
1036
1050
  let idList = [];
@@ -1049,14 +1063,16 @@ export async function taskDetails( req, res ) {
1049
1063
  let query = [
1050
1064
  {
1051
1065
  $match: {
1052
- date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
1066
+ // date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
1067
+ scheduleStartTime_iso: { $lt: toDate },
1068
+ scheduleEndTime_iso: { $gte: fromDate },
1053
1069
  client_id: req.body.clientId,
1054
1070
  ...( idList.length ) ? { sourceCheckList_id: { $in: idList } } : {},
1055
1071
  // store_id: { $in: req.body.storeId },
1056
1072
  $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ],
1057
1073
  },
1058
1074
  },
1059
- { $sort: { date_iso: -1 } },
1075
+ { $sort: { scheduleStartTime_iso: -1 } },
1060
1076
  {
1061
1077
  $group: {
1062
1078
  '_id': '$sourceCheckList_id',