tango-app-api-store-builder 1.0.15 → 1.0.17

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.
@@ -4,6 +4,7 @@ import { logger, insertOpenSearchData, getOpenSearchData, updateOpenSearchData,
4
4
  import * as planoService from '../service/planogram.service.js';
5
5
  import * as storeFixtureService from '../service/storeFixture.service.js';
6
6
  import * as fixtureShelfService from '../service/fixtureShelf.service.js';
7
+ import * as storeBuilderService from '../service/storeBuilder.service.js';
7
8
  // import * as planoProductService from '../service/planoProduct.service.js';
8
9
  import * as planoVmService from '../service/planoVm.service.js';
9
10
  // import * as planoMappingService from '../service/planoMapping.service.js';
@@ -18,67 +19,67 @@ import mongoose from 'mongoose';
18
19
  import * as planoRevisionService from '../service/planoRevision.service.js';
19
20
  import * as planoVmDuplicateService from '../service/planoVmDuplicate.service.js';
20
21
  import * as vmTypeService from '../service/vmType.service.js';
21
- import * as planoStaticService from '../service/planoStaticData.service.js';
22
- import * as processedChecklistService from '../service/processedchecklist.service.js';
23
-
24
- export async function getplanoFeedback(req, res) {
22
+ import * as planoMappingService from '../service/planoMapping.service.js';
23
+ import * as planoComplianceService from '../service/planoCompliance.service.js';
24
+ import dayjs from 'dayjs';
25
+ export async function getplanoFeedback( req, res ) {
25
26
  try {
26
- const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['layout', 'fixture', 'vm'];
27
+ const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'layout', 'fixture', 'vm' ];
27
28
  const filterByStatus = req.body.filterByStatus || [];
28
29
  const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
29
30
  const resultMap = {};
30
31
  const commentMap = {};
31
32
  await Promise.all(
32
- taskTypes.map(async (type, index) => {
33
- const pipeline = buildPipelineByType(type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask);
34
-
35
- let data = await planoTaskService.aggregate(pipeline);
36
- if (filterByApprovalStatus && filterByApprovalStatus?.length) {
37
- if (type == 'fixture') {
38
- let pendingData = [];
39
- let agreeData = [];
40
- let disAgreeData = [];
41
- if (filterByApprovalStatus.includes('pending')) {
42
- pendingData = data.filter((element) => {
43
- return element?.approvalStatus == 'pending';
44
- });
45
- } if (filterByApprovalStatus.includes('agree')) {
46
- agreeData = data.filter((element) => {
47
- return element?.answers?.[0]?.status == 'agree';
48
- });
49
- } if (filterByApprovalStatus.includes('disagree')) {
50
- disAgreeData = data.filter((element) => {
51
- return element?.answers?.[0]?.status == 'disagree';
52
- });
53
- }
54
- data = [...pendingData, ...agreeData, ...disAgreeData];
55
- } else {
56
- data.forEach((element) => {
57
- element.answers?.forEach((ans) => {
58
- ans.issues = ans.issues?.filter(
59
- (issue) => issue.Details && issue.Details.length > 0,
33
+ taskTypes.map( async ( type, index ) => {
34
+ const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
35
+
36
+ let data = await planoTaskService.aggregate( pipeline );
37
+ if ( filterByApprovalStatus && filterByApprovalStatus?.length ) {
38
+ if ( type == 'fixture' ) {
39
+ let pendingData = [];
40
+ let agreeData = [];
41
+ let disAgreeData = [];
42
+ if ( filterByApprovalStatus.includes( 'pending' ) ) {
43
+ pendingData = data.filter( ( element ) => {
44
+ return element?.approvalStatus == 'pending';
45
+ } );
46
+ } if ( filterByApprovalStatus.includes( 'agree' ) ) {
47
+ agreeData = data.filter( ( element ) => {
48
+ return element?.answers?.[0]?.status == 'agree';
49
+ } );
50
+ } if ( filterByApprovalStatus.includes( 'disagree' ) ) {
51
+ disAgreeData = data.filter( ( element ) => {
52
+ return element?.answers?.[0]?.status == 'disagree';
53
+ } );
54
+ }
55
+ data = [ ...pendingData, ...agreeData, ...disAgreeData ];
56
+ } else {
57
+ data.forEach( ( element ) => {
58
+ element.answers?.forEach( ( ans ) => {
59
+ ans.issues = ans.issues?.filter(
60
+ ( issue ) => issue.Details && issue.Details.length > 0,
61
+ );
62
+ } );
63
+ element.answers = element.answers?.filter(
64
+ ( ans ) => ans.issues && ans.issues.length > 0,
60
65
  );
61
- });
62
- element.answers = element.answers?.filter(
63
- (ans) => ans.issues && ans.issues.length > 0,
64
- );
65
- });
66
+ } );
67
+ }
68
+ data = data.filter(
69
+ ( element ) => element.answers && element.answers.length > 0,
70
+ );
66
71
  }
67
- data = data.filter(
68
- (element) => element.answers && element.answers.length > 0,
69
- );
70
- }
71
72
 
72
73
 
73
- resultMap[type] = data;
74
+ resultMap[type] = data;
74
75
 
75
- const comments = await planoGlobalCommentService.find({
76
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
77
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
78
- taskType: type,
79
- });
80
- commentMap[type] = comments;
81
- }),
76
+ const comments = await planoGlobalCommentService.find( {
77
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
78
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
79
+ taskType: type,
80
+ } );
81
+ commentMap[type] = comments;
82
+ } ),
82
83
  );
83
84
 
84
85
  const response = {
@@ -90,8 +91,8 @@ export async function getplanoFeedback(req, res) {
90
91
  vmComment: commentMap['vm'] || [],
91
92
  };
92
93
 
93
- response.fixtureData = await Promise.all(response.fixtureData.map(async (ele) => {
94
- if (ele?.FixtureData && ele?.FixtureData?._id) {
94
+ response.fixtureData = await Promise.all( response.fixtureData.map( async ( ele ) => {
95
+ if ( ele?.FixtureData && ele?.FixtureData?._id ) {
95
96
  // if ( !ele?.FixtureData._id ) {
96
97
  // return res.sendError( 'Fixture Id is required', 400 );
97
98
  // }
@@ -113,11 +114,12 @@ export async function getplanoFeedback(req, res) {
113
114
  };
114
115
 
115
116
 
116
- let aiDetails = await getOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoAIValidation, query);
117
- if (aiDetails.statusCode == 200) {
117
+ let aiDetails = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoAIValidation, query );
118
+ if ( aiDetails.statusCode == 200 ) {
118
119
  let data = {};
119
- if (aiDetails?.body?.hits?.hits.length) {
120
+ if ( aiDetails?.body?.hits?.hits.length ) {
120
121
  data = aiDetails?.body?.hits?.hits?.[0]?._source;
122
+ console.log( data, 'data' );
121
123
  delete data.isEmpty;
122
124
  delete data.fixtureFound;
123
125
  }
@@ -125,52 +127,52 @@ export async function getplanoFeedback(req, res) {
125
127
  }
126
128
  }
127
129
  return ele;
128
- }));
130
+ } ) );
129
131
 
130
- res.sendSuccess(response);
131
- } catch (e) {
132
- logger.error({ functionName: 'getplanoFeedback', error: e, message: req.body });
133
- return res.sendError(e, 500);
132
+ res.sendSuccess( response );
133
+ } catch ( e ) {
134
+ logger.error( { functionName: 'getplanoFeedback', error: e, message: req.body } );
135
+ return res.sendError( e, 500 );
134
136
  }
135
137
  }
136
- export async function getplanoFeedbackv1(req, res) {
138
+ export async function getplanoFeedbackv1( req, res ) {
137
139
  try {
138
- const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['layout', 'fixture', 'vm'];
140
+ const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'layout', 'fixture', 'vm' ];
139
141
  const filterByStatus = req.body.filterByStatus || [];
140
142
  const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
141
143
  const resultMap = {};
142
144
  const commentMap = {};
143
145
  await Promise.all(
144
- taskTypes.map(async (type, index) => {
145
- const pipeline = buildPipelineByType1(type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask);
146
-
147
- let data = await planoTaskService.aggregate(pipeline);
148
- if (filterByApprovalStatus && filterByApprovalStatus !== '') {
149
- data.forEach((element) => {
150
- element.answers?.forEach((ans) => {
151
- ans.issues = ans.issues?.filter(
152
- (issue) => issue.Details && issue.Details.length > 0,
146
+ taskTypes.map( async ( type, index ) => {
147
+ const pipeline = buildPipelineByType1( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
148
+
149
+ let data = await planoTaskService.aggregate( pipeline );
150
+ if ( filterByApprovalStatus && filterByApprovalStatus !== '' ) {
151
+ data.forEach( ( element ) => {
152
+ element.answers?.forEach( ( ans ) => {
153
+ ans.issues = ans.issues?.filter(
154
+ ( issue ) => issue.Details && issue.Details.length > 0,
155
+ );
156
+ } );
157
+ element.answers = element.answers?.filter(
158
+ ( ans ) => ans.issues && ans.issues.length > 0,
153
159
  );
154
- });
155
- element.answers = element.answers?.filter(
156
- (ans) => ans.issues && ans.issues.length > 0,
160
+ } );
161
+ data = data.filter(
162
+ ( element ) => element.answers && element.answers.length > 0,
157
163
  );
158
- });
159
- data = data.filter(
160
- (element) => element.answers && element.answers.length > 0,
161
- );
162
- }
164
+ }
163
165
 
164
166
 
165
- resultMap[type] = data;
167
+ resultMap[type] = data;
166
168
 
167
- const comments = await planoGlobalCommentService.find({
168
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
169
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
170
- taskType: type,
171
- });
172
- commentMap[type] = comments;
173
- }),
169
+ const comments = await planoGlobalCommentService.find( {
170
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
171
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
172
+ taskType: type,
173
+ } );
174
+ commentMap[type] = comments;
175
+ } ),
174
176
  );
175
177
 
176
178
  const response = {
@@ -182,41 +184,41 @@ export async function getplanoFeedbackv1(req, res) {
182
184
  vmComment: commentMap['vm'] || [],
183
185
  };
184
186
 
185
- res.sendSuccess(response);
186
- } catch (e) {
187
- logger.error({ functionName: 'getplanoFeedback', error: e, message: req.body });
188
- return res.sendError(e, 500);
187
+ res.sendSuccess( response );
188
+ } catch ( e ) {
189
+ logger.error( { functionName: 'getplanoFeedback', error: e, message: req.body } );
190
+ return res.sendError( e, 500 );
189
191
  }
190
192
  }
191
193
 
192
- function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0) {
194
+ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
193
195
  const matchStage = {
194
196
  $match: {
195
- planoId: new mongoose.Types.ObjectId(planoId),
196
- floorId: new mongoose.Types.ObjectId(floorId),
197
+ planoId: new mongoose.Types.ObjectId( planoId ),
198
+ floorId: new mongoose.Types.ObjectId( floorId ),
197
199
  type: type,
198
- ...(taskId && { taskId: new mongoose.Types.ObjectId(taskId) }),
199
- ...(filterByStatus?.length ? { status: { $in: filterByStatus } } : {}),
200
+ ...( taskId && { taskId: new mongoose.Types.ObjectId( taskId ) } ),
201
+ ...( filterByStatus?.length ? { status: { $in: filterByStatus } } : {} ),
200
202
  },
201
203
  };
202
204
 
203
205
 
204
206
  const conditionalMatchExpr = showtask ?
205
207
  {
206
- $eq: ['$_id', '$$taskId'],
208
+ $eq: [ '$_id', '$$taskId' ],
207
209
  } :
208
210
  {
209
211
  $and: [
210
212
  {
211
- $eq: ['$_id', '$$taskId'],
213
+ $eq: [ '$_id', '$$taskId' ],
212
214
  },
213
215
  {
214
216
  $or: [
215
- { $eq: ['$redoStatus', true] },
217
+ { $eq: [ '$redoStatus', true ] },
216
218
  {
217
219
  $and: [
218
- { $eq: ['$redoStatus', false] },
219
- { $eq: ['$checklistStatus', 'submit'] },
220
+ { $eq: [ '$redoStatus', false ] },
221
+ { $eq: [ '$checklistStatus', 'submit' ] },
220
222
  ],
221
223
  },
222
224
  ],
@@ -257,7 +259,7 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
257
259
  let: { fixtureId: '$fixtureId' },
258
260
  pipeline: [
259
261
  {
260
- $match: { $expr: { $eq: ['$_id', '$$fixtureId'] } },
262
+ $match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
261
263
  },
262
264
  ],
263
265
  as: 'FixtureData',
@@ -272,7 +274,7 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
272
274
  let: { fixtureId: '$FixtureData._id' },
273
275
  pipeline: [
274
276
  {
275
- $match: { $expr: { $eq: ['$fixtureId', '$$fixtureId'] } },
277
+ $match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
276
278
  },
277
279
  ],
278
280
  as: 'Fixtureshelves',
@@ -294,11 +296,11 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
294
296
  },
295
297
  },
296
298
  },
297
- }
299
+ },
298
300
 
299
301
  ];
300
302
 
301
- const vmStages = ['vm', 'vmRollout'].includes(type) ? [
303
+ const vmStages = [ 'vm', 'vmRollout' ].includes( type ) ? [
302
304
  {
303
305
  $unwind: { path: '$FixtureData.vmConfig', preserveNullAndEmptyArrays: true },
304
306
  },
@@ -308,7 +310,7 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
308
310
  let: { vmId: '$FixtureData.vmConfig.vmId' },
309
311
  pipeline: [
310
312
  {
311
- $match: { $expr: { $eq: ['$_id', '$$vmId'] } },
313
+ $match: { $expr: { $eq: [ '$_id', '$$vmId' ] } },
312
314
  },
313
315
  {
314
316
  $project: { vmName: 1, vmType: 1 },
@@ -345,7 +347,7 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
345
347
  collectedVmConfigs: {
346
348
  $push: {
347
349
  $cond: [
348
- { $ne: ['$FixtureData.vmConfig', {}] },
350
+ { $ne: [ '$FixtureData.vmConfig', {} ] },
349
351
  '$FixtureData.vmConfig',
350
352
  '$$REMOVE',
351
353
  ],
@@ -366,8 +368,8 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
366
368
  in: {
367
369
  $cond: [
368
370
  { $isArray: '$$this' },
369
- { $concatArrays: ['$$value', '$$this'] },
370
- { $concatArrays: ['$$value', ['$$this']] },
371
+ { $concatArrays: [ '$$value', '$$this' ] },
372
+ { $concatArrays: [ '$$value', [ '$$this' ] ] },
371
373
  ],
372
374
  },
373
375
  },
@@ -388,89 +390,89 @@ function buildPipelineByType(type, planoId, floorId, filterByStatus, filterByApp
388
390
  ...vmStages,
389
391
  { $sort: { _id: -1 } },
390
392
  ];
391
- if (filterByApprovalStatus && filterByApprovalStatus != '' && type !== 'fixture') {
393
+ if ( filterByApprovalStatus && filterByApprovalStatus != '' && type !== 'fixture' ) {
392
394
  pipeline = [];
393
- pipeline.push(matchStage);
395
+ pipeline.push( matchStage );
394
396
  pipeline.push(
395
- {
396
- $addFields: {
397
- answers: {
398
- $map: {
399
- input: '$answers',
400
- as: 'ans',
401
- in: {
402
- $mergeObjects: [
403
- '$$ans',
404
- {
405
- issues: {
406
- $map: {
407
- input: '$$ans.issues',
408
- as: 'issue',
409
- in: {
410
- $mergeObjects: [
411
- '$$issue',
412
- {
413
- Details: {
414
- $filter: {
415
- input: '$$issue.Details',
416
- as: 'detail',
417
- cond: filterByApprovalStatus === 'pending' ?
418
- { $eq: ['$$detail.status', 'pending'] } :
419
- { $ne: ['$$detail.status', 'pending'] },
397
+ {
398
+ $addFields: {
399
+ answers: {
400
+ $map: {
401
+ input: '$answers',
402
+ as: 'ans',
403
+ in: {
404
+ $mergeObjects: [
405
+ '$$ans',
406
+ {
407
+ issues: {
408
+ $map: {
409
+ input: '$$ans.issues',
410
+ as: 'issue',
411
+ in: {
412
+ $mergeObjects: [
413
+ '$$issue',
414
+ {
415
+ Details: {
416
+ $filter: {
417
+ input: '$$issue.Details',
418
+ as: 'detail',
419
+ cond: filterByApprovalStatus === 'pending' ?
420
+ { $eq: [ '$$detail.status', 'pending' ] } :
421
+ { $ne: [ '$$detail.status', 'pending' ] },
422
+ },
420
423
  },
421
424
  },
422
- },
423
- ],
425
+ ],
426
+ },
424
427
  },
425
428
  },
426
429
  },
427
- },
428
- ],
430
+ ],
431
+ },
429
432
  },
430
433
  },
431
434
  },
432
435
  },
433
- },
434
436
  );
435
- pipeline.push(taskLookup);
436
- pipeline.push(unwindTask);
437
- pipeline.push(...commonLookups);
438
- pipeline.push(...vmStages);
439
- pipeline.push({ $sort: { _id: -1 } });
437
+ pipeline.push( taskLookup );
438
+ pipeline.push( unwindTask );
439
+ pipeline.push( ...commonLookups );
440
+ pipeline.push( ...vmStages );
441
+ pipeline.push( { $sort: { _id: -1 } } );
440
442
  }
441
443
 
442
444
 
443
445
  return pipeline;
444
446
  }
445
447
 
446
- function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0) {
448
+ function buildPipelineByType1( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
447
449
  const matchStage = {
448
450
  $match: {
449
- planoId: new mongoose.Types.ObjectId(planoId),
450
- floorId: new mongoose.Types.ObjectId(floorId),
451
+ planoId: new mongoose.Types.ObjectId( planoId ),
452
+ floorId: new mongoose.Types.ObjectId( floorId ),
451
453
  type: type,
452
- ...(taskId && { taskId: new mongoose.Types.ObjectId(taskId) }),
453
- ...(filterByStatus?.length ? { status: { $in: filterByStatus } } : {}),
454
+ ...( taskId && { taskId: new mongoose.Types.ObjectId( taskId ) } ),
455
+ ...( filterByStatus?.length ? { status: { $in: filterByStatus } } : {} ),
454
456
  },
455
457
  };
456
458
 
457
459
 
458
460
  const conditionalMatchExpr = showtask ?
459
461
  {
460
- $eq: ['$_id', '$$taskId'],
462
+ $eq: [ '$_id', '$$taskId' ],
461
463
  } :
462
464
  {
463
465
  $and: [
464
466
  {
465
- $eq: ['$_id', '$$taskId'],
467
+ $eq: [ '$_id', '$$taskId' ],
466
468
  },
467
469
  {
468
470
  $or: [
469
- { $eq: ['$redoStatus', true] },
471
+ { $eq: [ '$redoStatus', true ] },
470
472
  {
471
473
  $and: [
472
- { $eq: ['$redoStatus', false] },
473
- { $eq: ['$checklistStatus', 'submit'] },
474
+ { $eq: [ '$redoStatus', false ] },
475
+ { $eq: [ '$checklistStatus', 'submit' ] },
474
476
  ],
475
477
  },
476
478
  ],
@@ -511,7 +513,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
511
513
  let: { fixtureId: '$fixtureId' },
512
514
  pipeline: [
513
515
  {
514
- $match: { $expr: { $eq: ['$_id', '$$fixtureId'] } },
516
+ $match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
515
517
  },
516
518
  ],
517
519
  as: 'FixtureData',
@@ -526,7 +528,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
526
528
  let: { fixtureId: '$FixtureData._id' },
527
529
  pipeline: [
528
530
  {
529
- $match: { $expr: { $eq: ['$fixtureId', '$$fixtureId'] } },
531
+ $match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
530
532
  },
531
533
  ],
532
534
  as: 'Fixtureshelves',
@@ -540,7 +542,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
540
542
  },
541
543
  ];
542
544
 
543
- const vmStages = ['vm', 'vmRollout'].includes(type) ? [
545
+ const vmStages = [ 'vm', 'vmRollout' ].includes( type ) ? [
544
546
  {
545
547
  $unwind: { path: '$FixtureData.vmConfig', preserveNullAndEmptyArrays: true },
546
548
  },
@@ -550,7 +552,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
550
552
  let: { vmId: '$FixtureData.vmConfig.vmId' },
551
553
  pipeline: [
552
554
  {
553
- $match: { $expr: { $eq: ['$_id', '$$vmId'] } },
555
+ $match: { $expr: { $eq: [ '$_id', '$$vmId' ] } },
554
556
  },
555
557
  {
556
558
  $project: { vmName: 1, vmType: 1 },
@@ -587,7 +589,7 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
587
589
  collectedVmConfigs: {
588
590
  $push: {
589
591
  $cond: [
590
- { $ne: ['$FixtureData.vmConfig', {}] },
592
+ { $ne: [ '$FixtureData.vmConfig', {} ] },
591
593
  '$FixtureData.vmConfig',
592
594
  '$$REMOVE',
593
595
  ],
@@ -608,8 +610,8 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
608
610
  in: {
609
611
  $cond: [
610
612
  { $isArray: '$$this' },
611
- { $concatArrays: ['$$value', '$$this'] },
612
- { $concatArrays: ['$$value', ['$$this']] },
613
+ { $concatArrays: [ '$$value', '$$this' ] },
614
+ { $concatArrays: [ '$$value', [ '$$this' ] ] },
613
615
  ],
614
616
  },
615
617
  },
@@ -630,136 +632,136 @@ function buildPipelineByType1(type, planoId, floorId, filterByStatus, filterByAp
630
632
  ...vmStages,
631
633
  { $sort: { _id: -1 } },
632
634
  ];
633
- if (filterByApprovalStatus && filterByApprovalStatus != '') {
635
+ if ( filterByApprovalStatus && filterByApprovalStatus != '' ) {
634
636
  pipeline = [];
635
- pipeline.push(matchStage);
637
+ pipeline.push( matchStage );
636
638
  pipeline.push(
637
- {
638
- $addFields: {
639
- answers: {
640
- $map: {
641
- input: '$answers',
642
- as: 'ans',
643
- in: {
644
- $mergeObjects: [
645
- '$$ans',
646
- {
647
- issues: {
648
- $map: {
649
- input: '$$ans.issues',
650
- as: 'issue',
651
- in: {
652
- $mergeObjects: [
653
- '$$issue',
654
- {
655
- Details: {
656
- $filter: {
657
- input: '$$issue.Details',
658
- as: 'detail',
659
- cond: filterByApprovalStatus === 'pending' ?
660
- { $eq: ['$$detail.status', 'pending'] } :
661
- { $ne: ['$$detail.status', 'pending'] },
639
+ {
640
+ $addFields: {
641
+ answers: {
642
+ $map: {
643
+ input: '$answers',
644
+ as: 'ans',
645
+ in: {
646
+ $mergeObjects: [
647
+ '$$ans',
648
+ {
649
+ issues: {
650
+ $map: {
651
+ input: '$$ans.issues',
652
+ as: 'issue',
653
+ in: {
654
+ $mergeObjects: [
655
+ '$$issue',
656
+ {
657
+ Details: {
658
+ $filter: {
659
+ input: '$$issue.Details',
660
+ as: 'detail',
661
+ cond: filterByApprovalStatus === 'pending' ?
662
+ { $eq: [ '$$detail.status', 'pending' ] } :
663
+ { $ne: [ '$$detail.status', 'pending' ] },
664
+ },
662
665
  },
663
666
  },
664
- },
665
- ],
667
+ ],
668
+ },
666
669
  },
667
670
  },
668
671
  },
669
- },
670
- ],
672
+ ],
673
+ },
671
674
  },
672
675
  },
673
676
  },
674
677
  },
675
- },
676
678
  );
677
- pipeline.push(taskLookup);
678
- pipeline.push(unwindTask);
679
- pipeline.push(...commonLookups);
680
- pipeline.push(...vmStages);
681
- pipeline.push({ $sort: { _id: -1 } });
679
+ pipeline.push( taskLookup );
680
+ pipeline.push( unwindTask );
681
+ pipeline.push( ...commonLookups );
682
+ pipeline.push( ...vmStages );
683
+ pipeline.push( { $sort: { _id: -1 } } );
682
684
  }
683
685
 
684
686
 
685
687
  return pipeline;
686
688
  }
687
689
 
688
- export async function getStoreFixturesfeedback(req, res) {
690
+ export async function getStoreFixturesfeedback( req, res ) {
689
691
  try {
690
692
  let query = [];
691
693
 
692
694
 
693
- query.push({
695
+ query.push( {
694
696
  $match: {
695
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
696
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
697
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
698
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
697
699
  type: { $ne: 'layout' },
698
700
  },
699
701
  },
700
- {
701
- $lookup: {
702
- from: 'processedtasks',
703
- let: { 'taskId': '$taskId' },
704
- pipeline: [
705
- {
706
- $match: {
707
- $expr: {
708
- $and: [
709
- { $eq: ['$_id', '$$taskId'] },
710
- ],
711
- },
702
+ {
703
+ $lookup: {
704
+ from: 'processedtasks',
705
+ let: { 'taskId': '$taskId' },
706
+ pipeline: [
707
+ {
708
+ $match: {
709
+ $expr: {
710
+ $and: [
711
+ { $eq: [ '$_id', '$$taskId' ] },
712
+ ],
712
713
  },
713
714
  },
714
- {
715
- $project: {
716
- 'userName': 1,
717
- 'createdAt': 1,
718
- 'createdByName': 1,
719
- 'submitTime_string': 1,
720
- },
715
+ },
716
+ {
717
+ $project: {
718
+ 'userName': 1,
719
+ 'createdAt': 1,
720
+ 'createdByName': 1,
721
+ 'submitTime_string': 1,
721
722
  },
722
- ],
723
- as: 'taskData',
724
- },
723
+ },
724
+ ],
725
+ as: 'taskData',
726
+ },
725
727
 
726
- }, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
727
- {
728
- $lookup: {
729
- from: 'fixtureconfigs',
730
- let: { 'fixtureId': '$fixtureId' },
731
- pipeline: [
732
- {
733
- $match: {
734
- $expr: {
735
- $and: [
736
- { $eq: ['$_id', '$$fixtureId'] },
737
- ],
738
- },
728
+ }, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
729
+ {
730
+ $lookup: {
731
+ from: 'fixtureconfigs',
732
+ let: { 'fixtureId': '$fixtureId' },
733
+ pipeline: [
734
+ {
735
+ $match: {
736
+ $expr: {
737
+ $and: [
738
+ { $eq: [ '$_id', '$$fixtureId' ] },
739
+ ],
739
740
  },
740
741
  },
741
- ],
742
- as: 'FixtureData',
743
- },
744
- },
745
- {
746
- $unwind: { path: '$FixtureData', preserveNullAndEmptyArrays: true },
742
+ },
743
+ ],
744
+ as: 'FixtureData',
747
745
  },
746
+ },
747
+ {
748
+ $unwind: { path: '$FixtureData', preserveNullAndEmptyArrays: true },
749
+ },
748
750
  );
749
751
 
750
752
 
751
- let findPlanoCompliance = await planoTaskService.aggregate(query);
752
- res.sendSuccess({ count: findPlanoCompliance.length, data: findPlanoCompliance });
753
- } catch (e) {
754
- logger.error({ functionName: 'getplanoFeedbackFixture', error: e, message: req.body });
755
- return res.sendError(e, 500);
753
+ let findPlanoCompliance = await planoTaskService.aggregate( query );
754
+ res.sendSuccess( { count: findPlanoCompliance.length, data: findPlanoCompliance } );
755
+ } catch ( e ) {
756
+ logger.error( { functionName: 'getplanoFeedbackFixture', error: e, message: req.body } );
757
+ return res.sendError( e, 500 );
756
758
  }
757
759
  }
758
- export async function updateStorePlano(req, res) {
760
+ export async function updateStorePlano( req, res ) {
759
761
  try {
760
762
  const { floorId, data } = req.body;
761
763
 
762
- const floorData = await floorService.findOne({ _id: new mongoose.Types.ObjectId(floorId) });
764
+ const floorData = await floorService.findOne( { _id: new mongoose.Types.ObjectId( floorId ) } );
763
765
 
764
766
  const additionalMeta = {
765
767
  clientId: '11',
@@ -769,78 +771,78 @@ export async function updateStorePlano(req, res) {
769
771
  floorId: floorData.toObject()._id,
770
772
  };
771
773
 
772
- const layoutPolygon = JSON.parse(JSON.stringify(data.layoutPolygon));
774
+ const layoutPolygon = JSON.parse( JSON.stringify( data.layoutPolygon ) );
773
775
 
774
- layoutPolygon.forEach((element) => {
776
+ layoutPolygon.forEach( ( element ) => {
775
777
  delete element.fixtures;
776
- });
778
+ } );
777
779
 
778
780
  await floorService.updateOne(
779
- { _id: new mongoose.Types.ObjectId(floorId) },
780
- {
781
- layoutPolygon: layoutPolygon,
782
- ...(req.body?.editMode === true && { isEdited: true }),
783
- },
781
+ { _id: new mongoose.Types.ObjectId( floorId ) },
782
+ {
783
+ layoutPolygon: layoutPolygon,
784
+ ...( req.body?.editMode === true && { isEdited: true } ),
785
+ },
784
786
  );
785
787
 
786
788
  // get fixtures
787
- const currentWallFixtures = data.layoutPolygon.flatMap((element) =>
788
- (element.fixtures || []).map((fixture) => fixture),
789
+ const currentWallFixtures = data.layoutPolygon.flatMap( ( element ) =>
790
+ ( element.fixtures || [] ).map( ( fixture ) => fixture ),
789
791
  );
790
792
  const currentFloorFixtures = data.centerFixture || [];
791
- const currentFixtures = [...currentWallFixtures, ...currentFloorFixtures];
793
+ const currentFixtures = [ ...currentWallFixtures, ...currentFloorFixtures ];
792
794
 
793
- const wallOtherElements = data.layoutPolygon.flatMap((element) =>
794
- (element.otherElements || []).map((el) => el),
795
+ const wallOtherElements = data.layoutPolygon.flatMap( ( element ) =>
796
+ ( element.otherElements || [] ).map( ( el ) => el ),
795
797
  );
796
798
  const floorOtherElements = data.otherElements || [];
797
- const currentOtherElements = [...wallOtherElements, ...floorOtherElements];
799
+ const currentOtherElements = [ ...wallOtherElements, ...floorOtherElements ];
798
800
 
799
- const existingFixtures = await storeFixtureService.find({
800
- floorId: new mongoose.Types.ObjectId(floorId),
801
+ const existingFixtures = await storeFixtureService.find( {
802
+ floorId: new mongoose.Types.ObjectId( floorId ),
801
803
  fixtureType: { $ne: 'other' },
802
- });
804
+ } );
803
805
 
804
- const existingOtherElements = await storeFixtureService.find({
805
- floorId: new mongoose.Types.ObjectId(floorId),
806
+ const existingOtherElements = await storeFixtureService.find( {
807
+ floorId: new mongoose.Types.ObjectId( floorId ),
806
808
  fixtureType: 'other',
807
- });
809
+ } );
808
810
 
809
- const currentOtherElementsIds = new Set(currentOtherElements.map((f) => f._id));
811
+ const currentOtherElementsIds = new Set( currentOtherElements.map( ( f ) => f._id ) );
810
812
 
811
813
  const removedOtherElements = existingOtherElements.filter(
812
- (f) => f._id && !currentOtherElementsIds.has(f._id.toString()),
814
+ ( f ) => f._id && !currentOtherElementsIds.has( f._id.toString() ),
813
815
  );
814
816
 
815
- if (removedOtherElements.length) {
816
- const otherElementIds = removedOtherElements.map((ele) => ele.toObject()._id);
817
- await storeFixtureService.deleteMany({ _id: { $in: otherElementIds } });
817
+ if ( removedOtherElements.length ) {
818
+ const otherElementIds = removedOtherElements.map( ( ele ) => ele.toObject()._id );
819
+ await storeFixtureService.deleteMany( { _id: { $in: otherElementIds } } );
818
820
  }
819
821
 
820
- const currentFixtureIds = new Set(currentFixtures.map((f) => f._id));
822
+ const currentFixtureIds = new Set( currentFixtures.map( ( f ) => f._id ) );
821
823
  const removedFixtures = existingFixtures.filter(
822
- (f) => f._id && !currentFixtureIds.has(f._id.toString()),
824
+ ( f ) => f._id && !currentFixtureIds.has( f._id.toString() ),
823
825
  );
824
826
 
825
- if (removedFixtures.length) {
826
- const fixtureIds = removedFixtures.map((fixture) => fixture.toObject()._id);
827
+ if ( removedFixtures.length ) {
828
+ const fixtureIds = removedFixtures.map( ( fixture ) => fixture.toObject()._id );
827
829
 
828
- await storeFixtureService.deleteMany({ _id: { $in: fixtureIds } });
829
- await fixtureShelfService.deleteMany({ fixtureId: { $in: fixtureIds } });
830
+ await storeFixtureService.deleteMany( { _id: { $in: fixtureIds } } );
831
+ await fixtureShelfService.deleteMany( { fixtureId: { $in: fixtureIds } } );
830
832
  }
831
833
 
832
834
  const newWallFixtures = currentWallFixtures.filter(
833
- (fixture) => fixture?._id?.startsWith('new'),
835
+ ( fixture ) => fixture?._id?.startsWith( 'new' ),
834
836
  );
835
837
  const newFloorFixtures = currentFloorFixtures.filter(
836
- (fixture) => fixture?._id?.startsWith('new'),
838
+ ( fixture ) => fixture?._id?.startsWith( 'new' ),
837
839
  );
838
840
 
839
- const newFixtures = [...newWallFixtures, ...newFloorFixtures];
841
+ const newFixtures = [ ...newWallFixtures, ...newFloorFixtures ];
840
842
 
841
843
  // ❗ async changed here
842
- if (newFixtures.length) {
843
- for (let i = 0; i < newFixtures.length; i++) {
844
+ if ( newFixtures.length ) {
845
+ for ( let i = 0; i < newFixtures.length; i++ ) {
844
846
  const fixture = newFixtures[i];
845
847
 
846
848
  delete fixture._id;
@@ -849,9 +851,9 @@ export async function updateStorePlano(req, res) {
849
851
  ...fixture,
850
852
  };
851
853
 
852
- const createdFixture = await storeFixtureService.create(fixturePayload);
854
+ const createdFixture = await storeFixtureService.create( fixturePayload );
853
855
 
854
- for (let j = 0; j < fixture.shelfConfig.length; j++) {
856
+ for ( let j = 0; j < fixture.shelfConfig.length; j++ ) {
855
857
  const shelf = fixture.shelfConfig[j];
856
858
 
857
859
  delete shelf._id;
@@ -861,26 +863,26 @@ export async function updateStorePlano(req, res) {
861
863
  fixtureId: createdFixture.toObject()._id,
862
864
  };
863
865
 
864
- await fixtureShelfService.create(shelfPayload);
866
+ await fixtureShelfService.create( shelfPayload );
865
867
  }
866
868
  }
867
869
  }
868
870
 
869
871
  const newOtherElements = currentOtherElements.filter(
870
- (ele) => ele?._id?.startsWith('new'),
872
+ ( ele ) => ele?._id?.startsWith( 'new' ),
871
873
  );
872
874
 
873
875
  // ❗ async changed here
874
- for (let i = 0; i < currentOtherElements.length; i++) {
876
+ for ( let i = 0; i < currentOtherElements.length; i++ ) {
875
877
  const ele = currentOtherElements[i];
876
- if (ele?._id && mongoose.Types.ObjectId.isValid(ele._id)) {
877
- await storeFixtureService.upsertOne({ _id: new mongoose.Types.ObjectId(ele._id) }, ele);
878
+ if ( ele?._id && mongoose.Types.ObjectId.isValid( ele._id ) ) {
879
+ await storeFixtureService.upsertOne( { _id: new mongoose.Types.ObjectId( ele._id ) }, ele );
878
880
  }
879
881
  }
880
882
 
881
883
  // ❗ async changed here
882
- if (newOtherElements.length) {
883
- for (let i = 0; i < newOtherElements.length; i++) {
884
+ if ( newOtherElements.length ) {
885
+ for ( let i = 0; i < newOtherElements.length; i++ ) {
884
886
  const ele = newOtherElements[i];
885
887
  delete ele._id;
886
888
 
@@ -889,27 +891,28 @@ export async function updateStorePlano(req, res) {
889
891
  ...additionalMeta,
890
892
  };
891
893
 
892
- await storeFixtureService.create(payload);
894
+ await storeFixtureService.create( payload );
893
895
  }
894
896
  }
895
897
 
896
- for (let i = 0; i < currentFixtures.length; i++) {
898
+ // async changed here
899
+ for ( let i = 0; i < currentFixtures.length; i++ ) {
897
900
  const fixture = currentFixtures[i];
898
901
 
899
- if (mongoose.Types.ObjectId.isValid(fixture._id)) {
902
+ if ( mongoose.Types.ObjectId.isValid( fixture._id ) ) {
900
903
  const updatedFixture = await storeFixtureService.upsertOne(
901
- { _id: new mongoose.Types.ObjectId(fixture._id) },
902
- fixture,
904
+ { _id: new mongoose.Types.ObjectId( fixture._id ) },
905
+ fixture,
903
906
  );
904
907
 
905
908
  await storeFixtureService.removeKeys(
906
- { fixtureType: 'floor', _id: fixture._id },
907
- { $unset: { associatedElementType: '', associatedElementNumber: '' } },
909
+ { fixtureType: 'floor', _id: fixture._id },
910
+ { $unset: { associatedElementType: '', associatedElementNumber: '' } },
908
911
  );
909
912
 
910
- await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixture._id) });
913
+ await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixture._id ) } );
911
914
 
912
- for (let j = 0; j < fixture.shelfConfig.length; j++) {
915
+ for ( let j = 0; j < fixture.shelfConfig.length; j++ ) {
913
916
  const shelf = fixture.shelfConfig[j];
914
917
 
915
918
  delete shelf._id;
@@ -920,109 +923,109 @@ export async function updateStorePlano(req, res) {
920
923
  fixtureId: updatedFixture.toObject()._id,
921
924
  };
922
925
 
923
- await fixtureShelfService.create(shelfPayload);
926
+ await fixtureShelfService.create( shelfPayload );
924
927
  }
925
928
  }
926
929
  }
927
930
 
928
-
931
+ updateFixtureNumber( floorId );
932
+
929
933
  await planoService.updateOne(
930
- { _id: floorData.toObject()?.planoId },
931
- { $set: { updatedAt: new Date() } },
934
+ { _id: floorData.toObject()?.planoId },
935
+ { $set: { updatedAt: new Date() } },
932
936
  );
933
937
 
934
- updateFixtureNumber(floorId);
935
-
936
- res.sendSuccess('Updated Successfully');
937
- } catch (e) {
938
- logger.error({ functionName: 'updateStorePlano', error: e });
939
- return res.sendError(e, 500);
938
+ res.sendSuccess( 'Updated Successfully' );
939
+ } catch ( e ) {
940
+ logger.error( { functionName: 'updateStorePlano', error: e } );
941
+ return res.sendError( e, 500 );
940
942
  }
941
943
  }
942
944
 
943
- async function updateFixtureNumber(floorId){
944
- let fixtureDetails = await storeFixtureService.findAndSort({ floorId: new mongoose.Types.ObjectId(floorId), fixtureType: { $ne: 'other' } }, {}, { fixtureType: -1, associatedElementNumber: 1 });
945
-
946
- fixtureDetails.sort((a, b) => {
947
- if (a.associatedElementNumber !== b.associatedElementNumber) {
945
+ async function updateFixtureNumber( floorId ) {
946
+ try {
947
+ let fixtureDetails = await storeFixtureService.findAndSort( { floorId: new mongoose.Types.ObjectId( floorId ), fixtureType: { $ne: 'other' } }, {}, { fixtureType: -1, associatedElementNumber: 1 } );
948
+ fixtureDetails.sort( ( a, b ) => {
949
+ if ( a.associatedElementNumber !== b.associatedElementNumber ) {
948
950
  return a.associatedElementNumber - b.associatedElementNumber;
949
951
  }
950
952
 
951
953
  return a.associatedElementFixtureNumber - b.associatedElementFixtureNumber;
952
- });
953
-
954
+ } );
954
955
  let fixtureNumber = 0;
955
-
956
- for (let fixture of fixtureDetails) {
956
+ for ( let fixture of fixtureDetails ) {
957
957
  fixtureNumber++;
958
- storeFixtureService.updateOne({ _id: fixture._id }, { fixtureNumber: fixtureNumber });
958
+ storeFixtureService.updateOne( { _id: fixture._id }, { fixtureNumber: fixtureNumber } );
959
959
  }
960
+ } catch ( e ) {
961
+ logger.error( { functionName: 'updateFixtureNumber', error: e } );
962
+ }
960
963
  }
961
964
 
962
965
 
963
- export async function fixtureList(req, res) {
966
+ export async function fixtureList( req, res ) {
964
967
  try {
965
- let findData = await fixtureLibraryService.find({ clientId: req.query.clientId });
966
- if (findData.length === 0) {
967
- return res.sendError('nodata found', 204);
968
+ let findData = await fixtureLibraryService.find( { clientId: req.query.clientId } );
969
+ if ( findData.length === 0 ) {
970
+ return res.sendError( 'nodata found', 204 );
968
971
  }
969
- res.sendSuccess(findData);
970
- } catch (e) {
971
- logger.error({ functionName: 'fixtureList', error: e });
972
- return res.sendError(e, 500);
972
+ res.sendSuccess( findData );
973
+ } catch ( e ) {
974
+ logger.error( { functionName: 'fixtureList', error: e } );
975
+ return res.sendError( e, 500 );
973
976
  }
974
977
  }
975
- export async function templateList(req, res) {
978
+ export async function templateList( req, res ) {
976
979
  try {
977
- let findData = await fixtureConfigService.find({ clientId: req.query.clientId, fixtureLibraryId: new mongoose.Types.ObjectId(req.query.fixtureId) });
978
- if (findData.length === 0) {
979
- return res.sendError('nodata found', 204);
980
+ let findData = await fixtureConfigService.find( { clientId: req.query.clientId, fixtureLibraryId: new mongoose.Types.ObjectId( req.query.fixtureId ) } );
981
+ if ( findData.length === 0 ) {
982
+ return res.sendError( 'nodata found', 204 );
980
983
  }
981
- res.sendSuccess(findData);
982
- } catch (e) {
983
- logger.error({ functionName: 'templateList', error: e });
984
- return res.sendError(e, 500);
984
+ res.sendSuccess( findData );
985
+ } catch ( e ) {
986
+ logger.error( { functionName: 'templateList', error: e } );
987
+ return res.sendError( e, 500 );
985
988
  }
986
989
  }
987
- export async function fixtureBrandsList(req, res) {
990
+ export async function fixtureBrandsList( req, res ) {
988
991
  try {
989
- let findData = await planoproductCategoryService.find({ clientId: req.query.clientId });
990
- if (findData.length === 0) {
991
- return res.sendError('nodata found', 204);
992
+ let findData = await planoproductCategoryService.find( { clientId: req.query.clientId } );
993
+ if ( findData.length === 0 ) {
994
+ return res.sendError( 'nodata found', 204 );
992
995
  }
993
- res.sendSuccess(findData);
994
- } catch (e) {
995
- logger.error({ functionName: 'fixtureBrandsList', error: e });
996
- return res.sendError(e, 500);
996
+ res.sendSuccess( findData );
997
+ } catch ( e ) {
998
+ logger.error( { functionName: 'fixtureBrandsList', error: e } );
999
+ return res.sendError( e, 500 );
997
1000
  }
998
1001
  }
999
1002
 
1000
- export async function fixtureVMList(req, res) {
1003
+ export async function fixtureVMList( req, res ) {
1001
1004
  try {
1002
- let findData = await planoVmService.find({ clientId: req.query.clientId });
1003
- if (findData.length === 0) {
1004
- return res.sendError('nodata found', 204);
1005
+ let findData = await planoVmService.find( { clientId: req.query.clientId } );
1006
+ if ( findData.length === 0 ) {
1007
+ return res.sendError( 'nodata found', 204 );
1005
1008
  }
1006
- res.sendSuccess(findData);
1007
- } catch (e) {
1008
- logger.error({ functionName: 'fixtureVMList', error: e });
1009
- return res.sendError(e, 500);
1009
+ res.sendSuccess( findData );
1010
+ } catch ( e ) {
1011
+ logger.error( { functionName: 'fixtureVMList', error: e } );
1012
+ return res.sendError( e, 500 );
1010
1013
  }
1011
1014
  }
1012
1015
 
1013
- export async function fixtureVMListv1(req, res) {
1016
+ export async function fixtureVMListv1( req, res ) {
1014
1017
  try {
1015
- let findData = await planoVmDuplicateService.find({ clientId: req.query.clientId });
1016
- if (findData.length === 0) {
1017
- return res.sendError('nodata found', 204);
1018
+ let findData = await planoVmDuplicateService.find( { clientId: req.query.clientId } );
1019
+ if ( findData.length === 0 ) {
1020
+ return res.sendError( 'nodata found', 204 );
1018
1021
  }
1019
- res.sendSuccess(findData);
1020
- } catch (e) {
1021
- logger.error({ functionName: 'fixtureVMListv1', error: e });
1022
- return res.sendError(e, 500);
1022
+ res.sendSuccess( findData );
1023
+ } catch ( e ) {
1024
+ logger.error( { functionName: 'fixtureVMListv1', error: e } );
1025
+ return res.sendError( e, 500 );
1023
1026
  }
1024
1027
  }
1025
- export async function updateFixtureStatus(req, res) {
1028
+ export async function updateFixtureStatus( req, res ) {
1026
1029
  try {
1027
1030
  let comments = {
1028
1031
  userId: req.user._id,
@@ -1032,152 +1035,152 @@ export async function updateFixtureStatus(req, res) {
1032
1035
  comment: req.body.comments,
1033
1036
  };
1034
1037
 
1035
- if (req.body.taskType.includes('fixture')) {
1038
+ if ( req.body.taskType.includes( 'fixture' ) ) {
1036
1039
  await planoTaskService.updateOnefilters(
1037
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1038
- {
1039
- $set: {
1040
- 'answers.$[ans].status': req.body.type,
1041
- 'answers.$[ans].userAction': req.body.userAction
1042
- }
1043
- },
1044
- [
1045
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1040
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1041
+ {
1042
+ $set: {
1043
+ 'answers.$[ans].status': req.body.type,
1044
+ 'answers.$[ans].userAction': req.body.userAction,
1045
+ },
1046
+ },
1047
+ [
1048
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1046
1049
 
1047
- ],
1050
+ ],
1048
1051
  );
1049
1052
  await planoTaskService.updateOnefilters(
1050
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1051
- {
1052
- $push: { 'answers.$[ans].comments': comments },
1053
- },
1054
- [
1055
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1056
- ]);
1053
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1054
+ {
1055
+ $push: { 'answers.$[ans].comments': comments },
1056
+ },
1057
+ [
1058
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1059
+ ] );
1057
1060
 
1058
- await planoTaskService.updateOne({ _id: req.body._id }, { approvalStatus: 'approved', taskType: 'initial' });
1061
+ await planoTaskService.updateOne( { _id: req.body._id }, { approvalStatus: 'approved', taskType: 'initial' } );
1059
1062
  let fixtureTask = await planoTaskService.find(
1060
- {
1061
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
1062
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
1063
- type: 'fixture',
1064
- },
1063
+ {
1064
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1065
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1066
+ type: 'fixture',
1067
+ },
1065
1068
  );
1066
- if (fixtureTask.length > 0) {
1067
- let allTaskDone = fixtureTask.filter((data) => !data?.answers?.[0]?.status || data?.answers?.[0]?.status == 'disagree');
1068
- if (allTaskDone.length === 0) {
1069
- await floorService.updateOne({ _id: new mongoose.Types.ObjectId(req.body.floorId) }, { planoProgress: 100 });
1069
+ if ( fixtureTask.length > 0 ) {
1070
+ let allTaskDone = fixtureTask.filter( ( data ) => !data?.answers?.[0]?.status || data?.answers?.[0]?.status == 'disagree' );
1071
+ if ( allTaskDone.length === 0 ) {
1072
+ await floorService.updateOne( { _id: new mongoose.Types.ObjectId( req.body.floorId ) }, { planoProgress: 100 } );
1070
1073
  }
1071
1074
  }
1072
1075
  } else {
1073
1076
  let updateResponse = await planoTaskService.updateOnefilters(
1074
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1075
- {
1076
- $set: { 'answers.$[ans].issues.$[iss].Details.$[det].status': req.body.type },
1077
- },
1078
- [
1079
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1080
- { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1081
- { 'det._id': new mongoose.Types.ObjectId(req.body.DetailsId) },
1082
-
1083
- ]);
1084
- if (updateResponse && updateResponse.answers.length > 0) {
1085
- let findissuse = updateResponse.answers[0].issues.filter((data) => data._id == req.body.issueId);
1086
- let findDetails = findissuse[0].Details.filter((det) => det.status === 'agree');
1087
- if (findissuse[0].Details.length === findDetails.length) {
1077
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1078
+ {
1079
+ $set: { 'answers.$[ans].issues.$[iss].Details.$[det].status': req.body.type },
1080
+ },
1081
+ [
1082
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1083
+ { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
1084
+ { 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
1085
+
1086
+ ] );
1087
+ if ( updateResponse && updateResponse.answers.length > 0 ) {
1088
+ let findissuse = updateResponse.answers[0].issues.filter( ( data ) => data._id == req.body.issueId );
1089
+ let findDetails = findissuse[0].Details.filter( ( det ) => det.status === 'agree' );
1090
+ if ( findissuse[0].Details.length === findDetails.length ) {
1088
1091
  await planoTaskService.updateOnefilters(
1089
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1090
- {
1091
- $set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
1092
- },
1093
- [
1094
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1095
- { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1096
- ]);
1092
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1093
+ {
1094
+ $set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
1095
+ },
1096
+ [
1097
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1098
+ { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
1099
+ ] );
1097
1100
  }
1098
- let findoneplanoData = await planoTaskService.findOne({ _id: new mongoose.Types.ObjectId(req.body._id) });
1099
- let totalApproved = findoneplanoData.answers[0].issues.filter((data) => data.status === 'pending');
1100
- if (totalApproved.length === 0) {
1101
+ let findoneplanoData = await planoTaskService.findOne( { _id: new mongoose.Types.ObjectId( req.body._id ) } );
1102
+ let totalApproved = findoneplanoData.answers[0].issues.filter( ( data ) => data.status === 'pending' );
1103
+ if ( totalApproved.length === 0 ) {
1101
1104
  await planoTaskService.updateOne(
1102
- {
1103
- _id: new mongoose.Types.ObjectId(req.body._id),
1104
- },
1105
- {
1106
- 'status': 'complete',
1107
- },
1108
- );
1109
- if (req.body.taskType === 'layout') {
1110
- await planoTaskService.updateMany(
1111
1105
  {
1112
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
1113
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
1114
- type: 'layout',
1106
+ _id: new mongoose.Types.ObjectId( req.body._id ),
1115
1107
  },
1116
1108
  {
1117
1109
  'status': 'complete',
1118
1110
  },
1111
+ );
1112
+ if ( req.body.taskType === 'layout' ) {
1113
+ await planoTaskService.updateMany(
1114
+ {
1115
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1116
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1117
+ type: 'layout',
1118
+ },
1119
+ {
1120
+ 'status': 'complete',
1121
+ },
1119
1122
  );
1120
1123
  }
1121
1124
  }
1122
1125
  }
1123
1126
 
1124
- if (req.body.taskType === 'layout') {
1127
+ if ( req.body.taskType === 'layout' ) {
1125
1128
  await planoTaskService.updateOnefilters(
1126
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1127
- {
1128
- $push: { 'answers.$[ans].issues.$[iss].Details.$[det].comments': comments },
1129
- },
1130
- [
1131
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1132
- { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1133
- { 'det._id': new mongoose.Types.ObjectId(req.body.DetailsId) },
1129
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1130
+ {
1131
+ $push: { 'answers.$[ans].issues.$[iss].Details.$[det].comments': comments },
1132
+ },
1133
+ [
1134
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1135
+ { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
1136
+ { 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
1134
1137
 
1135
- ]);
1138
+ ] );
1136
1139
  } else {
1137
1140
  await planoTaskService.updateOnefilters(
1138
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1139
- {
1140
- $push: { 'answers.$[ans].issues.$[iss].comments': comments },
1141
- },
1142
- [
1143
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1144
- { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1145
- ]);
1141
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1142
+ {
1143
+ $push: { 'answers.$[ans].issues.$[iss].comments': comments },
1144
+ },
1145
+ [
1146
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1147
+ { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
1148
+ ] );
1146
1149
  }
1147
1150
  let vmTask = await planoTaskService.find(
1148
- {
1149
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
1150
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
1151
- type: 'vm',
1152
- },
1151
+ {
1152
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1153
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1154
+ type: 'vm',
1155
+ },
1153
1156
 
1154
1157
  );
1155
- if (vmTask.length > 0) {
1156
- let allTaskDone = vmTask.filter((data) => data.status === 'incomplete');
1157
- if (allTaskDone.length === 0) {
1158
- await floorService.updateOne({ _id: new mongoose.Types.ObjectId(req.body.floorId) }, { planoProgress: 100 });
1158
+ if ( vmTask.length > 0 ) {
1159
+ let allTaskDone = vmTask.filter( ( data ) => data.status === 'incomplete' );
1160
+ if ( allTaskDone.length === 0 ) {
1161
+ await floorService.updateOne( { _id: new mongoose.Types.ObjectId( req.body.floorId ) }, { planoProgress: 100 } );
1159
1162
  }
1160
1163
  }
1161
1164
  }
1162
- res.sendSuccess('updated successfully');
1163
- } catch (e) {
1164
- logger.error({ functionName: 'updateFixtureStatus', error: e });
1165
- return res.sendError(e, 500);
1165
+ res.sendSuccess( 'updated successfully' );
1166
+ } catch ( e ) {
1167
+ logger.error( { functionName: 'updateFixtureStatus', error: e } );
1168
+ return res.sendError( e, 500 );
1166
1169
  }
1167
1170
  }
1168
1171
 
1169
- export async function updateApprovalStatus(req, res) {
1172
+ export async function updateApprovalStatus( req, res ) {
1170
1173
  try {
1171
1174
  await planoTaskService.updateOnefilters(
1172
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1173
- { $set: { approvalStatus: 'approved' } });
1174
- res.sendSuccess('updated successfully');
1175
- } catch (e) {
1176
- logger.error({ functionName: 'updateApprovalStatus', error: e });
1177
- return res.sendError(e, 500);
1175
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1176
+ { $set: { approvalStatus: 'approved' } } );
1177
+ res.sendSuccess( 'updated successfully' );
1178
+ } catch ( e ) {
1179
+ logger.error( { functionName: 'updateApprovalStatus', error: e } );
1180
+ return res.sendError( e, 500 );
1178
1181
  }
1179
1182
  }
1180
- export async function updateRolloutStatus(req, res) {
1183
+ export async function updateRolloutStatus( req, res ) {
1181
1184
  try {
1182
1185
  let comments = {
1183
1186
  userId: req.user._id,
@@ -1187,153 +1190,153 @@ export async function updateRolloutStatus(req, res) {
1187
1190
  comment: req.body.comments,
1188
1191
  };
1189
1192
 
1190
- if (req.body.issueId && req.body.DetailsId) {
1193
+ if ( req.body.issueId && req.body.DetailsId ) {
1191
1194
  let updateResponse = await planoTaskService.updateOnefilters(
1192
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1193
- {
1194
- $set: {
1195
- 'answers.$[ans].issues.$[iss].Details.$[det].status': req.body.type,
1196
- 'answers.$[ans].issues.$[iss].Details.$[det].adminStatus': req.body.type === 'agree' ? 'approved' : 'Unapproved',
1195
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1196
+ {
1197
+ $set: {
1198
+ 'answers.$[ans].issues.$[iss].Details.$[det].status': req.body.type,
1199
+ 'answers.$[ans].issues.$[iss].Details.$[det].adminStatus': req.body.type === 'agree' ? 'approved' : 'Unapproved',
1200
+ },
1197
1201
  },
1198
- },
1199
- [
1200
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1201
- { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1202
- { 'det._id': new mongoose.Types.ObjectId(req.body.DetailsId) },
1202
+ [
1203
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1204
+ { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
1205
+ { 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
1203
1206
 
1204
- ],
1207
+ ],
1205
1208
  );
1206
- if (updateResponse && updateResponse.answers.length > 0) {
1207
- let findissuse = updateResponse.answers[0].issues.filter((data) => data._id == req.body.issueId);
1208
- let findDetails = findissuse[0].Details.filter((det) => det.status === 'agree');
1209
- if (findissuse[0].Details.length === findDetails.length) {
1209
+ if ( updateResponse && updateResponse.answers.length > 0 ) {
1210
+ let findissuse = updateResponse.answers[0].issues.filter( ( data ) => data._id == req.body.issueId );
1211
+ let findDetails = findissuse[0].Details.filter( ( det ) => det.status === 'agree' );
1212
+ if ( findissuse[0].Details.length === findDetails.length ) {
1210
1213
  await planoTaskService.updateOnefilters(
1211
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1212
- {
1213
- $set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
1214
- },
1215
- [
1216
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1217
- { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1218
- ]);
1214
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1215
+ {
1216
+ $set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
1217
+ },
1218
+ [
1219
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1220
+ { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
1221
+ ] );
1219
1222
  }
1220
- let findoneplanoData = await planoTaskService.findOne({ _id: new mongoose.Types.ObjectId(req.body._id) });
1221
- let totalApproved = findoneplanoData.answers[0].issues.filter((data) => data.status === 'pending');
1222
- if (totalApproved.length === 0) {
1223
+ let findoneplanoData = await planoTaskService.findOne( { _id: new mongoose.Types.ObjectId( req.body._id ) } );
1224
+ let totalApproved = findoneplanoData.answers[0].issues.filter( ( data ) => data.status === 'pending' );
1225
+ if ( totalApproved.length === 0 ) {
1223
1226
  await planoTaskService.updateOne(
1224
- {
1225
- _id: new mongoose.Types.ObjectId(req.body._id),
1226
- },
1227
- {
1228
- 'status': 'complete',
1229
- 'approvalStatus': 'approved',
1230
- },
1227
+ {
1228
+ _id: new mongoose.Types.ObjectId( req.body._id ),
1229
+ },
1230
+ {
1231
+ 'status': 'complete',
1232
+ 'approvalStatus': 'approved',
1233
+ },
1231
1234
  );
1232
1235
  let data = {};
1233
- if (req.body.taskType == 'vmRollout') {
1236
+ if ( req.body.taskType == 'vmRollout' ) {
1234
1237
  data['isVmEdited'] = false;
1235
1238
  } else {
1236
1239
  data['isMerchEdited'] = false;
1237
1240
  }
1238
- await storeFixtureService.updateOne({ _id: updateResponse.fixtureId }, data);
1241
+ await storeFixtureService.updateOne( { _id: updateResponse.fixtureId }, data );
1239
1242
  }
1240
1243
  }
1241
1244
  await planoTaskService.updateOnefilters(
1242
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1243
- {
1244
- $push: { 'answers.$[ans].issues.$[iss].comments': comments },
1245
- },
1246
- [
1247
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1248
- { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1249
- ],
1245
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1246
+ {
1247
+ $push: { 'answers.$[ans].issues.$[iss].comments': comments },
1248
+ },
1249
+ [
1250
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1251
+ { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
1252
+ ],
1250
1253
  );
1251
1254
  } else {
1252
1255
  let updateResponse = await planoTaskService.updateOnefilters(
1253
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1254
- {
1255
- $set: {
1256
- 'answers.$[ans].status': req.body.type,
1256
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1257
+ {
1258
+ $set: {
1259
+ 'answers.$[ans].status': req.body.type,
1260
+ },
1257
1261
  },
1258
- },
1259
- [
1260
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1261
- ],
1262
+ [
1263
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1264
+ ],
1262
1265
  );
1263
1266
  await planoTaskService.updateOnefilters(
1264
- { _id: new mongoose.Types.ObjectId(req.body._id) },
1265
- {
1266
- $push: { 'answers.$[ans].comments': comments },
1267
- },
1268
- [
1269
- { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1270
- ],
1271
- );
1272
- if (req.body.type == 'agree') {
1273
- await planoTaskService.updateOne(
1274
- {
1275
- _id: new mongoose.Types.ObjectId(req.body._id),
1276
- },
1267
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
1277
1268
  {
1278
- 'approvalStatus': 'approved',
1269
+ $push: { 'answers.$[ans].comments': comments },
1279
1270
  },
1271
+ [
1272
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1273
+ ],
1274
+ );
1275
+ if ( req.body.type == 'agree' ) {
1276
+ await planoTaskService.updateOne(
1277
+ {
1278
+ _id: new mongoose.Types.ObjectId( req.body._id ),
1279
+ },
1280
+ {
1281
+ 'approvalStatus': 'approved',
1282
+ },
1280
1283
  );
1281
1284
  let data = {};
1282
- if (req.body.taskType == 'vmRollout') {
1285
+ if ( req.body.taskType == 'vmRollout' ) {
1283
1286
  data['isVmEdited'] = false;
1284
1287
  } else {
1285
1288
  data['isMerchEdited'] = false;
1286
1289
  }
1287
- await storeFixtureService.updateOne({ _id: updateResponse.fixtureId }, data);
1290
+ await storeFixtureService.updateOne( { _id: updateResponse.fixtureId }, data );
1288
1291
  }
1289
1292
  }
1290
1293
 
1291
- res.sendSuccess('updated successfully');
1292
- } catch (e) {
1293
- logger.error({ functionName: 'updateFixtureStatus', error: e });
1294
- return res.sendError(e, 500);
1294
+ res.sendSuccess( 'updated successfully' );
1295
+ } catch ( e ) {
1296
+ logger.error( { functionName: 'updateFixtureStatus', error: e } );
1297
+ return res.sendError( e, 500 );
1295
1298
  }
1296
1299
  }
1297
1300
 
1298
1301
 
1299
- export async function updateStoreFixture(req, res) {
1302
+ export async function updateStoreFixture( req, res ) {
1300
1303
  try {
1301
1304
  const { fixtureId, data } = req.body;
1302
1305
 
1303
1306
  let configId;
1304
1307
 
1305
- const currentFixture = await storeFixtureService.findOne({ _id: new mongoose.Types.ObjectId(fixtureId) });
1308
+ const currentFixture = await storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( fixtureId ) } );
1306
1309
  let currentFixtureDoc = currentFixture.toObject();
1307
- if (data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi') {
1308
- let shelfDetails = await fixtureShelfService.find({ fixtureId: fixtureId });
1309
- data.shelfConfig.forEach((ele) => {
1310
- let findShelfProduct = shelfDetails.find((shelf) => shelf.shelfNumber == ele.shelfNumber);
1311
- if (!ele?.zone) {
1310
+ if ( data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi' ) {
1311
+ let shelfDetails = await fixtureShelfService.find( { fixtureId: fixtureId } );
1312
+ data.shelfConfig.forEach( ( ele ) => {
1313
+ let findShelfProduct = shelfDetails.find( ( shelf ) => shelf.shelfNumber == ele.shelfNumber );
1314
+ if ( !ele?.zone ) {
1312
1315
  ele.zone = findShelfProduct?.zone ?? 'Bottom';
1313
1316
  }
1314
- if (!ele?.productBrandName) {
1317
+ if ( !ele?.productBrandName ) {
1315
1318
  ele.productBrandName = findShelfProduct?.productBrandName ?? [];
1316
1319
  }
1317
- if (!ele?.productCategory) {
1320
+ if ( !ele?.productCategory ) {
1318
1321
  ele.productCategory = findShelfProduct?.productCategory ?? [];
1319
1322
  }
1320
- if (!ele?.productSubCategory) {
1323
+ if ( !ele?.productSubCategory ) {
1321
1324
  ele.productSubCategory = findShelfProduct?.productSubCategory ?? [];
1322
1325
  }
1323
- });
1326
+ } );
1324
1327
  let vmConfig = [];
1325
- for (let vm of data.vmConfig) {
1326
- let checkvmType = await vmTypeService.findOne({ vmType: vm.vmType });
1327
- if (!checkvmType) {
1328
+ for ( let vm of data.vmConfig ) {
1329
+ let checkvmType = await vmTypeService.findOne( { vmType: vm.vmType } );
1330
+ if ( !checkvmType ) {
1328
1331
  let vmData = {
1329
1332
  vmType: vm.vmType,
1330
- imageUrls: [vm.vmImage],
1333
+ imageUrls: [ vm.vmImage ],
1331
1334
  clientId: '11',
1332
1335
  };
1333
- checkvmType = await vmTypeService.create(vmData);
1336
+ checkvmType = await vmTypeService.create( vmData );
1334
1337
  }
1335
- let vmDetails = await planoVmService.findOne({ ...(vm.vmName) ? { vmName: vm.vmName } : { _id: vm.vmId } });
1336
- if (!vmDetails) {
1338
+ let vmDetails = await planoVmService.findOne( { ...( vm.vmName ) ? { vmName: vm.vmName } : { _id: vm.vmId } } );
1339
+ if ( !vmDetails ) {
1337
1340
  let planovmData = {
1338
1341
  vmType: vm.vmType,
1339
1342
  vmName: vm.vmName,
@@ -1349,9 +1352,9 @@ export async function updateStoreFixture(req, res) {
1349
1352
  },
1350
1353
  vmImageUrl: vm.vmImage,
1351
1354
  };
1352
- vmDetails = await planoVmService.create(planovmData);
1355
+ vmDetails = await planoVmService.create( planovmData );
1353
1356
  }
1354
- vmConfig.push({ ...vm, vmId: vmDetails._id });
1357
+ vmConfig.push( { ...vm, vmId: vmDetails._id } );
1355
1358
  }
1356
1359
  data.vmConfig = vmConfig;
1357
1360
  let groupName = {
@@ -1360,12 +1363,12 @@ export async function updateStoreFixture(req, res) {
1360
1363
  'Vincent Chase': 'VC Eye',
1361
1364
  'OwnDays': 'OD Eye',
1362
1365
  };
1363
- let header = (data?.header?.label && data?.header?.label != 'Unknown') ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.header?.label;
1366
+ let header = ( data?.header?.label && data?.header?.label != 'Unknown' ) ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.header?.label;
1364
1367
  let mapKey = `${data.fixtureCategory}${currentFixtureDoc.fixtureWidth.value}${currentFixtureDoc.fixtureWidth.unit}${header}`;
1365
- mapKey += data.shelfConfig.map((ele) => `${ele.shelfNumber}=${ele.productBrandName.toString()}`).join('+');
1366
- data?.vmConfig?.forEach((ele) => {
1368
+ mapKey += data.shelfConfig.map( ( ele ) => `${ele.shelfNumber}=${ele.productBrandName.toString()}` ).join( '+' );
1369
+ data?.vmConfig?.forEach( ( ele ) => {
1367
1370
  mapKey += `${ele.vmName}${ele.startYPosition}${ele.endYPosition}${ele.xZone}${ele.yZone}`;
1368
- });
1371
+ } );
1369
1372
  let query = [
1370
1373
  {
1371
1374
  $addFields: {
@@ -1393,13 +1396,13 @@ export async function updateStoreFixture(req, res) {
1393
1396
  },
1394
1397
  },
1395
1398
  ];
1396
- let [fixturesubTemplate, fixtureMasterTemplate] = await Promise.all([
1397
- await fixtureConfigService.aggregate(query),
1398
- await fixtureConfigService.aggregate(masterQuery),
1399
- ]);
1399
+ let [ fixturesubTemplate, fixtureMasterTemplate ] = await Promise.all( [
1400
+ await fixtureConfigService.aggregate( query ),
1401
+ await fixtureConfigService.aggregate( masterQuery ),
1402
+ ] );
1400
1403
 
1401
- if (!fixturesubTemplate.length) {
1402
- let tempGroupName = (data?.header?.label && data?.header?.label != 'Unknown') ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.templateGroupName;
1404
+ if ( !fixturesubTemplate.length ) {
1405
+ let tempGroupName = ( data?.header?.label && data?.header?.label != 'Unknown' ) ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.templateGroupName;
1403
1406
  let templateIndex = 1;
1404
1407
  let templateData = {
1405
1408
  ...currentFixtureDoc,
@@ -1412,20 +1415,20 @@ export async function updateStoreFixture(req, res) {
1412
1415
  };
1413
1416
  delete templateData._id;
1414
1417
  delete templateData.masterTemplateId;
1415
- if (!fixtureMasterTemplate.length) {
1418
+ if ( !fixtureMasterTemplate.length ) {
1416
1419
  let masterTemplate = {
1417
1420
  ...templateData,
1418
1421
  fixtureName: `${templateData.header.label}-${templateData.fixtureCategory}`,
1419
1422
  templateType: 'master',
1420
1423
  crestMapKey: masterMapKey,
1421
1424
  };
1422
- fixtureMasterTemplate = await fixtureConfigService.create(masterTemplate);
1425
+ fixtureMasterTemplate = await fixtureConfigService.create( masterTemplate );
1423
1426
  } else {
1424
1427
  fixtureMasterTemplate = fixtureMasterTemplate[0];
1425
1428
  let tempQuery = [
1426
1429
  {
1427
1430
  $match: {
1428
- masterTemplateId: new mongoose.Types.ObjectId(fixtureMasterTemplate._id),
1431
+ masterTemplateId: new mongoose.Types.ObjectId( fixtureMasterTemplate._id ),
1429
1432
  },
1430
1433
  },
1431
1434
  {
@@ -1435,16 +1438,16 @@ export async function updateStoreFixture(req, res) {
1435
1438
  },
1436
1439
  },
1437
1440
  ];
1438
- let getMaxTemp = await fixtureConfigService.aggregate(tempQuery);
1441
+ let getMaxTemp = await fixtureConfigService.aggregate( tempQuery );
1439
1442
  templateIndex = getMaxTemp?.[0]?.tempId + 1;
1440
1443
  }
1441
- templateData.fixtureName = `${header}-${data.fixtureCategory}-variant-${templateIndex}`,
1442
- templateData.templateType = 'sub';
1444
+ templateData.fixtureName= `${header}-${data.fixtureCategory}-variant-${templateIndex}`,
1445
+ templateData.templateType = 'sub';
1443
1446
  templateData.masterTemplateId = fixtureMasterTemplate._id;
1444
1447
  templateData.templateIndex = templateIndex;
1445
1448
  templateData.createdAt = new Date();
1446
1449
  templateData.updatedAt = new Date();
1447
- let subTemplate = await fixtureConfigService.create(templateData);
1450
+ let subTemplate = await fixtureConfigService.create( templateData );
1448
1451
  configId = subTemplate._id;
1449
1452
 
1450
1453
  data.fixtureConfigId = subTemplate._id;
@@ -1460,72 +1463,72 @@ export async function updateStoreFixture(req, res) {
1460
1463
 
1461
1464
  let fixtureCapacity = 0;
1462
1465
 
1463
- data.shelfConfig.forEach((shelf) => {
1466
+ data.shelfConfig.forEach( ( shelf ) => {
1464
1467
  const { productBrandName: brand, productCategory: category, productSubCategory: subCategory } = shelf;
1465
1468
 
1466
- if (typeof shelf?.productPerShelf === 'number') {
1467
- if (shelf?.shelfType === 'shelf') {
1469
+ if ( typeof shelf?.productPerShelf === 'number' ) {
1470
+ if ( shelf?.shelfType === 'shelf' ) {
1468
1471
  fixtureCapacity += shelf.productPerShelf;
1469
1472
  }
1470
1473
 
1471
- if (shelf?.shelfType === 'tray') {
1472
- fixtureCapacity += (shelf?.productPerShelf * shelf?.trayRows);
1474
+ if ( shelf?.shelfType === 'tray' ) {
1475
+ fixtureCapacity += ( shelf?.productPerShelf * shelf?.trayRows );
1473
1476
  }
1474
1477
  }
1475
1478
 
1476
- if (Array.isArray(brand)) {
1477
- brand.forEach((b) => productBrandName.add(b));
1479
+ if ( Array.isArray( brand ) ) {
1480
+ brand.forEach( ( b ) => productBrandName.add( b ) );
1478
1481
  }
1479
1482
 
1480
- if (Array.isArray(category)) {
1481
- category.forEach((c) => productCategory.add(c));
1483
+ if ( Array.isArray( category ) ) {
1484
+ category.forEach( ( c ) => productCategory.add( c ) );
1482
1485
  }
1483
1486
 
1484
- if (Array.isArray(subCategory)) {
1485
- subCategory.forEach((s) => productSubCategory.add(s));
1487
+ if ( Array.isArray( subCategory ) ) {
1488
+ subCategory.forEach( ( s ) => productSubCategory.add( s ) );
1486
1489
  }
1487
- });
1490
+ } );
1488
1491
 
1489
1492
 
1490
- if (data?.fixtureConfigId && currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId) {
1491
- const newTemplate = await fixtureConfigService.findOne({ _id: data.fixtureConfigId });
1493
+ if ( data?.fixtureConfigId && currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId ) {
1494
+ const newTemplate = await fixtureConfigService.findOne( { _id: data.fixtureConfigId } );
1492
1495
  currentFixtureDoc = {
1493
1496
  ...currentFixtureDoc,
1494
1497
  ...newTemplate.toObject(),
1495
1498
  fixtureConfigId: newTemplate.toObject()._id,
1496
1499
  fixtureCapacity: fixtureCapacity,
1497
- productBrandName: [...productBrandName],
1498
- productCategory: [...productCategory],
1499
- productSubCategory: [...productSubCategory],
1500
+ productBrandName: [ ...productBrandName ],
1501
+ productCategory: [ ...productCategory ],
1502
+ productSubCategory: [ ...productSubCategory ],
1500
1503
  };
1501
1504
  } else {
1502
1505
  currentFixtureDoc = {
1503
1506
  ...currentFixtureDoc,
1504
1507
  ...data,
1505
1508
  fixtureCapacity: fixtureCapacity,
1506
- productBrandName: [...productBrandName],
1507
- productCategory: [...productCategory],
1508
- productSubCategory: [...productSubCategory],
1509
+ productBrandName: [ ...productBrandName ],
1510
+ productCategory: [ ...productCategory ],
1511
+ productSubCategory: [ ...productSubCategory ],
1509
1512
  };
1510
1513
  }
1511
1514
 
1512
- if (data.productResolutionLevel == 'L1') {
1513
- currentFixtureDoc.productBrandName = [...new Set(data.productBrandName.map((ele) => ele))];
1514
- currentFixtureDoc.productCategory = [...new Set(data.productCategory.map((ele) => ele))];
1515
- currentFixtureDoc.productSubCategory = [...new Set(data.productSubCategory.map((ele) => ele))];
1515
+ if ( data.productResolutionLevel == 'L1' ) {
1516
+ currentFixtureDoc.productBrandName = [ ...new Set( data.productBrandName.map( ( ele ) => ele ) ) ];
1517
+ currentFixtureDoc.productCategory = [ ...new Set( data.productCategory.map( ( ele ) => ele ) ) ];
1518
+ currentFixtureDoc.productSubCategory = [ ...new Set( data.productSubCategory.map( ( ele ) => ele ) ) ];
1516
1519
  }
1517
1520
 
1518
1521
 
1519
1522
  delete currentFixtureDoc._id;
1520
1523
 
1521
1524
 
1522
- await storeFixtureService.updateOne({ _id: new mongoose.Types.ObjectId(fixtureId) }, currentFixtureDoc);
1525
+ await storeFixtureService.updateOne( { _id: new mongoose.Types.ObjectId( fixtureId ) }, currentFixtureDoc );
1523
1526
 
1524
- if (data?.shelfConfig?.length) {
1525
- await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixtureId) });
1527
+ if ( data?.shelfConfig?.length ) {
1528
+ await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
1526
1529
 
1527
1530
 
1528
- data.shelfConfig.forEach(async (shelf) => {
1531
+ data.shelfConfig.forEach( async ( shelf ) => {
1529
1532
  delete shelf?._id;
1530
1533
  const additionalMeta = {
1531
1534
  clientId: currentFixture.clientId,
@@ -1536,12 +1539,12 @@ export async function updateStoreFixture(req, res) {
1536
1539
  fixtureId: currentFixture._id,
1537
1540
  };
1538
1541
 
1539
- await fixtureShelfService.create({ ...additionalMeta, ...shelf });
1540
- });
1542
+ await fixtureShelfService.create( { ...additionalMeta, ...shelf } );
1543
+ } );
1541
1544
  }
1542
- await planoService.updateOne({ _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } });
1545
+ await planoService.updateOne( { _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } } );
1543
1546
 
1544
- if (data?.userAction === 'editWithAi' || data?.userAction === 'editWithPlano') {
1547
+ if ( data?.userAction === 'editWithAi' || data?.userAction === 'editWithPlano' ) {
1545
1548
  let comments = {
1546
1549
  userId: req.user._id,
1547
1550
  userName: req.user.userName,
@@ -1549,151 +1552,149 @@ export async function updateStoreFixture(req, res) {
1549
1552
  responsetype: 'agree',
1550
1553
  comment: '',
1551
1554
  };
1552
- await planoTaskService.updateOne({ planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved', 'answers.0.userAction': data.userAction });
1555
+ await planoTaskService.updateOne( { planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved', 'answers.0.userAction': data.userAction } );
1553
1556
 
1554
1557
  await planoTaskService.updateOnefilters(
1555
- { planoId: new mongoose.Types.ObjectId(currentFixture.planoId), floorId: new mongoose.Types.ObjectId(currentFixture.floorId), fixtureId: new mongoose.Types.ObjectId(currentFixture._id) },
1556
- {
1557
- $push: { 'answers.0.comments': comments },
1558
- },
1558
+ { planoId: new mongoose.Types.ObjectId( currentFixture.planoId ), floorId: new mongoose.Types.ObjectId( currentFixture.floorId ), fixtureId: new mongoose.Types.ObjectId( currentFixture._id ) },
1559
+ {
1560
+ $push: { 'answers.0.comments': comments },
1561
+ },
1559
1562
  );
1560
-
1561
1563
  }
1562
1564
 
1563
- if (data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi') {
1564
- const op_id = `${data?.storeName}_${data?.storeDate}_${data?._id}`
1565
- await updateAIFeedbackInOpenSearch(data, op_id);
1565
+ if ( data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi' ) {
1566
+ const op_id = `${data?.storeName}_${data?.storeDate}_${data?._id}`;
1567
+ await updateAIFeedbackInOpenSearch( data, op_id );
1566
1568
  }
1567
1569
 
1568
1570
  // if ( req.body?.editMode ) {
1569
1571
  // await floorService.updateOne( { _id: new mongoose.Types.ObjectId( currentFixture.floorId ) }, { isEdited: true } );
1570
1572
  // }
1571
- res.sendSuccess({ message: 'Updated Successfully', ...(configId && { id: configId }) });
1572
- } catch (e) {
1573
- logger.error({ functionName: 'updateStoreFixture', error: e });
1574
- return res.sendError(e, 500);
1573
+ res.sendSuccess( { message: 'Updated Successfully', ...( configId && { id: configId } ) } );
1574
+ } catch ( e ) {
1575
+ logger.error( { functionName: 'updateStoreFixture', error: e } );
1576
+ return res.sendError( e, 500 );
1575
1577
  }
1576
1578
  }
1577
1579
 
1578
- const updateAIFeedbackInOpenSearch = async (fixtureData, id) => {
1579
-
1580
+ const updateAIFeedbackInOpenSearch = async ( fixtureData, id ) => {
1580
1581
  try {
1581
- let openSearchDetails = await getOpenSearchById(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id);
1582
- if (openSearchDetails && openSearchDetails.statusCode == 200 && openSearchDetails?.body?._source) {
1583
-
1582
+ let openSearchDetails = await getOpenSearchById( JSON.parse( process.env.OPENSEARCH ).planoAIValidation, id );
1583
+ if ( openSearchDetails && openSearchDetails.statusCode == 200 && openSearchDetails?.body?._source ) {
1584
1584
  const doc = {
1585
- "fixtureId": fixtureData._id,
1586
- "fixtureCapacity": fixtureData.fixtureCapacity,
1587
- "fixtureType": fixtureData.fixtureType,
1588
- "fixtureCategory": fixtureData.fixtureCategory,
1589
- "header": {
1590
- "label": fixtureData.header.label,
1585
+ 'fixtureId': fixtureData._id,
1586
+ 'fixtureCapacity': fixtureData.fixtureCapacity,
1587
+ 'fixtureType': fixtureData.fixtureType,
1588
+ 'fixtureCategory': fixtureData.fixtureCategory,
1589
+ 'header': {
1590
+ 'label': fixtureData.header.label,
1591
1591
  },
1592
- "vmConfig": fixtureData?.vmConfig.map(vm => {
1592
+ 'vmConfig': fixtureData?.vmConfig.map( ( vm ) => {
1593
1593
  return {
1594
- "vmType": vm.vmType,
1595
- "startYPosition": vm.startYPosition,
1596
- "endYPosition": vm.endYPosition,
1597
- "xZone": vm.xZone,
1598
- "yZone": vm.yZone,
1599
- "vmImage": vm.vmImage,
1600
- "vmName": vm.vmName,
1601
- }
1602
- }) ?? [
1594
+ 'vmType': vm.vmType,
1595
+ 'startYPosition': vm.startYPosition,
1596
+ 'endYPosition': vm.endYPosition,
1597
+ 'xZone': vm.xZone,
1598
+ 'yZone': vm.yZone,
1599
+ 'vmImage': vm.vmImage,
1600
+ 'vmName': vm.vmName,
1601
+ };
1602
+ } ) ?? [
1603
1603
 
1604
- ],
1605
- "shelfConfig": fixtureData?.shelfConfig.map(s => {
1604
+ ],
1605
+ 'shelfConfig': fixtureData?.shelfConfig.map( ( s ) => {
1606
1606
  return {
1607
- "shelfNumber": s.shelfNumber,
1608
- "shelfType": s.shelfType,
1609
- "productPerShelf": s.productPerShelf,
1610
- "trayRows": s.trayRows
1611
- }
1612
- }) ?? [],
1613
- "fixtureImage": fixtureData.fixtureImage,
1614
- "storeDate": fixtureData.storeDate
1615
- }
1607
+ 'shelfNumber': s.shelfNumber,
1608
+ 'shelfType': s.shelfType,
1609
+ 'productPerShelf': s.productPerShelf,
1610
+ 'trayRows': s.trayRows,
1611
+ };
1612
+ } ) ?? [],
1613
+ 'fixtureImage': fixtureData.fixtureImage,
1614
+ 'storeDate': fixtureData.storeDate,
1615
+ };
1616
1616
 
1617
1617
  const document = {
1618
1618
  doc: doc,
1619
1619
  };
1620
1620
 
1621
- let updateResult = await updateOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id, document);
1621
+ let updateResult = await updateOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoAIValidation, id, document );
1622
1622
 
1623
- if (updateResult?.statusCode == 200) {
1623
+ if ( updateResult?.statusCode == 200 ) {
1624
1624
  return true;
1625
1625
  }
1626
- return false
1626
+ return false;
1627
1627
  } else {
1628
- return false
1628
+ return false;
1629
1629
  }
1630
- } catch (e) {
1631
- logger.error({ error: e, function: 'updateAIFeedbackInOpenSearch' });
1632
- return false
1630
+ } catch ( e ) {
1631
+ logger.error( { error: e, function: 'updateAIFeedbackInOpenSearch' } );
1632
+ return false;
1633
1633
  }
1634
1634
  };
1635
1635
 
1636
- export async function updateredostatus(req, res) {
1636
+ export async function updateredostatus( req, res ) {
1637
1637
  try {
1638
- if (req.body.type === 'layout') {
1638
+ if ( req.body.type === 'layout' ) {
1639
1639
  await planoTaskService.updateOne(
1640
- {
1641
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
1642
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
1643
- type: req.body.type,
1644
- },
1645
- {
1646
- 'answers.$[].issues.$[].status': 'completed',
1647
- 'answers.$[].issues.$[].Details.$[].status': 'agree',
1648
- 'status': 'complete',
1649
- },
1640
+ {
1641
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1642
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1643
+ type: req.body.type,
1644
+ },
1645
+ {
1646
+ 'answers.$[].issues.$[].status': 'completed',
1647
+ 'answers.$[].issues.$[].Details.$[].status': 'agree',
1648
+ 'status': 'complete',
1649
+ },
1650
1650
  );
1651
1651
  } else {
1652
1652
  await planoTaskService.updateOne(
1653
- {
1654
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
1655
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
1656
- fixtureId: new mongoose.Types.ObjectId(req.body.fixtureId),
1657
- type: req.body.type,
1658
- },
1659
- {
1660
- 'answers.$[].issues.$[].status': 'completed',
1661
- 'answers.$[].issues.$[].Details.$[].status': 'agree',
1662
- 'status': 'complete',
1663
- },
1653
+ {
1654
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1655
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1656
+ fixtureId: new mongoose.Types.ObjectId( req.body.fixtureId ),
1657
+ type: req.body.type,
1658
+ },
1659
+ {
1660
+ 'answers.$[].issues.$[].status': 'completed',
1661
+ 'answers.$[].issues.$[].Details.$[].status': 'agree',
1662
+ 'status': 'complete',
1663
+ },
1664
1664
  );
1665
1665
  }
1666
- res.sendSuccess('updated successfully');
1667
- } catch (e) {
1668
- logger.error({ functionName: 'updateredostatus', error: e });
1669
- return res.sendError(e, 500);
1666
+ res.sendSuccess( 'updated successfully' );
1667
+ } catch ( e ) {
1668
+ logger.error( { functionName: 'updateredostatus', error: e } );
1669
+ return res.sendError( e, 500 );
1670
1670
  }
1671
1671
  }
1672
1672
 
1673
1673
 
1674
- export async function updateGlobalComment(req, res) {
1674
+ export async function updateGlobalComment( req, res ) {
1675
1675
  try {
1676
1676
  let payload = {
1677
1677
  userId: req.user._id,
1678
1678
  userName: req.user.userName,
1679
1679
  comment: req.body.comment,
1680
1680
  responsetype: req.body.responsetype,
1681
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
1682
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
1681
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1682
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1683
1683
  taskType: req.body.taskType,
1684
1684
  clientId: req.body.clientId,
1685
1685
  taskId: req.body.taskId,
1686
1686
  };
1687
- await planoGlobalCommentService.create(payload);
1688
- await insertOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoglobalcomments, payload);
1687
+ await planoGlobalCommentService.create( payload );
1688
+ await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoglobalcomments, payload );
1689
1689
 
1690
- res.sendSuccess('updated successfully');
1691
- } catch (e) {
1692
- logger.error({ functionName: 'updateGlobalComment', error: e });
1693
- return res.sendError(e, 500);
1690
+ res.sendSuccess( 'updated successfully' );
1691
+ } catch ( e ) {
1692
+ logger.error( { functionName: 'updateGlobalComment', error: e } );
1693
+ return res.sendError( e, 500 );
1694
1694
  }
1695
1695
  }
1696
- export async function getGlobalComment(req, res) {
1696
+
1697
+ export async function getGlobalComment( req, res ) {
1697
1698
  try {
1698
1699
  // let layoutComment = await planoGlobalCommentService.find( {
1699
1700
  // planoId: new mongoose.Types.ObjectId( req.body.planoId ),
@@ -1702,147 +1703,304 @@ export async function getGlobalComment(req, res) {
1702
1703
  // } );
1703
1704
 
1704
1705
  let taskId = [];
1705
- if (req.body?.taskId) {
1706
- taskId.push(new mongoose.Types.ObjectId(req.body.taskId));
1706
+ if ( req.body?.taskId ) {
1707
+ taskId.push( new mongoose.Types.ObjectId( req.body.taskId ) );
1707
1708
  }
1708
1709
 
1709
- if (req.body?.refTaskId) {
1710
- taskId.push(new mongoose.Types.ObjectId(req.body.refTaskId));
1710
+ if ( req.body?.refTaskId ) {
1711
+ taskId.push( new mongoose.Types.ObjectId( req.body.refTaskId ) );
1711
1712
  }
1712
1713
 
1713
- let layoutComment = await planoGlobalCommentService.find({
1714
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
1715
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
1716
- ...(taskId.length && { taskId: { $in: taskId } }),
1714
+ let layoutComment = await planoGlobalCommentService.find( {
1715
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1716
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1717
+ ...( taskId.length && { taskId: { $in: taskId } } ),
1717
1718
  taskType: req.body.taskType,
1718
- });
1719
+ } );
1719
1720
 
1720
- res.sendSuccess(layoutComment);
1721
- } catch (e) {
1722
- logger.error({ functionName: 'getGlobalComment', error: e });
1723
- return res.sendError(e, 500);
1721
+ res.sendSuccess( layoutComment );
1722
+ } catch ( e ) {
1723
+ logger.error( { functionName: 'getGlobalComment', error: e } );
1724
+ return res.sendError( e, 500 );
1724
1725
  }
1725
1726
  }
1726
1727
 
1727
- export async function getAllPlanoRevisions(req, res) {
1728
+ export async function getAllPlanoRevisions( req, res ) {
1728
1729
  try {
1729
- const { clientId } = req.body;
1730
+ const { planoId, floorId, storeId } = req.body;
1730
1731
 
1731
- if (!clientId) {
1732
- return res.sendError('Client Id is required', 400);
1732
+ if ( !storeId || !planoId || !floorId ) {
1733
+ return res.sendError( 'Required field is missing', 400 );
1733
1734
  }
1734
1735
 
1735
- const revisions = await planoRevisionService.find(
1736
- { clientId },
1737
- { storeName: 1, storeId: 1, planoId: 1, floorId: 1, createdAt: 1 },
1738
- );
1736
+ let query = [
1737
+ {
1738
+ $match: {
1739
+ storeId: storeId,
1740
+ planoId: new mongoose.Types.ObjectId( planoId ),
1741
+ floorId: new mongoose.Types.ObjectId( floorId ),
1742
+ },
1743
+ },
1744
+ {
1745
+ $sort: { _id: -1 },
1746
+ },
1747
+ {
1748
+ $limit: 5,
1749
+ },
1750
+ {
1751
+ $sort: { _id: 1 },
1752
+ },
1753
+ ];
1754
+
1755
+ const revisions = await planoRevisionService.aggregate( query );
1739
1756
 
1740
- res.sendSuccess(revisions);
1741
- } catch (e) {
1742
- logger.error({ functionName: 'getAllPlanoRevisions', error: e });
1743
- res.sendError('Failed to fetch plano revisions', 500);
1757
+ res.sendSuccess( revisions );
1758
+ } catch ( e ) {
1759
+ console.log( e );
1760
+ logger.error( { functionName: 'getAllPlanoRevisions', error: e } );
1761
+ res.sendError( 'Failed to fetch plano revisions', 500 );
1744
1762
  }
1745
1763
  }
1746
1764
 
1747
- export async function createPlanoRevision(req, res) {
1765
+ export async function createPlanoRevision( req, res ) {
1748
1766
  try {
1749
- const { storeName, storeId, clientId, planoId, floorId, floorData } = req.body;
1767
+ let { storeName, storeId, clientId, planoId, floorId, floorData } = req.body;
1750
1768
 
1751
- if (!storeName || !storeId || !clientId || !planoId || !floorId || !floorData) {
1752
- return res.sendError('Missing required fields', 400);
1769
+ if ( !storeName || !storeId || !clientId || !planoId || !floorId || !floorData ) {
1770
+ return res.sendError( 'Missing required fields', 400 );
1753
1771
  }
1772
+ let planoProductCount = 0;
1773
+ floorData.layoutPolygon.forEach( ( poly ) => {
1774
+ poly.fixtures.forEach( ( fixt ) => {
1775
+ planoProductCount += fixt.fixtureCapacity;
1776
+ } );
1777
+ } );
1754
1778
 
1755
- const newRevision = await planoRevisionService.create({
1756
- storeName,
1757
- storeId,
1758
- clientId,
1759
- planoId,
1760
- floorId,
1761
- floorData,
1762
- });
1763
-
1764
- res.sendSuccess(newRevision);
1765
- } catch (e) {
1766
- logger.error({ functionName: 'createPlanoRevision', error: e });
1767
- res.sendError('Failed to create plano revision', 500);
1779
+ floorData.centerFixture.forEach( ( fixt ) => {
1780
+ planoProductCount += fixt.fixtureCapacity;
1781
+ } );
1782
+
1783
+ floorData = { ...floorData, planoProductCount };
1784
+
1785
+ const data = {
1786
+ storeName: storeName,
1787
+ storeId: storeId,
1788
+ clientId: clientId,
1789
+ planoId: planoId,
1790
+ productResolutionLevel: req.body.productResolutionLevel,
1791
+ scanType: req.body.scanType,
1792
+ createdByName: req.user.userName,
1793
+ createdByEmail: req.user.email,
1794
+ createdBy: req.user._id,
1795
+ layoutName: req.body.layoutName,
1796
+ floorId: floorId,
1797
+ floorData: floorData,
1798
+ };
1799
+
1800
+ await planoRevisionService.create( data );
1801
+
1802
+ await storeBuilderService.updateOne( { _id: floorId }, { ...( req.body.type == 'rollout' ) ? { rolloutStatus: true } : { verificationStatus: true } } );
1803
+
1804
+ res.sendSuccess( 'Plano published successfully' );
1805
+ } catch ( e ) {
1806
+ logger.error( { functionName: 'createPlanoRevision', error: e } );
1807
+ res.sendError( 'Failed to create plano revision', 500 );
1768
1808
  }
1769
1809
  }
1770
1810
 
1771
- export async function getPlanoRevisionById(req, res) {
1811
+ export async function getPlanoRevisionById( req, res ) {
1772
1812
  try {
1773
- const { id } = req.params;
1813
+ let { clientId, planoId } = req.body;
1774
1814
 
1775
- if (!id) {
1776
- return res.sendError('Revision ID is required', 400);
1815
+ if ( req.body?.id ) {
1816
+ const planoDetails = await planoService.findOne( { ...( !mongoose.Types.ObjectId.isValid( req.body?.id ) && { storeId: req.body.id } ), ...( mongoose.Types.ObjectId.isValid( req.body?.id ) && { _id: req.body.id } ) }, { _id: 1, clientId: 1 } );
1817
+ if ( !planoDetails ) {
1818
+ return res.sendError( 'No data found', 204 );
1819
+ }
1820
+ planoId = planoDetails._id;
1821
+ clientId = planoDetails.clientId;
1777
1822
  }
1778
1823
 
1779
- const revision = await planoRevisionService.findOne(
1780
- { _id: id },
1781
- );
1782
-
1783
- if (!revision) {
1784
- return res.sendError('Plano revision not found', 404);
1824
+ if ( !clientId || !planoId ) {
1825
+ return res.sendError( 'Required field is missing', 400 );
1785
1826
  }
1786
1827
 
1787
- res.sendSuccess(revision);
1788
- } catch (e) {
1789
- logger.error({ functionName: 'getPlanoRevisionById', error: e });
1790
- res.sendError('Failed to fetch plano revision', 500);
1828
+ let query = [
1829
+ {
1830
+ $match: {
1831
+ planoId: new mongoose.Types.ObjectId( planoId ),
1832
+ clientId: clientId,
1833
+ },
1834
+ },
1835
+ {
1836
+ $sort: { _id: -1 },
1837
+ },
1838
+ {
1839
+ $group: {
1840
+ _id: { plano: '$planoId', floor: '$floorId' },
1841
+ storeName: { $first: '$storeName' },
1842
+ storeId: { $first: '$storeId' },
1843
+ productResolutionLevel: { $first: '$productResolutionLevel' },
1844
+ scanType: { $first: '$scanType' },
1845
+ layoutName: { $first: '$layoutName' },
1846
+ floorData: { $first: '$floorData' },
1847
+ floorData: { $first: '$floorData' },
1848
+ revisionId: { $first: '$_id' },
1849
+ },
1850
+ },
1851
+ {
1852
+ $group: {
1853
+ _id: '$_id.plano',
1854
+ storeName: { $first: '$storeName' },
1855
+ storeId: { $first: '$storeId' },
1856
+ productResolutionLevel: { $first: '$productResolutionLevel' },
1857
+ scanType: { $first: '$scanType' },
1858
+ layoutName: { $first: '$layoutName' },
1859
+ floors: { $push: '$floorData' },
1860
+ revisionId: { $first: '$revisionId' },
1861
+ },
1862
+ },
1863
+ {
1864
+ $limit: 1,
1865
+ },
1866
+ ];
1867
+
1868
+ let revisions = await planoRevisionService.aggregate( query );
1869
+ if ( !revisions.length ) {
1870
+ return res.sendError( 'No data found', 204 );
1871
+ }
1872
+ let currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
1873
+ revisions[0].floors = await Promise.all( revisions?.[0]?.floors.map( async ( floor ) => {
1874
+ floor.layoutPolygon = await Promise.all( floor.layoutPolygon.map( async ( poly ) => {
1875
+ poly.fixtures = await Promise.all( poly.fixtures.map( async ( fixture ) => {
1876
+ fixture.shelfConfig = await Promise.all( fixture.shelfConfig.map( async ( shelf ) => {
1877
+ const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf._id, type: 'product' }, { _id: 1 } );
1878
+ let productIdList = productDetails.map( ( ele ) => ele._id );
1879
+ let complianceQuery = [
1880
+ {
1881
+ $match: {
1882
+ fixtureId: fixture._id,
1883
+ shelfId: shelf._id,
1884
+ date: currentDate,
1885
+ planoMappingId: { $in: productIdList },
1886
+ },
1887
+ },
1888
+ {
1889
+ $group: {
1890
+ _id: '$createdAt',
1891
+ status: { $push: '$compliance' },
1892
+ },
1893
+ },
1894
+ {
1895
+ $sort: { _id: -1 },
1896
+ },
1897
+ {
1898
+ $limit: 1,
1899
+ },
1900
+ ];
1901
+ let complianceStatus = await planoComplianceService.aggregate( complianceQuery );
1902
+ shelf.compliance = complianceStatus?.[0]?.status.length ? ( ( complianceStatus?.[0]?.status?.length != shelf.productPerShelf ) || complianceStatus?.[0]?.status?.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
1903
+ return shelf;
1904
+ } ) );
1905
+ return fixture;
1906
+ } ) );
1907
+ return poly;
1908
+ } ) );
1909
+ floor.centerFixture = await Promise.all( floor.centerFixture.map( async ( fixture ) => {
1910
+ fixture.shelfConfig = await Promise.all( fixture.shelfConfig.map( async ( shelf ) => {
1911
+ const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf._id, type: 'product' }, { _id: 1 } );
1912
+ let productIdList = productDetails.map( ( ele ) => ele._id );
1913
+ let complianceQuery = [
1914
+ {
1915
+ $match: {
1916
+ fixtureId: fixture._id,
1917
+ shelfId: shelf._id,
1918
+ date: currentDate,
1919
+ planoMappingId: { $in: productIdList },
1920
+ },
1921
+ },
1922
+ {
1923
+ $group: {
1924
+ _id: '$createdAt',
1925
+ status: { $push: '$compliance' },
1926
+ },
1927
+ },
1928
+ {
1929
+ $sort: { _id: -1 },
1930
+ },
1931
+ {
1932
+ $limit: 1,
1933
+ },
1934
+ ];
1935
+ let complianceStatus = await planoComplianceService.aggregate( complianceQuery );
1936
+ shelf.compliance = complianceStatus?.[0]?.status.length ? ( ( complianceStatus?.[0]?.status?.length != shelf.productPerShelf ) || complianceStatus?.[0]?.status?.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
1937
+ return shelf;
1938
+ } ) );
1939
+ return fixture;
1940
+ } ) );
1941
+ return floor;
1942
+ } ) );
1943
+
1944
+ res.sendSuccess( revisions );
1945
+ } catch ( e ) {
1946
+ logger.error( { functionName: 'getPlanoRevisionById', error: e } );
1947
+ res.sendError( 'Failed to fetch plano revisions', 500 );
1791
1948
  }
1792
1949
  }
1793
- export async function getRolloutFeedback(req, res) {
1950
+
1951
+ export async function getRolloutFeedback( req, res ) {
1794
1952
  try {
1795
- const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['merchRollout', 'vmRollout'];
1953
+ const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'merchRollout', 'vmRollout' ];
1796
1954
  const filterByStatus = req.body.filterByStatus || [];
1797
1955
  const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
1798
1956
  const resultMap = {};
1799
1957
  const commentMap = {};
1800
- if (req.body.redo) {
1801
- let taskDetails = await planoTaskService.findOne({ taskId: req.body.taskId, fixtureId: req.body.fixtureId });
1802
- if (!taskDetails) {
1958
+ if ( req.body.redo ) {
1959
+ let taskDetails = await planoTaskService.findOne( { taskId: req.body.taskId, fixtureId: req.body.fixtureId } );
1960
+ if ( !taskDetails ) {
1803
1961
  req.body.taskId = req.body.refTaskId;
1804
1962
  }
1805
1963
  }
1806
1964
  await Promise.all(
1807
- taskTypes.map(async (type, index) => {
1808
- const pipeline = buildPipelineByType(type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask, req.body.taskId);
1809
-
1810
- let data = await planoTaskService.aggregate(pipeline);
1811
- if (filterByApprovalStatus && filterByApprovalStatus !== '') {
1812
- data.forEach((element) => {
1813
- element.answers?.forEach((ans) => {
1814
- ans.issues = ans.issues?.filter(
1815
- (issue) => issue.Details && issue.Details.length > 0,
1965
+ taskTypes.map( async ( type, index ) => {
1966
+ const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask, req.body.taskId );
1967
+
1968
+ let data = await planoTaskService.aggregate( pipeline );
1969
+ if ( filterByApprovalStatus && filterByApprovalStatus !== '' ) {
1970
+ data.forEach( ( element ) => {
1971
+ element.answers?.forEach( ( ans ) => {
1972
+ ans.issues = ans.issues?.filter(
1973
+ ( issue ) => issue.Details && issue.Details.length > 0,
1974
+ );
1975
+ } );
1976
+ element.answers = element.answers?.filter(
1977
+ ( ans ) => ans.issues && ans.issues.length > 0,
1816
1978
  );
1817
- });
1818
- element.answers = element.answers?.filter(
1819
- (ans) => ans.issues && ans.issues.length > 0,
1979
+ } );
1980
+ data = data.filter(
1981
+ ( element ) => element.answers && element.answers.length > 0,
1820
1982
  );
1821
- });
1822
- data = data.filter(
1823
- (element) => element.answers && element.answers.length > 0,
1824
- );
1825
- }
1983
+ }
1826
1984
 
1827
1985
 
1828
- resultMap[type] = data;
1986
+ resultMap[type] = data;
1829
1987
 
1830
- let taskId = [];
1831
- if (req.body.taskId) {
1832
- taskId.push(new mongoose.Types.ObjectId(req.body.taskId));
1833
- }
1834
- if (req.body.refTaskId) {
1835
- taskId.push(new mongoose.Types.ObjectId(req.body.refTaskId));
1836
- }
1988
+ let taskId = [];
1989
+ if ( req.body.taskId ) {
1990
+ taskId.push( new mongoose.Types.ObjectId( req.body.taskId ) );
1991
+ }
1992
+ if ( req.body.refTaskId ) {
1993
+ taskId.push( new mongoose.Types.ObjectId( req.body.refTaskId ) );
1994
+ }
1837
1995
 
1838
- const comments = await planoGlobalCommentService.find({
1839
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
1840
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
1841
- ...(taskId.length && { taskId: { $in: taskId } }),
1842
- taskType: type,
1843
- });
1844
- commentMap[type] = comments;
1845
- }),
1996
+ const comments = await planoGlobalCommentService.find( {
1997
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1998
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1999
+ ...( taskId.length && { taskId: { $in: taskId } } ),
2000
+ taskType: type,
2001
+ } );
2002
+ commentMap[type] = comments;
2003
+ } ),
1846
2004
  );
1847
2005
  const response = {
1848
2006
  merchRolloutData: resultMap['merchRollout'] || [],
@@ -1851,39 +2009,39 @@ export async function getRolloutFeedback(req, res) {
1851
2009
  vmRolloutComment: commentMap['vmRollout'] || [],
1852
2010
  };
1853
2011
 
1854
- res.sendSuccess(response);
1855
- } catch (e) {
1856
- logger.error({ functionName: 'getRolloutFeedback', error: e });
1857
- return res.sendError(e, 500);
2012
+ res.sendSuccess( response );
2013
+ } catch ( e ) {
2014
+ logger.error( { functionName: 'getRolloutFeedback', error: e } );
2015
+ return res.sendError( e, 500 );
1858
2016
  }
1859
2017
  }
1860
2018
 
1861
2019
 
1862
- export async function getRolloutFeedbackv2(req, res) {
2020
+ export async function getRolloutFeedbackv2( req, res ) {
1863
2021
  try {
1864
- const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['merchRollout', 'vmRollout'];
2022
+ const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'merchRollout', 'vmRollout' ];
1865
2023
  const filterByStatus = req.body.filterByStatus || [];
1866
2024
  const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
1867
2025
  const resultMap = {};
1868
2026
  const commentMap = {};
1869
2027
  await Promise.all(
1870
- taskTypes.map(async (type, index) => {
1871
- const pipeline = pipelineStage(type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask);
1872
- const data = await processedTaskService.aggregate(pipeline);
1873
- resultMap[type] = data;
1874
- }));
2028
+ taskTypes.map( async ( type, index ) => {
2029
+ const pipeline = pipelineStage( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
2030
+ const data = await processedTaskService.aggregate( pipeline );
2031
+ resultMap[type] = data;
2032
+ } ) );
1875
2033
  const response = {
1876
2034
  merchRolloutData: resultMap['merchRollout'] || [],
1877
2035
  vmRolloutData: resultMap['vmRollout'] || [],
1878
2036
  merchRolloutComment: commentMap['merchRollout'] || [],
1879
2037
  vmRolloutComment: commentMap['vmRollout'] || [],
1880
2038
  };
1881
- if (filterByStatus.length || filterByApprovalStatus) {
1882
- let data = response[`${req.body.type}RolloutData`].filter((ele) => ele.storeFixtureList.length);
1883
- if (filterByStatus.length == 1) {
1884
- data = data.filter((type) => {
1885
- let fixtureList = type.storeFixtureList.filter((ele) => filterByStatus.includes(ele.status));
1886
- if (filterByStatus.includes('complete')) {
2039
+ if ( filterByStatus.length || filterByApprovalStatus ) {
2040
+ let data = response[`${req.body.type}RolloutData`].filter( ( ele ) => ele.storeFixtureList.length );
2041
+ if ( filterByStatus.length == 1 ) {
2042
+ data = data.filter( ( type ) => {
2043
+ let fixtureList = type.storeFixtureList.filter( ( ele ) => filterByStatus.includes( ele.status ) );
2044
+ if ( filterByStatus.includes( 'complete' ) ) {
1887
2045
  return type.storeFixtureList.length == fixtureList.length;
1888
2046
  } else {
1889
2047
  return fixtureList.length;
@@ -1891,69 +2049,69 @@ export async function getRolloutFeedbackv2(req, res) {
1891
2049
  },
1892
2050
  );
1893
2051
  }
1894
- if (filterByApprovalStatus) {
1895
- if (filterByApprovalStatus === 'pending') {
1896
- data = data.filter((type) => {
1897
- let fixtureList = type.storeFixtureList.filter((ele) => {
1898
- if (ele.status === 'complete' && !ele.answers?.[0]?.issues.length && !ele.answers?.[0]?.status) {
2052
+ if ( filterByApprovalStatus ) {
2053
+ if ( filterByApprovalStatus === 'pending' ) {
2054
+ data = data.filter( ( type ) => {
2055
+ let fixtureList = type.storeFixtureList.filter( ( ele ) => {
2056
+ if ( ele.status === 'complete' && !ele.answers?.[0]?.issues.length && !ele.answers?.[0]?.status ) {
1899
2057
  return true;
1900
2058
  } else {
1901
- return ele.answers?.some((ans) =>
1902
- ans.issues?.some((issue) =>
1903
- issue?.Details?.some((detail) => detail.status === 'pending'),
2059
+ return ele.answers?.some( ( ans ) =>
2060
+ ans.issues?.some( ( issue ) =>
2061
+ issue?.Details?.some( ( detail ) => detail.status === 'pending' ),
1904
2062
  ),
1905
2063
  );
1906
2064
  }
1907
- });
2065
+ } );
1908
2066
 
1909
2067
  return fixtureList.length;
1910
- });
2068
+ } );
1911
2069
  } else {
1912
- data = data.filter((type) => {
1913
- let fixtureList = type.storeFixtureList.filter((ele) => {
1914
- if (ele.status === 'complete' && !ele.answers?.[0]?.issues.length && ele.answers?.[0]?.status) {
2070
+ data = data.filter( ( type ) => {
2071
+ let fixtureList = type.storeFixtureList.filter( ( ele ) => {
2072
+ if ( ele.status === 'complete' && !ele.answers?.[0]?.issues.length && ele.answers?.[0]?.status ) {
1915
2073
  return true;
1916
2074
  } else {
1917
- return ele.answers?.some((ans) =>
1918
- ans.issues?.some((issue) =>
1919
- issue?.Details?.some((detail) => detail.status !== 'pending'),
2075
+ return ele.answers?.some( ( ans ) =>
2076
+ ans.issues?.some( ( issue ) =>
2077
+ issue?.Details?.some( ( detail ) => detail.status !== 'pending' ),
1920
2078
  ),
1921
2079
  );
1922
2080
  }
1923
- });
2081
+ } );
1924
2082
 
1925
2083
  return fixtureList.length;
1926
- });
2084
+ } );
1927
2085
  }
1928
2086
  }
1929
2087
  response[`${req.body.type}RolloutData`] = data;
1930
2088
  }
1931
- response.vmRolloutData = await Promise.all(response.vmRolloutData.map(async (ele) => {
1932
- ele.storeFixtureList = await Promise.all(ele.storeFixtureList.map(async (fixt) => {
1933
- if (fixt?.FixtureData?.vmConfig?.length) {
1934
- fixt.FixtureData.vmConfig = await Promise.all(fixt?.FixtureData?.vmConfig?.map(async (config) => {
1935
- let vmDetails = await planoVmService.findOne({ _id: config.vmId }, { vmType: 1, vmName: 1 });
2089
+ response.vmRolloutData = await Promise.all( response.vmRolloutData.map( async ( ele ) => {
2090
+ ele.storeFixtureList = await Promise.all( ele.storeFixtureList.map( async ( fixt ) => {
2091
+ if ( fixt?.FixtureData?.vmConfig?.length ) {
2092
+ fixt.FixtureData.vmConfig = await Promise.all( fixt?.FixtureData?.vmConfig?.map( async ( config ) => {
2093
+ let vmDetails = await planoVmService.findOne( { _id: config.vmId }, { vmType: 1, vmName: 1 } );
1936
2094
  return { ...config, vmType: vmDetails.vmType, vmName: vmDetails.vmName };
1937
- }));
2095
+ } ) );
1938
2096
  }
1939
2097
  return fixt;
1940
- }));
2098
+ } ) );
1941
2099
  return ele;
1942
- }));
1943
- res.sendSuccess(response);
1944
- } catch (e) {
1945
- logger.error({ functionName: 'getRolloutFeedbackv2', error: e });
1946
- return res.sendError(e, 500);
2100
+ } ) );
2101
+ res.sendSuccess( response );
2102
+ } catch ( e ) {
2103
+ logger.error( { functionName: 'getRolloutFeedbackv2', error: e } );
2104
+ return res.sendError( e, 500 );
1947
2105
  }
1948
2106
  }
1949
2107
 
1950
2108
 
1951
- function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0) {
1952
- let matchStage = [{
2109
+ function pipelineStage( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
2110
+ let matchStage = [ {
1953
2111
  $match: {
1954
2112
  'planoType': type,
1955
- 'planoId': new mongoose.Types.ObjectId(planoId),
1956
- 'floorId': new mongoose.Types.ObjectId(floorId),
2113
+ 'planoId': new mongoose.Types.ObjectId( planoId ),
2114
+ 'floorId': new mongoose.Types.ObjectId( floorId ),
1957
2115
  },
1958
2116
  },
1959
2117
 
@@ -1981,7 +2139,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
1981
2139
  $match: {
1982
2140
  $expr: {
1983
2141
  $and: [
1984
- { $eq: ['$taskId', '$$taskId'] },
2142
+ { $eq: [ '$taskId', '$$taskId' ] },
1985
2143
  ],
1986
2144
  },
1987
2145
  },
@@ -2005,7 +2163,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
2005
2163
  {
2006
2164
  $match: {
2007
2165
  $expr: {
2008
- $eq: ['$taskId', '$$taskId'],
2166
+ $eq: [ '$taskId', '$$taskId' ],
2009
2167
  },
2010
2168
  },
2011
2169
  },
@@ -2023,7 +2181,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
2023
2181
  let: { fixtureId: '$planoData.fixtureId' },
2024
2182
  pipeline: [
2025
2183
  {
2026
- $match: { $expr: { $eq: ['$_id', '$$fixtureId'] } },
2184
+ $match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
2027
2185
  },
2028
2186
  ],
2029
2187
  as: 'FixtureData',
@@ -2038,7 +2196,7 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
2038
2196
  let: { fixtureId: '$FixtureData._id' },
2039
2197
  pipeline: [
2040
2198
  {
2041
- $match: { $expr: { $eq: ['$fixtureId', '$$fixtureId'] } },
2199
+ $match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
2042
2200
  },
2043
2201
  ],
2044
2202
  as: 'Fixtureshelves',
@@ -2073,16 +2231,16 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
2073
2231
  $and: [
2074
2232
  {
2075
2233
  $or: [
2076
- { $eq: ['$redoStatus', true] },
2234
+ { $eq: [ '$redoStatus', true ] },
2077
2235
  {
2078
2236
  $and: [
2079
- { $eq: ['$redoStatus', false] },
2080
- { $eq: ['$checklistStatus', 'submit'] },
2237
+ { $eq: [ '$redoStatus', false ] },
2238
+ { $eq: [ '$checklistStatus', 'submit' ] },
2081
2239
  ],
2082
2240
  },
2083
2241
  ],
2084
2242
  },
2085
- { $ne: [{ $ifNull: ['$FixtureData.fixtureName', null] }, null] },
2243
+ { $ne: [ { $ifNull: [ '$FixtureData.fixtureName', null ] }, null ] },
2086
2244
  // { $gt: [ { $size: { $ifNull: [ '$FixtureData' ] } }, 0 ] },
2087
2245
  // { $gt: [ { $size: { $ifNull: [ '$FixtureData.shelfConfig', [] ] } }, 0 ] },
2088
2246
  ],
@@ -2129,48 +2287,3 @@ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalS
2129
2287
 
2130
2288
  return pipeline;
2131
2289
  }
2132
-
2133
-
2134
- export async function getPlanoStoreVideoPageParams(req, res) {
2135
- try {
2136
- const { storeId } = req.body;
2137
-
2138
- if (!storeId) {
2139
- return res.sendError('Store ID Missing.', 400);
2140
- }
2141
-
2142
- const checkListRes = await planoStaticService.findOne({ type: 'storeVideoChecklist' }, { checklistIds: 1 });
2143
-
2144
- if (checkListRes?.checklistIds?.length <= 0) {
2145
- return res.sendError('No checklist ids found', 400);
2146
- }
2147
-
2148
- const checklistData = await processedChecklistService.findOne(
2149
- {
2150
- sourceCheckList_id: {
2151
- $in: checkListRes?.checklistIds ?? [],
2152
- },
2153
- checklistStatus: "submit",
2154
- store_id: storeId,
2155
- checkListType: "custom",
2156
- }, {}, { sort: { _id: -1 } }
2157
- );
2158
-
2159
- if (!checklistData) {
2160
- return res.sendError('No checklist data found', 400);
2161
- }
2162
-
2163
- const response = {
2164
- storeId: storeId,
2165
- ChecklistDate: checklistData?.date_string,
2166
- checklistType: checklistData?.checkListType,
2167
- checklistStatus: checklistData?.checklistStatus,
2168
- sourceCheckList_id: checklistData?.sourceCheckList_id,
2169
- }
2170
-
2171
- res.sendSuccess(response);
2172
- } catch (e) {
2173
- logger.error({ functionName: 'getPlanoStoreVideoPageParams', error: e });
2174
- res.sendError('Failed to fetch plano store video page params', 500);
2175
- }
2176
- }