tango-app-api-store-builder 1.0.0-beta-206 → 1.0.0-beta-208

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-store-builder",
3
- "version": "1.0.0-beta-206",
3
+ "version": "1.0.0-beta-208",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -32,7 +32,7 @@
32
32
  "path": "^0.12.7",
33
33
  "selenium-webdriver": "^4.31.0",
34
34
  "sharp": "^0.34.1",
35
- "tango-api-schema": "^2.3.32",
35
+ "tango-api-schema": "^2.4.3",
36
36
  "tango-app-api-middleware": "3.1.48",
37
37
  "url": "^0.11.4",
38
38
  "winston": "^3.17.0",
@@ -16,6 +16,7 @@ import * as planoTaskService from '../service/planoTask.service.js';
16
16
  import * as planoGlobalCommentService from '../service/planoGlobalComment.service.js';
17
17
  import mongoose from 'mongoose';
18
18
  import * as planoRevisionService from '../service/planoRevision.service.js';
19
+ import * as planoVmDuplicateService from '../service/planoVmDuplicate.service.js';
19
20
  export async function getplanoFeedback( req, res ) {
20
21
  try {
21
22
  const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'layout', 'fixture', 'vm' ];
@@ -71,6 +72,62 @@ export async function getplanoFeedback( req, res ) {
71
72
  return res.sendError( e, 500 );
72
73
  }
73
74
  }
