tango-app-api-store-builder 1.0.0-beta-158 → 1.0.0-beta-159

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.
@@ -1451,8 +1451,6 @@ export async function updateMissing( req, res ) {
1451
1451
 
1452
1452
  if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
1453
1453
 
1454
- console.log('called')
1455
-
1456
1454
  await Promise.all(
1457
1455
  fixtureShelves.map( async ( shelf ) => {
1458
1456
  const productMappings = await planoMappingService.find( { shelfId: shelf._id } );
@@ -1461,18 +1459,18 @@ export async function updateMissing( req, res ) {
1461
1459
  return { ...shelf.toObject(), products: [] };
1462
1460
  }
1463
1461
 
1464
- // const productIds = productMappings.map( ( mapping ) => mapping.productId );
1465
- // const products = await planoProductService.find( { _id: { $in: productIds } } );
1466
- // const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
1462
+ const productIds = productMappings.map( ( mapping ) => mapping.productId );
1463
+ const products = await planoProductService.find( { _id: { $in: productIds } } );
1464
+ const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
1467
1465
 
1468
1466
  const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
1469
1467
 
1470
1468
  await Promise.all(
1471
1469
  productMappings.map( async ( mapping ) => {
1472
- // const productData = productMap.get( mapping?.productId?.toString() );
1473
- // if ( !productData ) {
1474
- // return { ...mapping.toObject(), status: '' };
1475
- // }
1470
+ const productData = productMap.get( mapping.productId.toString() );
1471
+ if ( !productData ) {
1472
+ return { ...mapping.toObject(), status: '' };
1473
+ }
1476
1474
 
1477
1475
  const mappingCompliance = await planoComplianceService.findOne( {
1478
1476
  planoMappingId: mapping._id,
@@ -1486,7 +1484,7 @@ export async function updateMissing( req, res ) {
1486
1484
 
1487
1485
  return {
1488
1486
  ...mapping.toObject(),
1489
- // ...productData,
1487
+ ...productData,
1490
1488
  };
1491
1489
  } ),
1492
1490
  );
@@ -4509,3 +4507,833 @@ export async function getPlanoUser( req, res ) {
4509
4507
  return res.sendError( e, 500 );
4510
4508
  }
4511
4509
  }
4510
+
4511
+ export async function getRolloutDetails( req, res ) {
4512
+ try {
4513
+ let page = req?.body?.offset || 1;
4514
+ let limit = req.body?.limit || 10;
4515
+ let skip = ( page -1 ) * limit;
4516
+ let storeDetails = await storeService.find( { clientId: req.body.clientId, status: 'active' }, { storeId: 1 } );
4517
+ storeDetails = storeDetails.map( ( ele ) => ele.storeId );
4518
+ let query = [
4519
+ {
4520
+ $match: {
4521
+ clientId: req.body.clientId,
4522
+ planoProgress: 100,
4523
+ storeId: { $in: storeDetails },
4524
+ },
4525
+ },
4526
+ {
4527
+ $lookup: {
4528
+ from: 'storefixtures',
4529
+ let: { floor: '$_id' },
4530
+ pipeline: [
4531
+ {
4532
+ $match: {
4533
+ $expr: {
4534
+ $eq: [ '$floorId', '$$floor' ],
4535
+ },
4536
+ },
4537
+ },
4538
+ {
4539
+ $group: {
4540
+ _id: '',
4541
+ fixtureCount: { $sum: 1 },
4542
+ vmCount: { $sum: { $size: '$vmConfig' } },
4543
+ fixtureCapacity: { $sum: '$fixtureCapacity' },
4544
+ },
4545
+ },
4546
+ ],
4547
+ as: 'fixtureDetails',
4548
+ },
4549
+ },
4550
+ { $unwind: { path: '$fixtureDetails', preserveNullAndEmptyArrays: true } },
4551
+ {
4552
+ $project: {
4553
+ _id: 0,
4554
+ planoId: 1,
4555
+ layoutName: 1,
4556
+ floorId: '$_id',
4557
+ floorNumber: 1,
4558
+ floorName: 1,
4559
+ planoProgress: 1,
4560
+ fixtureCount: '$fixtureDetails.fixtureCount',
4561
+ vmCount: '$fixtureDetails.vmCount',
4562
+ fixtureCapacity: '$fixtureDetails.fixtureCapacity',
4563
+ storeId: 1,
4564
+ storeName: 1,
4565
+ lastUpdate: '$updatedAt',
4566
+ },
4567
+ },
4568
+ {
4569
+ $lookup: {
4570
+ from: 'processedtasks',
4571
+ let: { floorId: '$floorId' },
4572
+ pipeline: [
4573
+ {
4574
+ $match: {
4575
+ $expr: {
4576
+ $and: [
4577
+ { $lte: [ '$date_iso', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ] },
4578
+ { $eq: [ '$floorId', '$$floorId' ] },
4579
+ { $eq: [ '$isPlano', true ] },
4580
+ { $in: [ '$planoType', [ 'merchRollout', 'vmRollout' ] ] },
4581
+ ],
4582
+ },
4583
+ },
4584
+ },
4585
+ {
4586
+ $sort: { _id: -1 },
4587
+ },
4588
+ {
4589
+ $group: {
4590
+ _id: '$planoType',
4591
+ type: { $first: '$planoType' },
4592
+ status: { $first: '$checklistStatus' },
4593
+ taskId: { $last: '$_id' },
4594
+ scheduleEndTime_iso: { $last: '$scheduleEndTime_iso' },
4595
+ },
4596
+ },
4597
+ {
4598
+ $project: {
4599
+ _id: 0,
4600
+ type: 1,
4601
+ status: 1,
4602
+ taskId: 1,
4603
+ breach: {
4604
+ $cond: {
4605
+ if: {
4606
+ $gte: [ '$scheduleEndTime_iso', new Date() ],
4607
+ },
4608
+ then: false,
4609
+ else: true,
4610
+ },
4611
+ },
4612
+ },
4613
+ },
4614
+ ],
4615
+ as: 'taskDetails',
4616
+ },
4617
+ },
4618
+ {
4619
+ $lookup: {
4620
+ from: 'planotaskcompliances',
4621
+ let: { floorId: '$floorId', taskId: '$taskDetails.taskId' },
4622
+ pipeline: [
4623
+ {
4624
+ $match: {
4625
+ $expr: {
4626
+ $and: [
4627
+ { $eq: [ '$floorId', '$$floorId' ] },
4628
+ { $in: [ '$taskId', '$$taskId' ] },
4629
+ { $in: [ '$type', [ 'merchRollout', 'vmRollout' ] ] },
4630
+ { $eq: [ '$status', 'incomplete' ] },
4631
+ ],
4632
+ },
4633
+ },
4634
+ },
4635
+ {
4636
+ $sort: { _id: -1 },
4637
+ },
4638
+ {
4639
+ $set: {
4640
+ hasPendingIssues: {
4641
+ $anyElementTrue: {
4642
+ $map: {
4643
+ input: {
4644
+ $reduce: {
4645
+ input: '$answers',
4646
+ initialValue: [],
4647
+ in: {
4648
+ $concatArrays: [
4649
+ '$$value',
4650
+ {
4651
+ $reduce: {
4652
+ input: { $ifNull: [ '$$this.issues', [] ] },
4653
+ initialValue: [],
4654
+ in: {
4655
+ $concatArrays: [
4656
+ '$$value',
4657
+ { $ifNull: [ '$$this.Details', [] ] },
4658
+ ],
4659
+ },
4660
+ },
4661
+ },
4662
+ ],
4663
+ },
4664
+ },
4665
+ },
4666
+ as: 'detail',
4667
+ in: {
4668
+ $or: [
4669
+ { $eq: [ '$$detail.status', 'pending' ] },
4670
+ ],
4671
+ },
4672
+ },
4673
+ },
4674
+ },
4675
+ hasDisagreeIssues: {
4676
+ $anyElementTrue: {
4677
+ $map: {
4678
+ input: {
4679
+ $reduce: {
4680
+ input: '$answers',
4681
+ initialValue: [],
4682
+ in: {
4683
+ $concatArrays: [
4684
+ '$$value',
4685
+ {
4686
+ $reduce: {
4687
+ input: { $ifNull: [ '$$this.issues', [] ] },
4688
+ initialValue: [],
4689
+ in: {
4690
+ $concatArrays: [
4691
+ '$$value',
4692
+ { $ifNull: [ '$$this.Details', [] ] },
4693
+ ],
4694
+ },
4695
+ },
4696
+ },
4697
+ ],
4698
+ },
4699
+ },
4700
+ },
4701
+ as: 'detail',
4702
+ in: {
4703
+ $or: [
4704
+ { $eq: [ '$$detail.status', 'disagree' ] },
4705
+ ],
4706
+ },
4707
+ },
4708
+ },
4709
+ },
4710
+ },
4711
+ },
4712
+ {
4713
+ $group: {
4714
+ _id: '$floorId',
4715
+ merchCount: {
4716
+ $sum: { $cond: [ { $eq: [ '$type', 'merchRollout' ] }, 1, 0 ] },
4717
+ },
4718
+ vmCount: {
4719
+ $sum: { $cond: [ { $eq: [ '$type', 'vmRollout' ] }, 1, 0 ] },
4720
+ },
4721
+ merchPending: {
4722
+ $sum: {
4723
+ $cond: [
4724
+ { $and: [ { $eq: [ '$type', 'merchRollout' ] }, '$hasPendingIssues' ] },
4725
+ 1,
4726
+ 0,
4727
+ ],
4728
+ },
4729
+ },
4730
+ vmPending: {
4731
+ $sum: {
4732
+ $cond: [
4733
+ { $and: [ { $eq: [ '$type', 'vmRollout' ] }, '$hasPendingIssues' ] },
4734
+ 1,
4735
+ 0,
4736
+ ],
4737
+ },
4738
+ },
4739
+ merchDisagree: {
4740
+ $sum: {
4741
+ $cond: [
4742
+ { $and: [ { $eq: [ '$type', 'merchRollout' ] }, '$hasDisagreeIssues' ] },
4743
+ 1,
4744
+ 0,
4745
+ ],
4746
+ },
4747
+ },
4748
+ vmDisagree: {
4749
+ $sum: {
4750
+ $cond: [
4751
+ { $and: [ { $eq: [ '$type', 'vmRollout' ] }, '$hasDisagreeIssues' ] },
4752
+ 1,
4753
+ 0,
4754
+ ],
4755
+ },
4756
+ },
4757
+ },
4758
+ },
4759
+ {
4760
+ $project: {
4761
+ _id: 0,
4762
+ fixtureStatus: {
4763
+ $switch: {
4764
+ branches: [
4765
+ {
4766
+ case: { $and: [ { $gt: [ '$merchCount', 0 ] }, { $gt: [ '$merchPending', 0 ] } ] },
4767
+ then: 'merchPending',
4768
+ },
4769
+ {
4770
+ case: { $and: [ { $gt: [ '$merchCount', 0 ] }, { $gt: [ '$merchDisagree', 0 ] } ] },
4771
+ then: 'merchDisagree',
4772
+ },
4773
+ ],
4774
+ default: '',
4775
+ },
4776
+ },
4777
+ vmStatus: {
4778
+ $switch: {
4779
+ branches: [
4780
+ {
4781
+ case: { $and: [ { $gt: [ '$vmCount', 0 ] }, { $gt: [ '$vmPending', 0 ] } ] },
4782
+ then: 'vmPending',
4783
+ },
4784
+ {
4785
+ case: { $and: [ { $gt: [ '$vmCount', 0 ] }, { $gt: [ '$vmDisagree', 0 ] } ] },
4786
+ then: 'vmDisagree',
4787
+ },
4788
+ ],
4789
+ default: '',
4790
+ },
4791
+ },
4792
+ },
4793
+ },
4794
+ ],
4795
+ as: 'taskFeedback',
4796
+ },
4797
+ },
4798
+ ];
4799
+
4800
+ if ( req.body?.filter?.type == 'rollout' ) {
4801
+ query.push( {
4802
+ $match: {
4803
+ $expr: {
4804
+ $gt: [ { $size: '$taskDetails' }, 0 ],
4805
+ },
4806
+ },
4807
+ } );
4808
+ }
4809
+ if ( [ 'vm', 'merch' ].includes( req.body?.filter?.type ) ) {
4810
+ let andCondition;
4811
+ if ( req.body.filter.type == 'merch' ) {
4812
+ andCondition = [
4813
+ {
4814
+ taskDetails: { $elemMatch: { type: 'merchRollout', status: 'submit' } },
4815
+ },
4816
+ {
4817
+ compliance: { $elemMatch: { feedbackStatus: 'merchPending' } },
4818
+ },
4819
+ ];
4820
+ } else {
4821
+ andCondition = [
4822
+ {
4823
+ taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } },
4824
+ },
4825
+ {
4826
+ compliance: { $elemMatch: { feedbackStatus: 'vmPending' } },
4827
+ },
4828
+ ];
4829
+ }
4830
+
4831
+ query.push( {
4832
+ $match: {
4833
+ $and: andCondition,
4834
+ },
4835
+ } );
4836
+ }
4837
+
4838
+ if ( req.body.filter?.type == 'flag' ) {
4839
+ query.push( {
4840
+ $match: {
4841
+ $and: [
4842
+ {
4843
+ taskDetails: { $elemMatch: { breach: true } },
4844
+ },
4845
+ ],
4846
+ },
4847
+ } );
4848
+ }
4849
+
4850
+ let extraCondition = [];
4851
+
4852
+ if ( req.body.searchValue ) {
4853
+ extraCondition.push( {
4854
+ $match: {
4855
+ storeName: { $regex: req.body.searchValue, $options: 'i' },
4856
+ },
4857
+ } );
4858
+ }
4859
+
4860
+ extraCondition.push(
4861
+ { $skip: skip },
4862
+ { $limit: limit },
4863
+ );
4864
+
4865
+ if ( req.body.sortColumnName && req.body.sortBy ) {
4866
+ query.push(
4867
+ { $sort: { [req.body.sortColumnName]: req.body.sortBy } },
4868
+ );
4869
+ }
4870
+
4871
+
4872
+ query.push( {
4873
+ $facet: {
4874
+ totalStore: [
4875
+ {
4876
+ $group: {
4877
+ _id: '',
4878
+ storeList: { $addToSet: '$storeId' },
4879
+ },
4880
+ },
4881
+ {
4882
+ $project: {
4883
+ _id: 0,
4884
+ count: { $size: '$storeList' },
4885
+ },
4886
+ },
4887
+ ],
4888
+ rollOutStore: [
4889
+ {
4890
+ $match: {
4891
+ $expr: { $gt: [ { $size: '$taskDetails' }, 0 ] },
4892
+ },
4893
+ },
4894
+ { $count: 'count' },
4895
+ ],
4896
+ merchPending: [
4897
+ {
4898
+ $match: {
4899
+ $and: [
4900
+ {
4901
+ taskDetails: {
4902
+ $elemMatch: { type: 'merchRollout', status: 'submit' },
4903
+ },
4904
+ },
4905
+ {
4906
+ compliance: {
4907
+ $elemMatch: { feedbackStatus: 'merchPending' },
4908
+ },
4909
+ },
4910
+ ],
4911
+ },
4912
+ },
4913
+ { $count: 'count' },
4914
+ ],
4915
+ vmPending: [
4916
+ {
4917
+ $match: {
4918
+ $and: [
4919
+ {
4920
+ taskDetails: {
4921
+ $elemMatch: { type: 'vmRollout', status: 'submit' },
4922
+ },
4923
+ },
4924
+ {
4925
+ compliance: {
4926
+ $elemMatch: { feedbackStatus: 'vmPending' },
4927
+ },
4928
+ },
4929
+ ],
4930
+ },
4931
+ },
4932
+ { $count: 'count' },
4933
+ ],
4934
+ flag: [
4935
+ {
4936
+ $match: {
4937
+ taskDetails: {
4938
+ $elemMatch: { breach: true },
4939
+ },
4940
+ },
4941
+ },
4942
+ { $count: 'count' },
4943
+ ],
4944
+ doubleFloorStore: [
4945
+ {
4946
+ $group: {
4947
+ _id: '$storeId',
4948
+ count: { $sum: 1 },
4949
+ },
4950
+ },
4951
+ {
4952
+ $match: {
4953
+ count: { $gt: 1 },
4954
+ },
4955
+ },
4956
+ {
4957
+ $group: {
4958
+ _id: '',
4959
+ doubleFloorList: { $addToSet: '$_id' },
4960
+ },
4961
+ },
4962
+ {
4963
+ $project: {
4964
+ doubleFloorList: 1,
4965
+ },
4966
+ },
4967
+ ],
4968
+ data: extraCondition,
4969
+ count: [
4970
+ ...extraCondition,
4971
+ { $count: 'total' },
4972
+ ],
4973
+ },
4974
+ } );
4975
+
4976
+
4977
+ let rolloutDetails = await storeBuilderService.aggregate( query );
4978
+ let result = {
4979
+ cardData: {
4980
+ totalStore: rolloutDetails?.[0]?.totalStore?.[0]?.count || 0,
4981
+ rolloutStore: rolloutDetails?.[0]?.rollOutStore?.[0]?.count || 0,
4982
+ merchPendingStore: rolloutDetails?.[0]?.merchPending?.[0]?.count || 0,
4983
+ vmPendingStore: rolloutDetails?.[0]?.vmPending?.[0]?.count || 0,
4984
+ flagStore: rolloutDetails?.[0]?.flag?.[0]?.count || 0,
4985
+ flagStore: rolloutDetails?.[0]?.flag?.[0]?.count || 0,
4986
+ doubleFloorStore: rolloutDetails?.[0]?.doubleFloorStore?.[0]?.doubleFloorList || [],
4987
+ },
4988
+ tableData: {
4989
+ count: rolloutDetails?.[0]?.count?.[0]?.total || 0,
4990
+ data: rolloutDetails?.[0]?.data || 0,
4991
+ },
4992
+ };
4993
+ return res.sendSuccess( result );
4994
+ } catch ( e ) {
4995
+ logger.error( { functionName: 'getRolloutDetails', error: e } );
4996
+ return res.sendError( e, 500 );
4997
+ }
4998
+ }
4999
+
5000
+ export async function getRolloutTaskDetails( req, res ) {
5001
+ try {
5002
+ if ( !req.query.planoId ) {
5003
+ return res.sendError( 'PlanoId is required', 400 );
5004
+ }
5005
+ let query = [
5006
+ {
5007
+ $match: {
5008
+ planoId: new mongoose.Types.ObjectId( req.query.planoId ),
5009
+ isPlano: true,
5010
+ date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
5011
+ floorId: new mongoose.Types.ObjectId( req.query.floorId ),
5012
+ planoType: { $in: [ 'merchRollout', 'vmRollout' ] },
5013
+ },
5014
+ },
5015
+ {
5016
+ $group: {
5017
+ _id: { type: '$planoType', floorId: '$floorId' },
5018
+ dateString: { $last: '$date_string' },
5019
+ checklistStatus: { $last: '$checklistStatus' },
5020
+ taskId: { $last: '$_id' },
5021
+ redoStatus: { $last: '$redoStatus' },
5022
+ scheduleEndTime_iso: { $last: '$scheduleEndTime_iso' },
5023
+ },
5024
+ },
5025
+ {
5026
+ $group: {
5027
+ _id: null,
5028
+ taskStatus: {
5029
+ $push: {
5030
+ type: '$_id.type',
5031
+ status: '$checklistStatus',
5032
+ date: '$dateString',
5033
+ floorId: '$_id.floorId',
5034
+ redoStatus: '$redoStatus',
5035
+ endTime: '$scheduleEndTime_iso',
5036
+ breach: {
5037
+ $cond: {
5038
+ if: {
5039
+ $gte: [ '$scheduleEndTime_iso', new Date() ],
5040
+ },
5041
+ then: false,
5042
+ else: true,
5043
+ },
5044
+ },
5045
+ },
5046
+ },
5047
+ taskIds: { $push: '$taskId' },
5048
+ },
5049
+ },
5050
+ {
5051
+ $lookup: {
5052
+ from: 'planotaskcompliances',
5053
+ let: {
5054
+ task: '$taskIds',
5055
+ },
5056
+ pipeline: [
5057
+ {
5058
+ $match: {
5059
+ $expr: {
5060
+ $and: [
5061
+ { $eq: [ '$planoId', new mongoose.Types.ObjectId( req.query.planoId ) ] },
5062
+ { $in: [ '$taskId', '$$task' ] },
5063
+ { $eq: [ '$status', 'incomplete' ] },
5064
+ { $in: [ '$type', [ 'merchRollout', 'vmRollout' ] ] },
5065
+ ],
5066
+ },
5067
+ },
5068
+ },
5069
+ { $sort: { _id: -1 } },
5070
+ {
5071
+ $set: {
5072
+ hasPendingIssues: {
5073
+ $anyElementTrue: {
5074
+ $map: {
5075
+ input: {
5076
+ $reduce: {
5077
+ input: '$answers',
5078
+ initialValue: [],
5079
+ in: {
5080
+ $concatArrays: [
5081
+ '$$value',
5082
+ {
5083
+ $reduce: {
5084
+ input: { $ifNull: [ '$$this.issues', [] ] },
5085
+ initialValue: [],
5086
+ in: {
5087
+ $concatArrays: [
5088
+ '$$value',
5089
+ { $ifNull: [ '$$this.Details', [] ] },
5090
+ ],
5091
+ },
5092
+ },
5093
+ },
5094
+ ],
5095
+ },
5096
+ },
5097
+ },
5098
+ as: 'detail',
5099
+ in: {
5100
+ $or: [
5101
+ { $eq: [ '$$detail.status', 'pending' ] },
5102
+ ],
5103
+ },
5104
+ },
5105
+ },
5106
+ },
5107
+ hasDisagreeIssues: {
5108
+ $anyElementTrue: {
5109
+ $map: {
5110
+ input: {
5111
+ $reduce: {
5112
+ input: '$answers',
5113
+ initialValue: [],
5114
+ in: {
5115
+ $concatArrays: [
5116
+ '$$value',
5117
+ {
5118
+ $reduce: {
5119
+ input: { $ifNull: [ '$$this.issues', [] ] },
5120
+ initialValue: [],
5121
+ in: {
5122
+ $concatArrays: [
5123
+ '$$value',
5124
+ { $ifNull: [ '$$this.Details', [] ] },
5125
+ ],
5126
+ },
5127
+ },
5128
+ },
5129
+ ],
5130
+ },
5131
+ },
5132
+ },
5133
+ as: 'detail',
5134
+ in: {
5135
+ $or: [
5136
+ { $eq: [ '$$detail.status', 'disagree' ] },
5137
+ ],
5138
+ },
5139
+ },
5140
+ },
5141
+ },
5142
+ },
5143
+ },
5144
+ {
5145
+ $group: {
5146
+ _id: '$floorId',
5147
+ merchCount: {
5148
+ $sum: { $cond: [ { $eq: [ '$type', 'merchRollout' ] }, 1, 0 ] },
5149
+ },
5150
+ vmCount: {
5151
+ $sum: { $cond: [ { $eq: [ '$type', 'vmRollout' ] }, 1, 0 ] },
5152
+ },
5153
+ merchPending: {
5154
+ $sum: {
5155
+ $cond: [
5156
+ { $and: [ { $eq: [ '$type', 'merchRollout' ] }, '$hasPendingIssues' ] },
5157
+ 1,
5158
+ 0,
5159
+ ],
5160
+ },
5161
+ },
5162
+ vmPending: {
5163
+ $sum: {
5164
+ $cond: [
5165
+ { $and: [ { $eq: [ '$type', 'vmRollout' ] }, '$hasPendingIssues' ] },
5166
+ 1,
5167
+ 0,
5168
+ ],
5169
+ },
5170
+ },
5171
+ merchDisagree: {
5172
+ $sum: {
5173
+ $cond: [
5174
+ { $and: [ { $eq: [ '$type', 'merchRollout' ] }, '$hasDisagreeIssues' ] },
5175
+ 1,
5176
+ 0,
5177
+ ],
5178
+ },
5179
+ },
5180
+ vmDisagree: {
5181
+ $sum: {
5182
+ $cond: [
5183
+ { $and: [ { $eq: [ '$type', 'vmRollout' ] }, '$hasDisagreeIssues' ] },
5184
+ 1,
5185
+ 0,
5186
+ ],
5187
+ },
5188
+ },
5189
+ },
5190
+ },
5191
+ {
5192
+ $project: {
5193
+ _id: 0,
5194
+ merchStatus: {
5195
+ $cond: {
5196
+ if: {
5197
+ $and: [
5198
+ { $gt: [ '$merchCount', 0 ] },
5199
+ { $eq: [ '$merchPending', 0 ] },
5200
+ { $eq: [ '$merchDisagree', 0 ] },
5201
+ ],
5202
+ },
5203
+ then: 'complete',
5204
+ else: {
5205
+ $cond: {
5206
+ if: {
5207
+ $and: [
5208
+ {
5209
+ $gt: [ '$merchCount', 0 ],
5210
+ },
5211
+ {
5212
+ $gt: [
5213
+ '$merchPending',
5214
+ 0,
5215
+ ],
5216
+ },
5217
+ ],
5218
+ },
5219
+ then: 'pending',
5220
+ else: {
5221
+ $cond: {
5222
+ if: {
5223
+ $and: [
5224
+ {
5225
+ $gt: [ '$merchCount', 0 ],
5226
+ },
5227
+ {
5228
+ $gt: [
5229
+ '$merchDisagree',
5230
+ 0,
5231
+ ],
5232
+ },
5233
+ ],
5234
+ },
5235
+ then: 'disagree',
5236
+ else: '',
5237
+ },
5238
+ },
5239
+ },
5240
+ },
5241
+ },
5242
+ },
5243
+ vmStatus: {
5244
+ $cond: {
5245
+ if: {
5246
+ $and: [
5247
+ { $gt: [ '$vmCount', 0 ] },
5248
+ { $eq: [ '$vmPending', 0 ] },
5249
+ { $eq: [ '$vmDisagree', 0 ] },
5250
+ ],
5251
+ },
5252
+ then: 'complete',
5253
+ else: {
5254
+ $cond: {
5255
+ if: {
5256
+ $and: [
5257
+ { $gt: [ '$vmCount', 0 ] },
5258
+ { $gt: [ '$vmPending', 0 ] },
5259
+ ],
5260
+ },
5261
+ then: 'pending',
5262
+ else: {
5263
+ $cond: {
5264
+ if: {
5265
+ $and: [
5266
+ {
5267
+ $gt: [ '$vmCount', 0 ],
5268
+ },
5269
+ {
5270
+ $gt: [
5271
+ '$vmDisagree',
5272
+ 0,
5273
+ ],
5274
+ },
5275
+ ],
5276
+ },
5277
+ then: 'disagree',
5278
+ else: '',
5279
+ },
5280
+ },
5281
+ },
5282
+ },
5283
+ },
5284
+ },
5285
+ },
5286
+ },
5287
+ ],
5288
+ as: 'taskDetails',
5289
+ },
5290
+ },
5291
+ {
5292
+ $project: {
5293
+ _id: 0,
5294
+ taskStatus: {
5295
+ $map: {
5296
+ input: '$taskStatus',
5297
+ as: 'task',
5298
+ in: {
5299
+ type: '$$task.type',
5300
+ status: '$$task.status',
5301
+ date: '$$task.date',
5302
+ floorId: '$$task.floorId',
5303
+ redoStatus: '$$task.redoStatus',
5304
+ endTime: '$$task.endTime',
5305
+ breach: '$$task.breach',
5306
+ feedbackStatus: {
5307
+ $switch: {
5308
+ branches: [
5309
+ {
5310
+ case: { $eq: [ '$$task.type', 'merchRollout' ] },
5311
+ then: { $arrayElemAt: [ '$taskDetails.merchStatus', 0 ] },
5312
+ },
5313
+ {
5314
+ case: { $eq: [ '$$task.type', 'vmRollout' ] },
5315
+ then: { $arrayElemAt: [ '$taskDetails.vmStatus', 0 ] },
5316
+ },
5317
+ ],
5318
+ default: '',
5319
+ },
5320
+ },
5321
+ },
5322
+ },
5323
+ },
5324
+ },
5325
+ },
5326
+
5327
+ ];
5328
+
5329
+ let taskInfo = await planotaskService.aggregate( query );
5330
+ const [ merchCount, vmCount ] = await Promise.all( [
5331
+ await layoutService.count( { _id: req.query.floorId, isMerchEdited: true } ),
5332
+ await layoutService.count( { _id: req.query.floorId, isVmEdited: true } ),
5333
+ ] );
5334
+ return res.sendSuccess( { taskDetails: taskInfo, merchCount, vmCount } );
5335
+ } catch ( e ) {
5336
+ logger.error( { functionName: 'getTaskDetails', error: e } );
5337
+ return res.sendError( e, 500 );
5338
+ }
5339
+ }