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

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,28 @@ 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
896
  // ❗ async changed here
894
- for ( let i = 0; i < currentFixtures.length; i++ ) {
897
+ for (let i = 0; i < currentFixtures.length; i++) {
895
898
  const fixture = currentFixtures[i];
896
899
 
897
- if ( mongoose.Types.ObjectId.isValid( fixture._id ) ) {
900
+ if (mongoose.Types.ObjectId.isValid(fixture._id)) {
898
901
  const updatedFixture = await storeFixtureService.upsertOne(
899
- { _id: new mongoose.Types.ObjectId( fixture._id ) },
900
- fixture,
902
+ { _id: new mongoose.Types.ObjectId(fixture._id) },
903
+ fixture,
901
904
  );
902
905
 
903
906
  await storeFixtureService.removeKeys(
904
- { fixtureType: 'floor', _id: fixture._id },
905
- { $unset: { associatedElementType: '', associatedElementNumber: '' } },
907
+ { fixtureType: 'floor', _id: fixture._id },
908
+ { $unset: { associatedElementType: '', associatedElementNumber: '' } },
906
909
  );
907
910
 
908
- await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixture._id ) } );
911
+ await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixture._id) });
909
912
 
910
- for ( let j = 0; j < fixture.shelfConfig.length; j++ ) {
913
+ for (let j = 0; j < fixture.shelfConfig.length; j++) {
911
914
  const shelf = fixture.shelfConfig[j];
912
915
 
913
916
  delete shelf._id;
@@ -918,87 +921,87 @@ export async function updateStorePlano( req, res ) {
918
921
  fixtureId: updatedFixture.toObject()._id,
919
922
  };
920
923
 
921
- await fixtureShelfService.create( shelfPayload );
924
+ await fixtureShelfService.create(shelfPayload);
922
925
  }
923
926
  }
924
927
  }
925
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
+ res.sendSuccess('Updated Successfully');
935
+ } catch (e) {
936
+ logger.error({ functionName: 'updateStorePlano', error: e });
937
+ return res.sendError(e, 500);
935
938
  }
936
939
  }
937
940
 
938
941
 
939
- export async function fixtureList( req, res ) {
942
+ export async function fixtureList(req, res) {
940
943
  try {
941
- let findData = await fixtureLibraryService.find( { clientId: req.query.clientId } );
942
- if ( findData.length === 0 ) {
943
- return res.sendError( 'nodata found', 204 );
944
+ let findData = await fixtureLibraryService.find({ clientId: req.query.clientId });
945
+ if (findData.length === 0) {
946
+ return res.sendError('nodata found', 204);
944
947
  }
945
- res.sendSuccess( findData );
946
- } catch ( e ) {
947
- logger.error( { functionName: 'fixtureList', error: e } );
948
- return res.sendError( e, 500 );
948
+ res.sendSuccess(findData);
949
+ } catch (e) {
950
+ logger.error({ functionName: 'fixtureList', error: e });
951
+ return res.sendError(e, 500);
949
952
  }
950
953
  }
951
- export async function templateList( req, res ) {
954
+ export async function templateList(req, res) {
952
955
  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 );
956
+ let findData = await fixtureConfigService.find({ clientId: req.query.clientId, fixtureLibraryId: new mongoose.Types.ObjectId(req.query.fixtureId) });
957
+ if (findData.length === 0) {
958
+ return res.sendError('nodata found', 204);
956
959
  }
957
- res.sendSuccess( findData );
958
- } catch ( e ) {
959
- logger.error( { functionName: 'templateList', error: e } );
960
- return res.sendError( e, 500 );
960
+ res.sendSuccess(findData);
961
+ } catch (e) {
962
+ logger.error({ functionName: 'templateList', error: e });
963
+ return res.sendError(e, 500);
961
964
  }
962
965
  }
963
- export async function fixtureBrandsList( req, res ) {
966
+ export async function fixtureBrandsList(req, res) {
964
967
  try {
965
- let findData = await planoproductCategoryService.find( { clientId: req.query.clientId } );
966
- if ( findData.length === 0 ) {
967
- return res.sendError( 'nodata found', 204 );
968
+ let findData = await planoproductCategoryService.find({ clientId: req.query.clientId });
969
+ if (findData.length === 0) {
970
+ return res.sendError('nodata found', 204);
968
971
  }
969
- res.sendSuccess( findData );
970
- } catch ( e ) {
971
- logger.error( { functionName: 'fixtureBrandsList', error: e } );
972
- return res.sendError( e, 500 );
972
+ res.sendSuccess(findData);
973
+ } catch (e) {
974
+ logger.error({ functionName: 'fixtureBrandsList', error: e });
975
+ return res.sendError(e, 500);
973
976
  }
974
977
  }
975
978
 
976
- export async function fixtureVMList( req, res ) {
979
+ export async function fixtureVMList(req, res) {
977
980
  try {
978
- let findData = await planoVmService.find( { clientId: req.query.clientId } );
979
- if ( findData.length === 0 ) {
980
- return res.sendError( 'nodata found', 204 );
981
+ let findData = await planoVmService.find({ clientId: req.query.clientId });
982
+ if (findData.length === 0) {
983
+ return res.sendError('nodata found', 204);
981
984
  }
982
- res.sendSuccess( findData );
983
- } catch ( e ) {
984
- logger.error( { functionName: 'fixtureVMList', error: e } );
985
- return res.sendError( e, 500 );
985
+ res.sendSuccess(findData);
986
+ } catch (e) {
987
+ logger.error({ functionName: 'fixtureVMList', error: e });
988
+ return res.sendError(e, 500);
986
989
  }
987
990
  }
988
991
 
989
- export async function fixtureVMListv1( req, res ) {
992
+ export async function fixtureVMListv1(req, res) {
990
993
  try {
991
- let findData = await planoVmDuplicateService.find( { clientId: req.query.clientId } );
992
- if ( findData.length === 0 ) {
993
- return res.sendError( 'nodata found', 204 );
994
+ let findData = await planoVmDuplicateService.find({ clientId: req.query.clientId });
995
+ if (findData.length === 0) {
996
+ return res.sendError('nodata found', 204);
994
997
  }
995
- res.sendSuccess( findData );
996
- } catch ( e ) {
997
- logger.error( { functionName: 'fixtureVMListv1', error: e } );
998
- return res.sendError( e, 500 );
998
+ res.sendSuccess(findData);
999
+ } catch (e) {
1000
+ logger.error({ functionName: 'fixtureVMListv1', error: e });
1001
+ return res.sendError(e, 500);
999
1002
  }
1000
1003
  }
1001
- export async function updateFixtureStatus( req, res ) {
1004
+ export async function updateFixtureStatus(req, res) {
1002
1005
  try {
1003
1006
  let comments = {
1004
1007
  userId: req.user._id,
@@ -1008,152 +1011,152 @@ export async function updateFixtureStatus( req, res ) {
1008
1011
  comment: req.body.comments,
1009
1012
  };
1010
1013
 
1011
- if ( req.body.taskType.includes( 'fixture' ) ) {
1014
+ if (req.body.taskType.includes('fixture')) {
1012
1015
  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 ) },
1016
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1017
+ {
1018
+ $set: {
1019
+ 'answers.$[ans].status': req.body.type,
1020
+ 'answers.$[ans].userAction': req.body.userAction
1021
+ }
1022
+ },
1023
+ [
1024
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1022
1025
 
1023
- ],
1026
+ ],
1024
1027
  );
1025
1028
  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
- ] );
1029
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1030
+ {
1031
+ $push: { 'answers.$[ans].comments': comments },
1032
+ },
1033
+ [
1034
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1035
+ ]);
1033
1036
 
1034
- await planoTaskService.updateOne( { _id: req.body._id }, { approvalStatus: 'approved', taskType: 'initial' } );
1037
+ await planoTaskService.updateOne({ _id: req.body._id }, { approvalStatus: 'approved', taskType: 'initial' });
1035
1038
  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
- },
1039
+ {
1040
+ planoId: new mongoose.Types.ObjectId(req.body.planoId),
1041
+ floorId: new mongoose.Types.ObjectId(req.body.floorId),
1042
+ type: 'fixture',
1043
+ },
1041
1044
  );
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 } );
1045
+ if (fixtureTask.length > 0) {
1046
+ let allTaskDone = fixtureTask.filter((data) => !data?.answers?.[0]?.status || data?.answers?.[0]?.status == 'disagree');
1047
+ if (allTaskDone.length === 0) {
1048
+ await floorService.updateOne({ _id: new mongoose.Types.ObjectId(req.body.floorId) }, { planoProgress: 100 });
1046
1049
  }
1047
1050
  }
1048
1051
  } else {
1049
1052
  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 ) {
1053
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1054
+ {
1055
+ $set: { 'answers.$[ans].issues.$[iss].Details.$[det].status': req.body.type },
1056
+ },
1057
+ [
1058
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1059
+ { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1060
+ { 'det._id': new mongoose.Types.ObjectId(req.body.DetailsId) },
1061
+
1062
+ ]);
1063
+ if (updateResponse && updateResponse.answers.length > 0) {
1064
+ let findissuse = updateResponse.answers[0].issues.filter((data) => data._id == req.body.issueId);
1065
+ let findDetails = findissuse[0].Details.filter((det) => det.status === 'agree');
1066
+ if (findissuse[0].Details.length === findDetails.length) {
1064
1067
  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
- ] );
1068
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1069
+ {
1070
+ $set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
1071
+ },
1072
+ [
1073
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1074
+ { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1075
+ ]);
1073
1076
  }
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 ) {
1077
+ let findoneplanoData = await planoTaskService.findOne({ _id: new mongoose.Types.ObjectId(req.body._id) });
1078
+ let totalApproved = findoneplanoData.answers[0].issues.filter((data) => data.status === 'pending');
1079
+ if (totalApproved.length === 0) {
1077
1080
  await planoTaskService.updateOne(
1081
+ {
1082
+ _id: new mongoose.Types.ObjectId(req.body._id),
1083
+ },
1084
+ {
1085
+ 'status': 'complete',
1086
+ },
1087
+ );
1088
+ if (req.body.taskType === 'layout') {
1089
+ await planoTaskService.updateMany(
1078
1090
  {
1079
- _id: new mongoose.Types.ObjectId( req.body._id ),
1091
+ planoId: new mongoose.Types.ObjectId(req.body.planoId),
1092
+ floorId: new mongoose.Types.ObjectId(req.body.floorId),
1093
+ type: 'layout',
1080
1094
  },
1081
1095
  {
1082
1096
  'status': 'complete',
1083
1097
  },
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
1098
  );
1096
1099
  }
1097
1100
  }
1098
1101
  }