75
+ export async function getplanoFeedbackv1( req, res ) {
76
+ try {
77
+ const taskTypes = req.body.filterByTask && req.body.filterByTask.length > 0 ? req.body.filterByTask : [ 'layout', 'fixture', 'vm' ];
78
+ const filterByStatus = req.body.filterByStatus || [];
79
+ const filterByApprovalStatus = req.body.filterByApprovalStatus || '';
80
+ const resultMap = {};
81
+ const commentMap = {};
82
+ await Promise.all(
83
+ taskTypes.map( async ( type, index ) => {
84
+ const pipeline = buildPipelineByType1( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
85
+
86
+ let data = await planoTaskService.aggregate( pipeline );
87
+ if ( filterByApprovalStatus && filterByApprovalStatus !== '' ) {
88
+ data.forEach( ( element ) => {
89
+ element.answers?.forEach( ( ans ) => {
90
+ ans.issues = ans.issues?.filter(
91
+ ( issue ) => issue.Details && issue.Details.length > 0,
92
+ );
93
+ } );
94
+ element.answers = element.answers?.filter(
95
+ ( ans ) => ans.issues && ans.issues.length > 0,
96
+ );
97
+ } );
98
+ data = data.filter(
99
+ ( element ) => element.answers && element.answers.length > 0,
100
+ );
101
+ }
102
+
103
+
104
+ resultMap[type] = data;
105
+
106
+ const comments = await planoGlobalCommentService.find( {
107
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
108
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
109
+ taskType: type,
110
+ } );
111
+ commentMap[type] = comments;
112
+ } ),
113
+ );
114
+
115
+ const response = {
116
+ layoutData: resultMap['layout'] || [],
117
+ fixtureData: resultMap['fixture'] || [],
118
+ VmData: resultMap['vm'] || [],
119
+ layoutComment: commentMap['layout'] || [],
120
+ fixtureComment: commentMap['fixture'] || [],
121
+ vmComment: commentMap['vm'] || [],
122
+ };
123
+
124
+ res.sendSuccess( response );
125
+ } catch ( e ) {
126
+ logger.error( { functionName: 'getplanoFeedback', error: e, message: req.body } );
127
+ return res.sendError( e, 500 );
128
+ }
129
+ }
130
+
74
131
  function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
75
132
  console.log( type, planoId, floorId, filterByStatus );
76
133
  const matchStage = {
@@ -314,6 +371,249 @@ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByAp
314
371
  return pipeline;
315
372
  }
316
373
 
374
+ function buildPipelineByType1( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask, taskId = 0 ) {
375
+ console.log( type, planoId, floorId, filterByStatus );
376
+ const matchStage = {
377
+ $match: {
378
+ planoId: new mongoose.Types.ObjectId( planoId ),
379
+ floorId: new mongoose.Types.ObjectId( floorId ),
380
+ type: type,
381
+ ...( taskId && { taskId: new mongoose.Types.ObjectId( taskId ) } ),
382
+ ...( filterByStatus?.length ? { status: { $in: filterByStatus } } : {} ),
383
+ },
384
+ };
385
+
386
+
387
+ const conditionalMatchExpr = showtask ?
388
+ {
389
+ $eq: [ '$_id', '$$taskId' ],
390
+ } :
391
+ {
392
+ $and: [
393
+ {
394
+ $eq: [ '$_id', '$$taskId' ],
395
+ },
396
+ {
397
+ $or: [
398
+ { $eq: [ '$redoStatus', true ] },
399
+ {
400
+ $and: [
401
+ { $eq: [ '$redoStatus', false ] },
402
+ { $eq: [ '$checklistStatus', 'submit' ] },
403
+ ],
404
+ },
405
+ ],
406
+ },
407
+ ],
408
+ };
409
+
410
+ const taskLookup = {
411
+ $lookup: {
412
+ from: 'processedtasks',
413
+ let: { taskId: '$taskId' },
414
+ pipeline: [
415
+ {
416
+ $match: {
417
+ $expr: conditionalMatchExpr,
418
+ },
419
+ },
420
+ {
421
+ $project: {
422
+ userName: 1,
423
+ createdAt: 1,
424
+ createdByName: 1,
425
+ submitTime_string: 1,
426
+ },
427
+ },
428
+ ],
429
+ as: 'taskData',
430
+ },
431
+ };
432
+
433
+
434
+ const unwindTask = { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: false } };
435
+
436
+ const commonLookups = type === 'layout' ? [] : [
437
+ {
438
+ $lookup: {
439
+ from: 'storefixtureduplicates',
440
+ let: { fixtureId: '$fixtureId' },
441
+ pipeline: [
442
+ {
443
+ $match: { $expr: { $eq: [ '$_id', '$$fixtureId' ] } },
444
+ },
445
+ ],
446
+ as: 'FixtureData',
447
+ },
448
+ },
449
+ {
450
+ $unwind: { path: '$FixtureData', preserveNullAndEmptyArrays: true },
451
+ },
452
+ {
453
+ $lookup: {
454
+ from: 'fixtureshelfduplicates',
455
+ let: { fixtureId: '$FixtureData._id' },
456
+ pipeline: [
457
+ {
458
+ $match: { $expr: { $eq: [ '$fixtureId', '$$fixtureId' ] } },
459
+ },
460
+ ],
461
+ as: 'Fixtureshelves',
462
+ },
463
+ },
464
+
465
+ {
466
+ $set: {
467
+ 'FixtureData.shelfConfig': '$Fixtureshelves',
468
+ },
469
+ },
470
+ ];
471
+
472
+ const vmStages = [ 'vm', 'vmRollout' ].includes( type ) ? [
473
+ {
474
+ $unwind: { path: '$FixtureData.vmConfig', preserveNullAndEmptyArrays: true },
475
+ },
476
+ {
477
+ $lookup: {
478
+ from: 'planovmdetailduplicates',
479
+ let: { vmId: '$FixtureData.vmConfig.vmId' },
480
+ pipeline: [
481
+ {
482
+ $match: { $expr: { $eq: [ '$_id', '$$vmId' ] } },
483
+ },
484
+ {
485
+ $project: { vmName: 1, vmType: 1 },
486
+ },
487
+ ],
488
+ as: 'vmDetails',
489
+ },
490
+ },
491
+ {
492
+ $unwind: { path: '$vmDetails', preserveNullAndEmptyArrays: true },
493
+ },
494
+ {
495
+ $set: {
496
+ 'FixtureData.vmConfig.vmName': '$vmDetails.vmName',
497
+ 'FixtureData.vmConfig.vmType': '$vmDetails.vmType',
498
+ },
499
+ },
500
+ {
501
+ $group: {
502
+ _id: '$_id',
503
+ answers: { $first: '$answers' },
504
+ createdAt: { $first: '$createdAt' },
505
+ date_iso: { $first: '$date_iso' },
506
+ date_string: { $first: '$date_string' },
507
+ fixtureId: { $first: '$fixtureId' },
508
+ floorId: { $first: '$floorId' },
509
+ planoId: { $first: '$planoId' },
510
+ status: { $first: '$status' },
511
+ taskType: { $first: '$taskType' },
512
+ type: { $first: '$type' },
513
+ taskId: { $first: '$taskId' },
514
+ taskData: { $first: '$taskData' },
515
+ baseFixtureData: { $first: '$FixtureData' },
516
+ collectedVmConfigs: {
517
+ $push: {
518
+ $cond: [
519
+ { $ne: [ '$FixtureData.vmConfig', {} ] },
520
+ '$FixtureData.vmConfig',
521
+ '$$REMOVE',
522
+ ],
523
+ },
524
+ },
525
+ },
526
+ },
527
+ {
528
+ $set: {
529
+ FixtureData: {
530
+ $mergeObjects: [
531
+ '$baseFixtureData',
532
+ {
533
+ vmConfig: {
534
+ $reduce: {
535
+ input: '$collectedVmConfigs',
536
+ initialValue: [],
537
+ in: {
538
+ $cond: [
539
+ { $isArray: '$$this' },
540
+ { $concatArrays: [ '$$value', '$$this' ] },
541
+ { $concatArrays: [ '$$value', [ '$$this' ] ] },
542
+ ],
543
+ },
544
+ },
545
+ },
546
+ },
547
+ ],
548
+ },
549
+ },
550
+ },
551
+ ] : [];
552
+
553
+
554
+ let pipeline = [
555
+ matchStage,
556
+ taskLookup,
557
+ unwindTask,
558
+ ...commonLookups,
559
+ ...vmStages,
560
+ { $sort: { _id: -1 } },
561
+ ];
562
+ if ( filterByApprovalStatus && filterByApprovalStatus != '' ) {
563
+ pipeline = [];
564
+ pipeline.push( matchStage );
565
+ pipeline.push(
566
+ {
567
+ $addFields: {
568
+ answers: {
569
+ $map: {
570
+ input: '$answers',
571
+ as: 'ans',
572
+ in: {
573
+ $mergeObjects: [
574
+ '$$ans',
575
+ {
576
+ issues: {
577
+ $map: {
578
+ input: '$$ans.issues',
579
+ as: 'issue',
580
+ in: {
581
+ $mergeObjects: [
582
+ '$$issue',
583
+ {
584
+ Details: {
585
+ $filter: {
586
+ input: '$$issue.Details',
587
+ as: 'detail',
588
+ cond: filterByApprovalStatus === 'pending' ?
589
+ { $eq: [ '$$detail.status', 'pending' ] } :
590
+ { $ne: [ '$$detail.status', 'pending' ] },
591
+ },
592
+ },
593
+ },
594
+ ],
595
+ },
596
+ },
597
+ },
598
+ },
599
+ ],
600
+ },
601
+ },
602
+ },
603
+ },
604
+ },
605
+ );
606
+ pipeline.push( taskLookup );
607
+ pipeline.push( unwindTask );
608
+ pipeline.push( ...commonLookups );
609
+ pipeline.push( ...vmStages );
610
+ pipeline.push( { $sort: { _id: -1 } } );
611
+ }
612
+
613
+
614
+ return pipeline;
615
+ }
616
+
317
617
  export async function getStoreFixturesfeedback( req, res ) {
318
618
  try {
319
619
  let query = [];
@@ -536,6 +836,19 @@ export async function fixtureVMList( req, res ) {
536
836
  return res.sendError( e, 500 );
537
837
  }
538
838
  }
839
+
840
+ export async function fixtureVMListv1( req, res ) {
841
+ try {
842
+ let findData = await planoVmDuplicateService.find( { clientId: req.query.clientId } );
843
+ if ( findData.length === 0 ) {
844
+ return res.sendError( 'nodata found', 204 );
845
+ }
846
+ res.sendSuccess( findData );
847
+ } catch ( e ) {
848
+ logger.error( { functionName: 'fixtureVMListv1', error: e } );
849
+ return res.sendError( e, 500 );
850
+ }
851
+ }
539
852
  export async function updateFixtureStatus( req, res ) {
540
853
  try {
541
854
  let comments = {
@@ -933,7 +1246,7 @@ export async function updateGlobalComment( req, res ) {
933
1246
  return res.sendError( e, 500 );
934
1247
  }
935
1248
  }
936
- export async function getGlobalComment(req, res) {
1249
+ export async function getGlobalComment( req, res ) {
937
1250
  try {
938
1251
  // let layoutComment = await planoGlobalCommentService.find( {
939
1252
  // planoId: new mongoose.Types.ObjectId( req.body.planoId ),
@@ -942,25 +1255,25 @@ export async function getGlobalComment(req, res) {
942
1255
  // } );
943
1256
 
944
1257
  let taskId = [];
945
- if (req.body?.taskId) {
946
- taskId.push(new mongoose.Types.ObjectId(req.body.taskId));
1258
+ if ( req.body?.taskId ) {
1259
+ taskId.push( new mongoose.Types.ObjectId( req.body.taskId ) );
947
1260
  }
948
1261
 
949
- if (req.body?.refTaskId) {
950
- taskId.push(new mongoose.Types.ObjectId(req.body.refTaskId));
1262
+ if ( req.body?.refTaskId ) {
1263
+ taskId.push( new mongoose.Types.ObjectId( req.body.refTaskId ) );
951
1264
  }
952
-
953
- let layoutComment = await planoGlobalCommentService.find({
954
- planoId: new mongoose.Types.ObjectId(req.body.planoId),
955
- floorId: new mongoose.Types.ObjectId(req.body.floorId),
956
- ...(taskId.length && { taskId: { $in: taskId } }),
1265
+
1266
+ let layoutComment = await planoGlobalCommentService.find( {
1267
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
1268
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
1269
+ ...( taskId.length && { taskId: { $in: taskId } } ),
957
1270
  taskType: req.body.taskType,
958
- });
1271
+ } );
959
1272
 
960
- res.sendSuccess(layoutComment);
961
- } catch (e) {
962
- logger.error({ functionName: 'getGlobalComment', error: e });
963
- return res.sendError(e, 500);
1273
+ res.sendSuccess( layoutComment );
1274
+ } catch ( e ) {
1275
+ logger.error( { functionName: 'getGlobalComment', error: e } );
1276
+ return res.sendError( e, 500 );
964
1277
  }
965
1278
  }
966
1279