tango-app-api-store-builder 1.0.21 → 1.0.23

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