1099
1102
 
1100
- if ( req.body.taskType === 'layout' ) {
1103
+ if (req.body.taskType === 'layout') {
1101
1104
  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 ) },
1105
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1106
+ {
1107
+ $push: { 'answers.$[ans].issues.$[iss].Details.$[det].comments': comments },
1108
+ },
1109
+ [
1110
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1111
+ { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1112
+ { 'det._id': new mongoose.Types.ObjectId(req.body.DetailsId) },
1110
1113
 
1111
- ] );
1114
+ ]);
1112
1115
  } else {
1113
1116
  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(
1117
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1124
1118
  {
1125
- planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1126
- floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1127
- type: 'vm',
1119
+ $push: { 'answers.$[ans].issues.$[iss].comments': comments },
1128
1120
  },
1121
+ [
1122
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1123
+ { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1124
+ ]);
1125
+ }
1126
+ let vmTask = await planoTaskService.find(
1127
+ {
1128
+ planoId: new mongoose.Types.ObjectId(req.body.planoId),
1129
+ floorId: new mongoose.Types.ObjectId(req.body.floorId),
1130
+ type: 'vm',
1131
+ },
1129
1132
 
1130
1133
  );
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 } );
1134
+ if (vmTask.length > 0) {
1135
+ let allTaskDone = vmTask.filter((data) => data.status === 'incomplete');
1136
+ if (allTaskDone.length === 0) {
1137
+ await floorService.updateOne({ _id: new mongoose.Types.ObjectId(req.body.floorId) }, { planoProgress: 100 });
1135
1138
  }
1136
1139
  }
1137
1140
  }
1138
- res.sendSuccess( 'updated successfully' );
1139
- } catch ( e ) {
1140
- logger.error( { functionName: 'updateFixtureStatus', error: e } );
1141
- return res.sendError( e, 500 );
1141
+ res.sendSuccess('updated successfully');
1142
+ } catch (e) {
1143
+ logger.error({ functionName: 'updateFixtureStatus', error: e });
1144
+ return res.sendError(e, 500);
1142
1145
  }
1143
1146
  }
1144
1147
 
1145
- export async function updateApprovalStatus( req, res ) {
1148
+ export async function updateApprovalStatus(req, res) {
1146
1149
  try {
1147
1150
  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 );
1151
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1152
+ { $set: { approvalStatus: 'approved' } });
1153
+ res.sendSuccess('updated successfully');
1154
+ } catch (e) {
1155
+ logger.error({ functionName: 'updateApprovalStatus', error: e });
1156
+ return res.sendError(e, 500);
1154
1157
  }
1155
1158
  }
1156
- export async function updateRolloutStatus( req, res ) {
1159
+ export async function updateRolloutStatus(req, res) {
1157
1160
  try {
1158
1161
  let comments = {
1159
1162
  userId: req.user._id,
@@ -1163,153 +1166,153 @@ export async function updateRolloutStatus( req, res ) {
1163
1166
  comment: req.body.comments,
1164
1167
  };
1165
1168
 
1166
- if ( req.body.issueId && req.body.DetailsId ) {
1169
+ if (req.body.issueId && req.body.DetailsId) {
1167
1170
  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
- },
1171
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1172
+ {
1173
+ $set: {
1174
+ 'answers.$[ans].issues.$[iss].Details.$[det].status': req.body.type,
1175
+ 'answers.$[ans].issues.$[iss].Details.$[det].adminStatus': req.body.type === 'agree' ? 'approved' : 'Unapproved',
1174
1176
  },
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 ) },
1177
+ },
1178
+ [
1179
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1180
+ { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1181
+ { 'det._id': new mongoose.Types.ObjectId(req.body.DetailsId) },
1179
1182
 
1180
- ],
1183
+ ],
1181
1184
  );
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 ) {
1185
+ if (updateResponse && updateResponse.answers.length > 0) {
1186
+ let findissuse = updateResponse.answers[0].issues.filter((data) => data._id == req.body.issueId);
1187
+ let findDetails = findissuse[0].Details.filter((det) => det.status === 'agree');
1188
+ if (findissuse[0].Details.length === findDetails.length) {
1186
1189
  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
- ] );
1190
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1191
+ {
1192
+ $set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
1193
+ },
1194
+ [
1195
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1196
+ { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1197
+ ]);
1195
1198
  }
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 ) {
1199
+ let findoneplanoData = await planoTaskService.findOne({ _id: new mongoose.Types.ObjectId(req.body._id) });
1200
+ let totalApproved = findoneplanoData.answers[0].issues.filter((data) => data.status === 'pending');
1201
+ if (totalApproved.length === 0) {
1199
1202
  await planoTaskService.updateOne(
1200
- {
1201
- _id: new mongoose.Types.ObjectId( req.body._id ),
1202
- },
1203
- {
1204
- 'status': 'complete',
1205
- 'approvalStatus': 'approved',
1206
- },
1203
+ {
1204
+ _id: new mongoose.Types.ObjectId(req.body._id),
1205
+ },
1206
+ {
1207
+ 'status': 'complete',
1208
+ 'approvalStatus': 'approved',
1209
+ },
1207
1210
  );
1208
1211
  let data = {};
1209
- if ( req.body.taskType == 'vmRollout' ) {
1212
+ if (req.body.taskType == 'vmRollout') {
1210
1213
  data['isVmEdited'] = false;
1211
1214
  } else {
1212
1215
  data['isMerchEdited'] = false;
1213
1216
  }
1214
- await storeFixtureService.updateOne( { _id: updateResponse.fixtureId }, data );
1217
+ await storeFixtureService.updateOne({ _id: updateResponse.fixtureId }, data);
1215
1218
  }
1216
1219
  }
1217
1220
  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
- ],
1221
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1222
+ {
1223
+ $push: { 'answers.$[ans].issues.$[iss].comments': comments },
1224
+ },
1225
+ [
1226
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1227
+ { 'iss._id': new mongoose.Types.ObjectId(req.body.issueId) },
1228
+ ],
1226
1229
  );
