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

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