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

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