1227
1230
  } else {
1228
1231
  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
- },
1232
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1233
+ {
1234
+ $set: {
1235
+ 'answers.$[ans].status': req.body.type,
1234
1236
  },
1235
- [
1236
- { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
1237
- ],
1237
+ },
1238
+ [
1239
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1240
+ ],
1238
1241
  );
1239
1242
  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
- ],
1243
+ { _id: new mongoose.Types.ObjectId(req.body._id) },
1244
+ {
1245
+ $push: { 'answers.$[ans].comments': comments },
1246
+ },
1247
+ [
1248
+ { 'ans._id': new mongoose.Types.ObjectId(req.body.answerId) },
1249
+ ],
1247
1250
  );
1248
- if ( req.body.type == 'agree' ) {
1251
+ if (req.body.type == 'agree') {
1249
1252
  await planoTaskService.updateOne(
1250
- {
1251
- _id: new mongoose.Types.ObjectId( req.body._id ),
1252
- },
1253
- {
1254
- 'approvalStatus': 'approved',
1255
- },
1253
+ {
1254
+ _id: new mongoose.Types.ObjectId(req.body._id),
1255
+ },
1256
+ {
1257
+ 'approvalStatus': 'approved',
1258
+ },
1256
1259
  );
1257
1260
  let data = {};
1258
- if ( req.body.taskType == 'vmRollout' ) {
1261
+ if (req.body.taskType == 'vmRollout') {
1259
1262
  data['isVmEdited'] = false;
1260
1263
  } else {
1261
1264
  data['isMerchEdited'] = false;
1262
1265
  }
1263
- await storeFixtureService.updateOne( { _id: updateResponse.fixtureId }, data );
1266
+ await storeFixtureService.updateOne({ _id: updateResponse.fixtureId }, data);
1264
1267
  }
1265
1268
  }
1266
1269
 
1267
- res.sendSuccess( 'updated successfully' );
1268
- } catch ( e ) {
1269
- logger.error( { functionName: 'updateFixtureStatus', error: e } );
1270
- return res.sendError( e, 500 );
1270
+ res.sendSuccess('updated successfully');
1271
+ } catch (e) {
1272
+ logger.error({ functionName: 'updateFixtureStatus', error: e });
1273
+ return res.sendError(e, 500);
1271
1274
  }
1272
1275
  }
1273
1276
 
1274
1277
 
1275
- export async function updateStoreFixture( req, res ) {
1278
+ export async function updateStoreFixture(req, res) {
1276
1279
  try {
1277
1280
  const { fixtureId, data } = req.body;
1278
1281
 
1279
1282
  let configId;
1280
1283
 
1281
- const currentFixture = await storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( fixtureId ) } );
1284
+ const currentFixture = await storeFixtureService.findOne({ _id: new mongoose.Types.ObjectId(fixtureId) });
1282
1285
  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 ) {
1286
+ if (data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi') {
1287
+ let shelfDetails = await fixtureShelfService.find({ fixtureId: fixtureId });
1288
+ data.shelfConfig.forEach((ele) => {
1289
+ let findShelfProduct = shelfDetails.find((shelf) => shelf.shelfNumber == ele.shelfNumber);
1290
+ if (!ele?.zone) {
1288
1291
  ele.zone = findShelfProduct?.zone ?? 'Bottom';
1289
1292
  }
1290
- if ( !ele?.productBrandName ) {
1293
+ if (!ele?.productBrandName) {
1291
1294
  ele.productBrandName = findShelfProduct?.productBrandName ?? [];
1292
1295
  }
1293
- if ( !ele?.productCategory ) {
1296
+ if (!ele?.productCategory) {
1294
1297
  ele.productCategory = findShelfProduct?.productCategory ?? [];
1295
1298
  }
1296
- if ( !ele?.productSubCategory ) {
1299
+ if (!ele?.productSubCategory) {
1297
1300
  ele.productSubCategory = findShelfProduct?.productSubCategory ?? [];
1298
1301
  }
1299
- } );
1302
+ });
1300
1303
  let vmConfig = [];
1301
- for ( let vm of data.vmConfig ) {
1302
- let checkvmType = await vmTypeService.findOne( { vmType: vm.vmType } );
1303
- if ( !checkvmType ) {
1304
+ for (let vm of data.vmConfig) {
1305
+ let checkvmType = await vmTypeService.findOne({ vmType: vm.vmType });
1306
+ if (!checkvmType) {
1304
1307
  let vmData = {
1305
1308
  vmType: vm.vmType,
1306
- imageUrls: [ vm.vmImage ],
1309
+ imageUrls: [vm.vmImage],
1307
1310
  clientId: '11',
1308
1311
  };
1309
- checkvmType = await vmTypeService.create( vmData );
1312
+ checkvmType = await vmTypeService.create(vmData);
1310
1313
  }
1311
- let vmDetails = await planoVmService.findOne( { ...( vm.vmName ) ? { vmName: vm.vmName } : { _id: vm.vmId } } );
1312
- if ( !vmDetails ) {
1314
+ let vmDetails = await planoVmService.findOne({ ...(vm.vmName) ? { vmName: vm.vmName } : { _id: vm.vmId } });
1315
+ if (!vmDetails) {
1313
1316
  let planovmData = {
1314
1317
  vmType: vm.vmType,
1315
1318
  vmName: vm.vmName,
@@ -1325,9 +1328,9 @@ export async function updateStoreFixture( req, res ) {
1325
1328
  },
1326
1329
  vmImageUrl: vm.vmImage,
1327
1330
  };
1328
- vmDetails = await planoVmService.create( planovmData );
1331
+ vmDetails = await planoVmService.create(planovmData);
1329
1332
  }
1330
- vmConfig.push( { ...vm, vmId: vmDetails._id } );
1333
+ vmConfig.push({ ...vm, vmId: vmDetails._id });
1331
1334
  }
1332
1335
  data.vmConfig = vmConfig;
1333
1336
  let groupName = {
@@ -1336,12 +1339,12 @@ export async function updateStoreFixture( req, res ) {
1336
1339
  'Vincent Chase': 'VC Eye',
1337
1340
  'OwnDays': 'OD Eye',
1338
1341
  };
1339
- let header = ( data?.header?.label && data?.header?.label != 'Unknown' ) ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.header?.label;
1342
+ let header = (data?.header?.label && data?.header?.label != 'Unknown') ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.header?.label;
1340
1343
  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 ) => {
1344
+ mapKey += data.shelfConfig.map((ele) => `${ele.shelfNumber}=${ele.productBrandName.toString()}`).join('+');
1345
+ data?.vmConfig?.forEach((ele) => {
1343
1346
  mapKey += `${ele.vmName}${ele.startYPosition}${ele.endYPosition}${ele.xZone}${ele.yZone}`;
1344
- } );
1347
+ });
1345
1348
  let query = [
1346
1349
  {
1347
1350
  $addFields: {
@@ -1369,13 +1372,13 @@ export async function updateStoreFixture( req, res ) {
1369
1372
  },
1370
1373
  },
1371
1374
  ];
1372
- let [ fixturesubTemplate, fixtureMasterTemplate ] = await Promise.all( [
1373
- await fixtureConfigService.aggregate( query ),
1374
- await fixtureConfigService.aggregate( masterQuery ),
1375
- ] );
1375
+ let [fixturesubTemplate, fixtureMasterTemplate] = await Promise.all([
1376
+ await fixtureConfigService.aggregate(query),
1377
+ await fixtureConfigService.aggregate(masterQuery),
1378
+ ]);
1376
1379
 
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;
1380
+ if (!fixturesubTemplate.length) {
1381
+ let tempGroupName = (data?.header?.label && data?.header?.label != 'Unknown') ? groupName?.[data?.header?.label] ? groupName?.[data?.header?.label] : data?.header?.label : currentFixture.templateGroupName;
1379
1382
  let templateIndex = 1;
1380
1383
  let templateData = {
1381
1384
  ...currentFixtureDoc,
@@ -1388,20 +1391,20 @@ export async function updateStoreFixture( req, res ) {
1388
1391
  };
1389
1392
  delete templateData._id;
1390
1393
  delete templateData.masterTemplateId;
1391
- if ( !fixtureMasterTemplate.length ) {
1394
+ if (!fixtureMasterTemplate.length) {
1392
1395
  let masterTemplate = {
1393
1396
  ...templateData,
1394
1397
  fixtureName: `${templateData.header.label}-${templateData.fixtureCategory}`,
1395
1398
  templateType: 'master',
1396
1399
  crestMapKey: masterMapKey,
1397
1400
  };
1398
- fixtureMasterTemplate = await fixtureConfigService.create( masterTemplate );
1401
+ fixtureMasterTemplate = await fixtureConfigService.create(masterTemplate);
1399
1402
  } else {
1400
1403
  fixtureMasterTemplate = fixtureMasterTemplate[0];
1401
1404
  let tempQuery = [
1402
1405
  {
1403
1406
  $match: {
1404
- masterTemplateId: new mongoose.Types.ObjectId( fixtureMasterTemplate._id ),
1407
+ masterTemplateId: new mongoose.Types.ObjectId(fixtureMasterTemplate._id),
1405
1408
  },
1406
1409
  },
1407
1410
  {
@@ -1411,16 +1414,16 @@ export async function updateStoreFixture( req, res ) {
1411
1414
  },
1412
1415
  },
1413
1416
  ];
1414
- let getMaxTemp = await fixtureConfigService.aggregate( tempQuery );
1417
+ let getMaxTemp = await fixtureConfigService.aggregate(tempQuery);
1415
1418
  templateIndex = getMaxTemp?.[0]?.tempId + 1;
1416
1419
  }
1417
- templateData.fixtureName= `${header}-${data.fixtureCategory}-variant-${templateIndex}`,
1418
- templateData.templateType = 'sub';
1420
+ templateData.fixtureName = `${header}-${data.fixtureCategory}-variant-${templateIndex}`,
1421
+ templateData.templateType = 'sub';
1419
1422
  templateData.masterTemplateId = fixtureMasterTemplate._id;
1420
1423
  templateData.templateIndex = templateIndex;
1421
1424
  templateData.createdAt = new Date();
1422
1425
  templateData.updatedAt = new Date();
1423
- let subTemplate = await fixtureConfigService.create( templateData );
1426
+ let subTemplate = await fixtureConfigService.create(templateData);
1424
1427
  configId = subTemplate._id;
1425
1428
 
1426
1429
  data.fixtureConfigId = subTemplate._id;
@@ -1436,72 +1439,72 @@ export async function updateStoreFixture( req, res ) {
1436
1439
 
1437
1440
  let fixtureCapacity = 0;
1438
1441
 
1439
- data.shelfConfig.forEach( ( shelf ) => {
1442
+ data.shelfConfig.forEach((shelf) => {
1440
1443
  const { productBrandName: brand, productCategory: category, productSubCategory: subCategory } = shelf;
1441
1444
 
1442
- if ( typeof shelf?.productPerShelf === 'number' ) {
1443
- if ( shelf?.shelfType === 'shelf' ) {
1445
+ if (typeof shelf?.productPerShelf === 'number') {
1446
+ if (shelf?.shelfType === 'shelf') {
1444
1447
  fixtureCapacity += shelf.productPerShelf;
1445
1448
  }
1446
1449
 
1447
- if ( shelf?.shelfType === 'tray' ) {
1448
- fixtureCapacity += ( shelf?.productPerShelf * shelf?.trayRows );
1450
+ if (shelf?.shelfType === 'tray') {
1451
+ fixtureCapacity += (shelf?.productPerShelf * shelf?.trayRows);
1449
1452
  }
1450
1453
  }
1451
1454
 
1452
- if ( Array.isArray( brand ) ) {
1453
- brand.forEach( ( b ) => productBrandName.add( b ) );
1455
+ if (Array.isArray(brand)) {
1456
+ brand.forEach((b) => productBrandName.add(b));
1454
1457
  }
1455
1458
 
1456
- if ( Array.isArray( category ) ) {
1457
- category.forEach( ( c ) => productCategory.add( c ) );
1459
+ if (Array.isArray(category)) {
1460
+ category.forEach((c) => productCategory.add(c));
1458
1461
  }
1459
1462
 
1460
- if ( Array.isArray( subCategory ) ) {
1461
- subCategory.forEach( ( s ) => productSubCategory.add( s ) );
1463
+ if (Array.isArray(subCategory)) {
1464
+ subCategory.forEach((s) => productSubCategory.add(s));
1462
1465
  }
1463
- } );
1466
+ });
1464
1467
 
1465
1468
 
1466
- if ( data?.fixtureConfigId && currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId ) {
1467
- const newTemplate = await fixtureConfigService.findOne( { _id: data.fixtureConfigId } );
1469
+ if (data?.fixtureConfigId && currentFixtureDoc.fixtureConfigId.toString() !== data.fixtureConfigId) {
1470
+ const newTemplate = await fixtureConfigService.findOne({ _id: data.fixtureConfigId });
1468
1471
  currentFixtureDoc = {
1469
1472
  ...currentFixtureDoc,
1470
1473
  ...newTemplate.toObject(),
1471
1474
  fixtureConfigId: newTemplate.toObject()._id,
1472
1475
  fixtureCapacity: fixtureCapacity,
1473
- productBrandName: [ ...productBrandName ],
1474
- productCategory: [ ...productCategory ],
1475
- productSubCategory: [ ...productSubCategory ],
1476
+ productBrandName: [...productBrandName],
1477
+ productCategory: [...productCategory],
1478
+ productSubCategory: [...productSubCategory],
1476
1479
  };
1477
1480
  } else {
1478
1481
  currentFixtureDoc = {
1479
1482
  ...currentFixtureDoc,
1480
1483
  ...data,
1481
1484
  fixtureCapacity: fixtureCapacity,
1482
- productBrandName: [ ...productBrandName ],
1483
- productCategory: [ ...productCategory ],
1484
- productSubCategory: [ ...productSubCategory ],
1485
+ productBrandName: [...productBrandName],
1486
+ productCategory: [...productCategory],
1487
+ productSubCategory: [...productSubCategory],
1485
1488
  };
1486
1489
  }
1487
1490
 
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 ) ) ];
1491
+ if (data.productResolutionLevel == 'L1') {
1492
+ currentFixtureDoc.productBrandName = [...new Set(data.productBrandName.map((ele) => ele))];
1493
+ currentFixtureDoc.productCategory = [...new Set(data.productCategory.map((ele) => ele))];
1494
+ currentFixtureDoc.productSubCategory = [...new Set(data.productSubCategory.map((ele) => ele))];
1492
1495
  }
1493
1496
 
1494
1497
 
1495
1498
  delete currentFixtureDoc._id;
1496
1499
 
1497
1500
 
1498
- await storeFixtureService.updateOne( { _id: new mongoose.Types.ObjectId( fixtureId ) }, currentFixtureDoc );
1501
+ await storeFixtureService.updateOne({ _id: new mongoose.Types.ObjectId(fixtureId) }, currentFixtureDoc);
1499
1502
 
1500
- if ( data?.shelfConfig?.length ) {
1501
- await fixtureShelfService.deleteMany( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
1503
+ if (data?.shelfConfig?.length) {
1504
+ await fixtureShelfService.deleteMany({ fixtureId: new mongoose.Types.ObjectId(fixtureId) });
1502
1505
 
1503
1506
 
1504
- data.shelfConfig.forEach( async ( shelf ) => {
1507
+ data.shelfConfig.forEach(async (shelf) => {
1505
1508
  delete shelf?._id;
1506
1509
  const additionalMeta = {
1507
1510
  clientId: currentFixture.clientId,
@@ -1512,12 +1515,12 @@ export async function updateStoreFixture( req, res ) {
1512
1515
  fixtureId: currentFixture._id,
1513
1516
  };
1514
1517
 
1515
- await fixtureShelfService.create( { ...additionalMeta, ...shelf } );
1516
- } );
1518
+ await fixtureShelfService.create({ ...additionalMeta, ...shelf });
1519
+ });
1517
1520
  }
1518
- await planoService.updateOne( { _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } } );
1521
+ await planoService.updateOne({ _id: currentFixtureDoc?.planoId }, { $set: { updatedAt: new Date() } });
1519
1522
 
1520
- if ( data?.userAction === 'editWithAi' || data?.userAction === 'editWithPlano' ) {
1523
+ if (data?.userAction === 'editWithAi' || data?.userAction === 'editWithPlano') {
1521
1524
  let comments = {
1522
1525
  userId: req.user._id,
1523
1526
  userName: req.user.userName,
@@ -1525,8 +1528,8 @@ export async function updateStoreFixture( req, res ) {
1525
1528
  responsetype: 'agree',
1526
1529
  comment: '',
1527
1530
  };
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
-
1531
+ await planoTaskService.updateOne({ planoId: currentFixture.planoId, floorId: currentFixture.floorId, fixtureId: currentFixture._id }, { 'answers.0.status': 'agree', 'approvalStatus': 'approved', 'answers.0.userAction': data.userAction });
1532
+
1530
1533
  await planoTaskService.updateOnefilters(
1531
1534
  { planoId: new mongoose.Types.ObjectId(currentFixture.planoId), floorId: new mongoose.Types.ObjectId(currentFixture.floorId), fixtureId: new mongoose.Types.ObjectId(currentFixture._id) },
1532
1535
  {
@@ -1536,23 +1539,23 @@ export async function updateStoreFixture( req, res ) {
1536
1539
 
1537
1540
  }
1538
1541
 
1539
- if ( data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi' ) {
1542
+ if (data?.userAction === 'editWithAi' || data?.userAction === 'acceptAi') {
1540
1543
  const op_id = `${data?.storeName}_${data?.storeDate}_${data?._id}`
1541
- await updateAIFeedbackInOpenSearch(data,op_id);
1544
+ await updateAIFeedbackInOpenSearch(data, op_id);
1542
1545
  }
1543
1546
 
1544
1547
  // if ( req.body?.editMode ) {
1545
1548
  // await floorService.updateOne( { _id: new mongoose.Types.ObjectId( currentFixture.floorId ) }, { isEdited: true } );
1546
1549
  // }
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 );
1550
+ res.sendSuccess({ message: 'Updated Successfully', ...(configId && { id: configId }) });
1551
+ } catch (e) {
1552
+ logger.error({ functionName: 'updateStoreFixture', error: e });
1553
+ return res.sendError(e, 500);
1551
1554
  }
1552
1555
  }
1553
1556
 
1554
1557
  const updateAIFeedbackInOpenSearch = async (fixtureData, id) => {
1555
-
1558
+
1556
1559
  try {
1557
1560
  let openSearchDetails = await getOpenSearchById(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id);
1558
1561
  if (openSearchDetails && openSearchDetails.statusCode == 200 && openSearchDetails?.body?._source) {
@@ -1595,7 +1598,7 @@ const updateAIFeedbackInOpenSearch = async (fixtureData, id) => {
1595
1598
  };
1596
1599
 
1597
1600
  let updateResult = await updateOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoAIValidation, id, document);
1598
-
1601
+
1599
1602
  if (updateResult?.statusCode == 200) {
1600
1603
  return true;
1601
1604
  }
@@ -1609,67 +1612,67 @@ const updateAIFeedbackInOpenSearch = async (fixtureData, id) => {
1609
1612
  }
1610
1613
  };
1611
1614
 
1612
- export async function updateredostatus( req, res ) {
1615
+ export async function updateredostatus(req, res) {
1613
1616
  try {
1614
- if ( req.body.type === 'layout' ) {
1617
+ if (req.body.type === 'layout') {
1615
1618
  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
- },
1619
+ {
1620
+ planoId: new mongoose.Types.ObjectId(req.body.planoId),
1621
+ floorId: new mongoose.Types.ObjectId(req.body.floorId),
1622
+ type: req.body.type,
1623
+ },
1624
+ {
1625
+ 'answers.$[].issues.$[].status': 'completed',
1626
+ 'answers.$[].issues.$[].Details.$[].status': 'agree',
1627
+ 'status': 'complete',
1628
+ },
1626
1629
  );
1627
1630
  } else {
1628
1631
  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
- },
1632
+ {
1633
+ planoId: new mongoose.Types.ObjectId(req.body.planoId),
1634
+ floorId: new mongoose.Types.ObjectId(req.body.floorId),
1635
+ fixtureId: new mongoose.Types.ObjectId(req.body.fixtureId),
1636
+ type: req.body.type,
1637
+ },
1638
+ {
1639
+ 'answers.$[].issues.$[].status': 'completed',
1640
+ 'answers.$[].issues.$[].Details.$[].status': 'agree',
1641
+ 'status': 'complete',
1642
+ },
1640
1643
  );
1641
1644
  }
1642
- res.sendSuccess( 'updated successfully' );
1643
- } catch ( e ) {
1644
- logger.error( { functionName: 'updateredostatus', error: e } );
1645
- return res.sendError( e, 500 );
1645
+ res.sendSuccess('updated successfully');
1646
+ } catch (e) {
1647
+ logger.error({ functionName: 'updateredostatus', error: e });
1648
+ return res.sendError(e, 500);
1646
1649
  }
1647
1650
  }
1648
1651
 
1649
1652
 
1650
- export async function updateGlobalComment( req, res ) {
1653
+ export async function updateGlobalComment(req, res) {
1651
1654
  try {
1652
1655
  let payload = {
1653
1656
  userId: req.user._id,
1654
1657
  userName: req.user.userName,
1655
1658
  comment: req.body.comment,
1656
1659
  responsetype: req.body.responsetype,
1657
- planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1658
- floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1660
+ planoId: new mongoose.Types.ObjectId(req.body.planoId),
1661
+ floorId: new mongoose.Types.ObjectId(req.body.floorId),
1659
1662
  taskType: req.body.taskType,
1660
1663
  clientId: req.body.clientId,
1661
1664
  taskId: req.body.taskId,
1662
1665
  };
1663
- await planoGlobalCommentService.create( payload );
1664
- await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoglobalcomments, payload );
1666
+ await planoGlobalCommentService.create(payload);
1667
+ await insertOpenSearchData(JSON.parse(process.env.OPENSEARCH).planoglobalcomments, payload);
1665
1668
 
1666
- res.sendSuccess( 'updated successfully' );
1667
- } catch ( e ) {
1668
- logger.error( { functionName: 'updateGlobalComment', error: e } );
1669
- return res.sendError( e, 500 );
1669
+ res.sendSuccess('updated successfully');
1670
+ } catch (e) {
1671
+ logger.error({ functionName: 'updateGlobalComment', error: e });
1672
+ return res.sendError(e, 500);
1670
1673
  }
1671
1674
  }
1672
- export async function getGlobalComment( req, res ) {
1675
+ export async function getGlobalComment(req, res) {
1673
1676
  try {
1674
1677
  // let layoutComment = await planoGlobalCommentService.find( {
1675
1678
  // planoId: new mongoose.Types.ObjectId( req.body.planoId ),
@@ -1678,147 +1681,147 @@ export async function getGlobalComment( req, res ) {
1678
1681
  // } );
1679
1682
 
1680
1683
  let taskId = [];
1681
- if ( req.body?.taskId ) {
1682
- taskId.push( new mongoose.Types.ObjectId( req.body.taskId ) );
1684
+ if (req.body?.taskId) {
1685
+ taskId.push(new mongoose.Types.ObjectId(req.body.taskId));
1683
1686
  }
1684
1687
 
1685
- if ( req.body?.refTaskId ) {
1686
- taskId.push( new mongoose.Types.ObjectId( req.body.refTaskId ) );
1688
+ if (req.body?.refTaskId) {
1689
+ taskId.push(new mongoose.Types.ObjectId(req.body.refTaskId));
1687
1690
  }
1688
1691
 
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 } } ),
1692
+ let layoutComment = await planoGlobalCommentService.find({
1693
+ planoId: new mongoose.Types.ObjectId(req.body.planoId),
1694
+ floorId: new mongoose.Types.ObjectId(req.body.floorId),
1695
+ ...(taskId.length && { taskId: { $in: taskId } }),
1693
1696
  taskType: req.body.taskType,
1694
- } );
1697
+ });
1695
1698
 
1696
- res.sendSuccess( layoutComment );
1697
- } catch ( e ) {
1698
- logger.error( { functionName: 'getGlobalComment', error: e } );
1699
- return res.sendError( e, 500 );
1699
+ res.sendSuccess(layoutComment);
1700
+ } catch (e) {
1701
+ logger.error({ functionName: 'getGlobalComment', error: e });
1702
+ return res.sendError(e, 500);
1700
1703
  }
1701
1704
  }
1702
1705
 
1703
- export async function getAllPlanoRevisions( req, res ) {
1706
+ export async function getAllPlanoRevisions(req, res) {
1704
1707
  try {
1705
1708
  const { clientId } = req.body;
1706
1709
 
1707
- if ( !clientId ) {
1708
- return res.sendError( 'Client Id is required', 400 );
1710
+ if (!clientId) {
1711
+ return res.sendError('Client Id is required', 400);
1709
1712
  }
1710
1713
 
1711
1714
  const revisions = await planoRevisionService.find(
1712
- { clientId },
1713
- { storeName: 1, storeId: 1, planoId: 1, floorId: 1, createdAt: 1 },
1715
+ { clientId },
1716
+ { storeName: 1, storeId: 1, planoId: 1, floorId: 1, createdAt: 1 },
1714
1717
  );
1715
1718
 
1716
- res.sendSuccess( revisions );
1717
- } catch ( e ) {
1718
- logger.error( { functionName: 'getAllPlanoRevisions', error: e } );
1719
- res.sendError( 'Failed to fetch plano revisions', 500 );
1719
+ res.sendSuccess(revisions);
1720
+ } catch (e) {
1721
+ logger.error({ functionName: 'getAllPlanoRevisions', error: e });
1722
+ res.sendError('Failed to fetch plano revisions', 500);
1720
1723
  }
1721
1724
  }
1722
1725
 
1723
- export async function createPlanoRevision( req, res ) {
1726
+ export async function createPlanoRevision(req, res) {
1724
1727
  try {
1725
1728
  const { storeName, storeId, clientId, planoId, floorId, floorData } = req.body;
1726
1729
 
1727
- if ( !storeName || !storeId || !clientId || !planoId || !floorId || !floorData ) {
1728
- return res.sendError( 'Missing required fields', 400 );
1730
+ if (!storeName || !storeId || !clientId || !planoId || !floorId || !floorData) {
1731
+ return res.sendError('Missing required fields', 400);
1729
1732
  }
1730
1733
 
1731
- const newRevision = await planoRevisionService.create( {
1734
+ const newRevision = await planoRevisionService.create({
1732
1735
  storeName,
1733
1736
  storeId,
1734
1737
  clientId,
1735
1738
  planoId,
1736
1739
  floorId,
1737
1740
  floorData,
1738
- } );
1741
+ });
1739
1742
 
1740
- res.sendSuccess( newRevision );
1741
- } catch ( e ) {
1742
- logger.error( { functionName: 'createPlanoRevision', error: e } );
1743
- res.sendError( 'Failed to create plano revision', 500 );
1743
+ res.sendSuccess(newRevision);
1744
+ } catch (e) {
1745
+ logger.error({ functionName: 'createPlanoRevision', error: e });
1746
+ res.sendError('Failed to create plano revision', 500);
1744
1747
  }
1745
1748
  }
1746
1749
 
1747
- export async function getPlanoRevisionById( req, res ) {
1750
+ export async function getPlanoRevisionById(req, res) {
1748
1751
  try {
1749
1752
  const { id } = req.params;
1750
1753
 
1751
- if ( !id ) {
1752
- return res.sendError( 'Revision ID is required', 400 );
1754
+ if (!id) {
1755
+ return res.sendError('Revision ID is required', 400);
1753
1756
  }
1754
1757
 
1755
1758
  const revision = await planoRevisionService.findOne(
1756
- { _id: id },
1759
+ { _id: id },
1757
1760
  );
1758
1761
 
1759
- if ( !revision ) {
1760
- return res.sendError( 'Plano revision not found', 404 );
1762
+ if (!revision) {
1763
+ return res.sendError('Plano revision not found', 404);
1761
1764
  }
1762
1765
 
1763
- res.sendSuccess( revision );
1764
- } catch ( e ) {
1765
- logger.error( { functionName: 'getPlanoRevisionById', error: e } );
1766
- res.sendError( 'Failed to fetch plano revision', 500 );
1766
+ res.sendSuccess(revision);
1767
+ } catch (e) {
1768
+ logger.error({ functionName: 'getPlanoRevisionById', error: e });
1769
+ res.sendError('Failed to fetch plano revision', 500);
1767
1770
  }
1768
1771
  }
1769
- export async function getRolloutFeedback( req, res ) {
1772
+ export async function getRolloutFeedback(req, res) {
1770
1773
  try {
1771
- const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'merchRollout', 'vmRollout' ];
1774
+ const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['merchRollout', 'vmRollout'];
1772
1775
  const filterByStatus = req.body.filterByStatus || [];
1773
1776
  const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
1774
1777
  const resultMap = {};
1775
1778
  const commentMap = {};
1776
- if ( req.body.redo ) {
1777
- let taskDetails = await planoTaskService.findOne( { taskId: req.body.taskId, fixtureId: req.body.fixtureId } );
1778
- if ( !taskDetails ) {
1779
+ if (req.body.redo) {
1780
+ let taskDetails = await planoTaskService.findOne({ taskId: req.body.taskId, fixtureId: req.body.fixtureId });
1781
+ if (!taskDetails) {
1779
1782
  req.body.taskId = req.body.refTaskId;
1780
1783
  }
1781
1784
  }
1782
1785
  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,
1786
+ taskTypes.map(async (type, index) => {
1787
+ const pipeline = buildPipelineByType(type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask, req.body.taskId);
1788
+
1789
+ let data = await planoTaskService.aggregate(pipeline);
1790
+ if (filterByApprovalStatus && filterByApprovalStatus !== '') {
1791
+ data.forEach((element) => {
1792
+ element.answers?.forEach((ans) => {
1793
+ ans.issues = ans.issues?.filter(
1794
+ (issue) => issue.Details && issue.Details.length > 0,
1796
1795
  );
1797
- } );
1798
- data = data.filter(
1799
- ( element ) => element.answers && element.answers.length > 0,
1796
+ });
1797
+ element.answers = element.answers?.filter(
1798
+ (ans) => ans.issues && ans.issues.length > 0,
1800
1799
  );
1801
- }
1800
+ });
1801
+ data = data.filter(
1802
+ (element) => element.answers && element.answers.length > 0,
1803
+ );
1804
+ }
1802
1805
 
1803
1806
 
1804
- resultMap[type] = data;
1807
+ resultMap[type] = data;
1805
1808
 
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
- }
1809
+ let taskId = [];
1810
+ if (req.body.taskId) {
1811
+ taskId.push(new mongoose.Types.ObjectId(req.body.taskId));
1812
+ }
1813
+ if (req.body.refTaskId) {
1814
+ taskId.push(new mongoose.Types.ObjectId(req.body.refTaskId));
1815
+ }
1813
1816
 
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
- } ),
1817
+ const comments = await planoGlobalCommentService.find({
1818
+ planoId: new mongoose.Types.ObjectId(req.body.planoId),
1819
+ floorId: new mongoose.Types.ObjectId(req.body.floorId),
1820
+ ...(taskId.length && { taskId: { $in: taskId } }),
1821
+ taskType: type,
1822
+ });
1823
+ commentMap[type] = comments;
1824
+ }),
1822
1825
  );
1823
1826
  const response = {
1824
1827
  merchRolloutData: resultMap['merchRollout'] || [],
@@ -1827,39 +1830,39 @@ export async function getRolloutFeedback( req, res ) {
1827
1830
  vmRolloutComment: commentMap['vmRollout'] || [],
1828
1831
  };
1829
1832
 
1830
- res.sendSuccess( response );
1831
- } catch ( e ) {
1832
- logger.error( { functionName: 'getRolloutFeedback', error: e } );
1833
- return res.sendError( e, 500 );
1833
+ res.sendSuccess(response);
1834
+ } catch (e) {
1835
+ logger.error({ functionName: 'getRolloutFeedback', error: e });
1836
+ return res.sendError(e, 500);
1834
1837
  }
1835
1838
  }
1836
1839
 
1837
1840
 
1838
- export async function getRolloutFeedbackv2( req, res ) {
1841
+ export async function getRolloutFeedbackv2(req, res) {
1839
1842
  try {
1840
- const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'merchRollout', 'vmRollout' ];
1843
+ const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : ['merchRollout', 'vmRollout'];
1841
1844
  const filterByStatus = req.body.filterByStatus || [];
1842
1845
  const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
1843
1846
  const resultMap = {};
1844
1847
  const commentMap = {};
1845
1848
  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
- } ) );
1849
+ taskTypes.map(async (type, index) => {
1850
+ const pipeline = pipelineStage(type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask);
1851
+ const data = await processedTaskService.aggregate(pipeline);
1852
+ resultMap[type] = data;
1853
+ }));
1851
1854
  const response = {
1852
1855
  merchRolloutData: resultMap['merchRollout'] || [],
1853
1856
  vmRolloutData: resultMap['vmRollout'] || [],
1854
1857
  merchRolloutComment: commentMap['merchRollout'] || [],
1855
1858
  vmRolloutComment: commentMap['vmRollout'] || [],
1856
1859
  };
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' ) ) {
1860
+ if (filterByStatus.length || filterByApprovalStatus) {
1861
+ let data = response[`${req.body.type}RolloutData`].filter((ele) => ele.storeFixtureList.length);
1862
+ if (filterByStatus.length == 1) {
1863
+ data = data.filter((type) => {
1864
+ let fixtureList = type.storeFixtureList.filter((ele) => filterByStatus.includes(ele.status));
1865
+ if (filterByStatus.includes('complete')) {
1863
1866
  return type.storeFixtureList.length == fixtureList.length;
1864
1867
  } else {
1865
1868
  return fixtureList.length;
@@ -1867,69 +1870,69 @@ export async function getRolloutFeedbackv2( req, res ) {
1867
1870
  },
1868
1871
  );
1869
1872
  }
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 ) {
1873
+ if (filterByApprovalStatus) {
1874
+ if (filterByApprovalStatus === 'pending') {
1875
+ data = data.filter((type) => {
1876
+ let fixtureList = type.storeFixtureList.filter((ele) => {
1877
+ if (ele.status === 'complete' && !ele.answers?.[0]?.issues.length && !ele.answers?.[0]?.status) {
1875
1878
  return true;
1876
1879
  } else {
1877
- return ele.answers?.some( ( ans ) =>
1878
- ans.issues?.some( ( issue ) =>
1879
- issue?.Details?.some( ( detail ) => detail.status === 'pending' ),
1880
+ return ele.answers?.some((ans) =>
1881
+ ans.issues?.some((issue) =>
1882
+ issue?.Details?.some((detail) => detail.status === 'pending'),
1880
1883
  ),
1881
1884
  );
1882
1885
  }
1883
- } );
1886
+ });
1884
1887
 
1885
1888
  return fixtureList.length;
1886
- } );
1889
+ });
1887
1890
  } 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 ) {
1891
+ data = data.filter((type) => {
1892
+ let fixtureList = type.storeFixtureList.filter((ele) => {
1893
+ if (ele.status === 'complete' && !ele.answers?.[0]?.issues.length && ele.answers?.[0]?.status) {
1891
1894
  return true;
1892
1895
  } else {
1893
- return ele.answers?.some( ( ans ) =>
1894
- ans.issues?.some( ( issue ) =>
1895
- issue?.Details?.some( ( detail ) => detail.status !== 'pending' ),
1896
+ return ele.answers?.some((ans) =>
1897
+ ans.issues?.some((issue) =>
1898
+ issue?.Details?.some((detail) => detail.status !== 'pending'),
1896
1899
  ),
1897
1900
  );
1898
1901
  }
1899
- } );
1902
+ });
1900
1903
 
1901
1904
  return fixtureList.length;
1902
- } );
1905
+ });
1903
1906
  }
1904
1907
  }
1905
1908
  response[`${req.body.type}RolloutData`] = data;
1906
1909
  }
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 } );
1910
+ response.vmRolloutData = await Promise.all(response.vmRolloutData.map(async (ele) => {
1911
+ ele.storeFixtureList = await Promise.all(ele.storeFixtureList.map(async (fixt) => {
1912
+ if (fixt?.FixtureData?.vmConfig?.length) {
1913
+ fixt.FixtureData.vmConfig = await Promise.all(fixt?.FixtureData?.vmConfig?.map(async (config) => {
1914
+ let vmDetails = await planoVmService.findOne({ _id: config.vmId }, { vmType: 1, vmName: 1 });
1912
1915
  return { ...config, vmType: vmDetails.vmType, vmName: vmDetails.vmName };
1913
- } ) );
1916
+ }));
1914
1917
  }
1915
1918
  return fixt;
1916
- } ) );
1919
+ }));
1917
1920
  return ele;
1918
- } ) );
1919
- res.sendSuccess( response );
1920
- } catch ( e ) {
1921
- logger.error( { functionName: 'getRolloutFeedbackv2', error: e } );
1922
- return res.sendError( e, 500 );
1921
+ }));
1922
+ res.sendSuccess(response);
1923
+ } catch (e) {
1924
+ logger.error({ functionName: 'getRolloutFeedbackv2', error: e });
1925
+ return res.sendError(e, 500);
1923
1926
  }
1924
1927
  }
1925
1928
 
1926
1929
 
1927
- function pipelineStage( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
1928
- let matchStage = [ {
1930
+ function pipelineStage(type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0) {
1931
+ let matchStage = [{
1929
1932
  $match: {
1930
1933
  'planoType': type,
1931
- 'planoId': new mongoose.Types.ObjectId( planoId ),
1932
- 'floorId': new mongoose.Types.ObjectId( floorId ),
1934
+ 'planoId': new mongoose.Types.ObjectId(planoId),
1935
+ 'floorId': new mongoose.Types.ObjectId(floorId),
1933
1936
  },
1934
1937
  },
1935
1938
 
@@ -1957,7 +1960,7 @@ function pipelineStage( type, planoId, floorId, filterByStatus, filterByApproval
1957
1960
  $match: {
1958
1961
  $expr: {
1959
1962
  $and: [
1960
- { $eq: [ '$taskId', '$$taskId' ] },
1963
+ { $eq: ['$taskId', '$$taskId'] },
1961
1964
  ],
1962
1965
  },
1963
1966
  },
@@ -1981,7 +1984,7 @@ function pipelineStage( type, planoId, floorId, filterByStatus, filterByApproval
1981
1984
  {
1982
1985
  $match: {
1983
1986
  $expr: {
1984
- $eq: [ '$taskId', '$$taskId' ],
1987
+ $eq: ['$taskId', '$$taskId'],
1985
1988
  },
1986
1989
  },
1987
1990
  },
@@ -1999,7 +2002,7 @@ function pipelineStage( type, planoId, floorId, filterByStatus, filterByApproval
1999
2002
  let: { fixtureId: '$planoData.fixtureId' },
2000
2003
  pipeline: [
2001
2004
  {
2002
- $match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
2005
+ $match: { $expr: { $eq: ['$_id', '$$fixtureId'] } },
2003
2006
  },
2004
2007
  ],
2005
2008
  as: 'FixtureData',
@@ -2014,7 +2017,7 @@ function pipelineStage( type, planoId, floorId, filterByStatus, filterByApproval
2014
2017
  let: { fixtureId: '$FixtureData._id' },
2015
2018
  pipeline: [
2016
2019
  {
2017
- $match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
2020
+ $match: { $expr: { $eq: ['$fixtureId', '$$fixtureId'] } },
2018
2021
  },
2019
2022
  ],
2020
2023
  as: 'Fixtureshelves',
@@ -2049,16 +2052,16 @@ function pipelineStage( type, planoId, floorId, filterByStatus, filterByApproval
2049
2052
  $and: [
2050
2053
  {
2051
2054
  $or: [
2052
- { $eq: [ '$redoStatus', true ] },
2055
+ { $eq: ['$redoStatus', true] },
2053
2056
  {
2054
2057
  $and: [
2055
- { $eq: [ '$redoStatus', false ] },
2056
- { $eq: [ '$checklistStatus', 'submit' ] },
2058
+ { $eq: ['$redoStatus', false] },
2059
+ { $eq: ['$checklistStatus', 'submit'] },
2057
2060
  ],
2058
2061
  },
2059
2062
  ],
2060
2063
  },
2061
- { $ne: [ { $ifNull: [ '$FixtureData.fixtureName', null ] }, null ] },
2064
+ { $ne: [{ $ifNull: ['$FixtureData.fixtureName', null] }, null] },
2062
2065
  // { $gt: [ { $size: { $ifNull: [ '$FixtureData' ] } }, 0 ] },
2063
2066
  // { $gt: [ { $size: { $ifNull: [ '$FixtureData.shelfConfig', [] ] } }, 0 ] },
2064
2067
  ],
@@ -2105,3 +2108,48 @@ function pipelineStage( type, planoId, floorId, filterByStatus, filterByApproval
2105
2108
 
2106
2109
  return pipeline;
2107
2110
  }
2111
+
2112
+
2113
+ export async function getPlanoStoreVideoPageParams(req, res) {
2114
+ try {
2115
+ const { storeId } = req.body;
2116
+
2117
+ if (!storeId) {
2118
+ return res.sendError('Store ID Missing.', 400);
2119
+ }
2120
+
2121
+ const checkListRes = await planoStaticService.findOne({ type: 'storeVideoChecklist' }, { checklistIds: 1 });
2122
+
2123
+ if (checkListRes?.checklistIds?.length <= 0) {
2124
+ return res.sendError('No checklist ids found', 400);
2125
+ }
2126
+
2127
+ const checklistData = await processedChecklistService.findOne(
2128
+ {
2129
+ sourceCheckList_id: {
2130
+ $in: checkListRes?.checklistIds ?? [],
2131
+ },
2132
+ checklistStatus: "submit",
2133
+ store_id: storeId,
2134
+ checkListType: "custom",
2135
+ }, {}, { sort: { _id: -1 } }
2136
+ );
2137
+
2138
+ if (!checklistData) {
2139
+ return res.sendError('No checklist data found', 400);
2140
+ }
2141
+
2142
+ const response = {
2143
+ storeId: storeId,
2144
+ ChecklistDate: checklistData?.date_string,
2145
+ checklistType: checklistData?.checkListType,
2146
+ checklistStatus: checklistData?.checklistStatus,
2147
+ sourceCheckList_id: checklistData?.sourceCheckList_id,
2148
+ }
2149
+
2150
+ res.sendSuccess(response);
2151
+ } catch (e) {
2152
+ logger.error({ functionName: 'getPlanoStoreVideoPageParams', error: e });
2153
+ res.sendError('Failed to fetch plano store video page params', 500);
2154
+ }
2155
+ }