tango-app-api-store-builder 1.0.0-beta-141 → 1.0.0-beta-143

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-141",
3
+ "version": "1.0.0-beta-143",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@ export async function getplanoFeedback( req, res ) {
26
26
  console.log( taskTypes );
27
27
  await Promise.all(
28
28
  taskTypes.map( async ( type, index ) => {
29
- const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus );
29
+ const pipeline = buildPipelineByType( type, req.body.planoId, req.body.floorId, filterByStatus, filterByApprovalStatus, req.body.showtask );
30
30
 
31
31
  const data = await planoTaskService.aggregate( pipeline );
32
32
  console.log( '-------', data );
@@ -56,7 +56,7 @@ export async function getplanoFeedback( req, res ) {
56
56
  return res.sendError( e, 500 );
57
57
  }
58
58
  }
59
- function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByApprovalStatus ) {
59
+ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByApprovalStatus, showtask ) {
60
60
  console.log( type, planoId, floorId, filterByStatus );
61
61
  const matchStage = {
62
62
  $match: {
@@ -67,7 +67,7 @@ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByAp
67
67
  },
68
68
  };
69
69
 
70
- const taskLookup = {
70
+ let taskLookup = {
71
71
  $lookup: {
72
72
  from: 'processedtasks',
73
73
  let: { taskId: '$taskId' },
@@ -104,6 +104,34 @@ function buildPipelineByType( type, planoId, floorId, filterByStatus, filterByAp
104
104
  as: 'taskData',
105
105
  },
106
106
  };
107
+ if ( showtask ) {
108
+ taskLookup = {
109
+ $lookup: {
110
+ from: 'processedtasks',
111
+ let: { taskId: '$taskId' },
112
+ pipeline: [
113
+ {
114
+ $match: {
115
+ $expr: {
116
+ $and: [
117
+ { $eq: [ '$_id', '$$taskId' ] },
118
+ ],
119
+ },
120
+ },
121
+ },
122
+ {
123
+ $project: {
124
+ userName: 1,
125
+ createdAt: 1,
126
+ createdByName: 1,
127
+ submitTime_string: 1,
128
+ },
129
+ },
130
+ ],
131
+ as: 'taskData',
132
+ },
133
+ };
134
+ }
107
135
 
108
136
  const unwindTask = { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: false } };
109
137
 
@@ -418,7 +446,9 @@ export async function updateStorePlano( req, res ) {
418
446
  } );
419
447
 
420
448
  await floorService.updateOne( { _id: new mongoose.Types.ObjectId( floorId ) },
421
- { layoutPolygon: layoutPolygon } );
449
+ { layoutPolygon: layoutPolygon,
450
+ ...( req.body?.editMode === true && { isEdited: true } ),
451
+ } );
422
452
 
423
453
  const currentWallFixtures = data.layoutPolygon.flatMap( ( element ) =>
424
454
  ( element.fixtures || [] ).map( ( fixture ) => fixture ),
@@ -8593,6 +8593,7 @@ export async function migrateCrestv1( req, res ) {
8593
8593
  vmName: vm.name + ' - 1',
8594
8594
  vmHeight: configData1.vmHeightmm,
8595
8595
  vmWidth: configData1.vmWidthmm,
8596
+ ...( vm?.preview_image_url && { preview_image_url: vm?.preview_image_url } ),
8596
8597
  },
8597
8598
  {
8598
8599
  startYPosition: configData2.startShelf,
@@ -8602,11 +8603,39 @@ export async function migrateCrestv1( req, res ) {
8602
8603
  vmName: vm.name + ' - 2',
8603
8604
  vmHeight: configData2.vmHeightmm,
8604
8605
  vmWidth: configData2.vmWidthmm,
8606
+ ...( vm?.preview_image_url2 && { preview_image_url: vm?.preview_image_url2 } ),
8605
8607
  },
8606
8608
  ];
8607
8609
  } );
8608
8610
 
8609
8611
  const vmTemplate = await Promise.all( vmConfig.map( async ( vmTemplate, k ) => {
8612
+ let attachmentId = '';
8613
+ let imgPath = '';
8614
+ let imageMeta = null;
8615
+ if ( vmTemplate?.preview_image_url ) {
8616
+ const parsedUrl = new URL( vmTemplate.preview_image_url );
8617
+ attachmentId = parsedUrl.searchParams.get( 'attachment_id' );
8618
+
8619
+ const isVmImageExist = await planoVmService.findOne( { crestImageId: attachmentId } );
8620
+
8621
+ if ( !isVmImageExist ) {
8622
+ const vmImageData = await fetchVmImage( attachmentId );
8623
+
8624
+ imageMeta = await getImageMetadata( vmImageData );
8625
+
8626
+ const params = {
8627
+ Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
8628
+ Key: `crestVms/`,
8629
+ fileName: `${attachmentId}.${imageMeta.fileExtension}`,
8630
+ ContentType: imageMeta.contentType,
8631
+ body: vmImageData,
8632
+ };
8633
+
8634
+ const imgUpload = await fileUpload( params );
8635
+
8636
+ imgPath = imgUpload.Key;
8637
+ }
8638
+ }
8610
8639
  const vmInsertData = {
8611
8640
  clientId: '11',
8612
8641
  vmName: vmTemplate.vmName,
@@ -8623,6 +8652,11 @@ export async function migrateCrestv1( req, res ) {
8623
8652
  vmType: 'LKVM',
8624
8653
  };
8625
8654
 
8655
+ if ( attachmentId && imgPath ) {
8656
+ vmInsertData.crestImageId = attachmentId;
8657
+ vmInsertData.vmImageUrl = imgPath;
8658
+ }
8659
+
8626
8660
  const vmIdentifier = `vm${k+1}=${vmTemplate.vmName}+${vmTemplate.vmHeight}+${vmTemplate.vmWidth}+${vmTemplate.startYPosition}+${vmTemplate.endYPosition}+${vmTemplate.xZone}`;
8627
8661
 
8628
8662
  mapKey += ','+vmIdentifier;
@@ -2655,7 +2655,7 @@ export async function storeFixturesv2( req, res ) {
2655
2655
  planograms.map( async ( planogram ) => {
2656
2656
  const floors = await storeBuilderService.find(
2657
2657
  { planoId: planogram._id },
2658
- { floorName: 1, layoutPolygon: 1, planoId: 1 },
2658
+ { floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1 },
2659
2659
  );
2660
2660
 
2661
2661
  const floorsWithFixtures = await Promise.all(
@@ -2669,7 +2669,7 @@ export async function storeFixturesv2( req, res ) {
2669
2669
  floorId: floor._id,
2670
2670
  associatedElementType: element.elementType,
2671
2671
  associatedElementNumber: element.elementNumber,
2672
- }, { shelfcount: 0 }, { fixtureNumber: 1 } );
2672
+ }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
2673
2673
 
2674
2674
  const fixturesWithStatus = await Promise.all(
2675
2675
  fixtures.map( async ( fixture ) => {
@@ -2762,13 +2762,14 @@ export async function storeFixturesv2( req, res ) {
2762
2762
  } ),
2763
2763
  );
2764
2764
 
2765
- const centerFixtures = await storeFixtureService.find( {
2765
+ const centerFixtures = await storeFixtureService.findAndSort( {
2766
2766
  floorId: floor._id,
2767
2767
  $and: [
2768
2768
  { associatedElementType: { $exists: false } },
2769
2769
  { associatedElementNumber: { $exists: false } },
2770
2770
  ],
2771
- } );
2771
+ }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
2772
+
2772
2773
 
2773
2774
  const centerFixturesWithStatus = await Promise.all(
2774
2775
  centerFixtures.map( async ( fixture ) => {
@@ -2838,7 +2839,7 @@ export async function storeFixturesv2( req, res ) {
2838
2839
  return {
2839
2840
  ...fixture.toObject(),
2840
2841
  status: fixtureStatus,
2841
- shelfCount: shelves.shelves,
2842
+ shelfCount: shelves.length,
2842
2843
  productCount: productCount,
2843
2844
  vmCount: vmCount,
2844
2845
  shelfConfig: shelfDetails,
@@ -2977,7 +2978,7 @@ export async function storeFixturesTaskv2( req, res ) {
2977
2978
  planograms.map( async ( planogram ) => {
2978
2979
  const floors = await storeBuilderService.find(
2979
2980
  { planoId: planogram._id },
2980
- { floorName: 1, layoutPolygon: 1, planoId: 1 },
2981
+ { floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1 },
2981
2982
  );
2982
2983
 
2983
2984
  const floorsWithFixtures = await Promise.all(
@@ -2992,7 +2993,7 @@ export async function storeFixturesTaskv2( req, res ) {
2992
2993
  floorId: floor._id,
2993
2994
  associatedElementType: element.elementType,
2994
2995
  associatedElementNumber: element.elementNumber,
2995
- }, { shelfcount: 0 }, { fixtureNumber: 1 } );
2996
+ }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
2996
2997
 
2997
2998
  const fixturesWithStatus = await Promise.all(
2998
2999
  fixtures.map( async ( fixture ) => {
@@ -3086,13 +3087,13 @@ export async function storeFixturesTaskv2( req, res ) {
3086
3087
  } ),
3087
3088
  );
3088
3089
 
3089
- const centerFixtures = await storeFixtureService.find( {
3090
+ const centerFixtures = await storeFixtureService.findAndSort( {
3090
3091
  floorId: floor._id,
3091
3092
  $and: [
3092
3093
  { associatedElementType: { $exists: false } },
3093
3094
  { associatedElementNumber: { $exists: false } },
3094
3095
  ],
3095
- } );
3096
+ }, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
3096
3097
 
3097
3098
  const centerFixturesWithStatus = await Promise.all(
3098
3099
  centerFixtures.map( async ( fixture ) => {
@@ -3161,7 +3162,7 @@ export async function storeFixturesTaskv2( req, res ) {
3161
3162
  return {
3162
3163
  ...fixture.toObject(),
3163
3164
  status: compliance?.status ? compliance.status : '',
3164
- shelfCount: shelves.shelves,
3165
+ shelfCount: shelves.length,
3165
3166
  productCount: productCount,
3166
3167
  disabled: req?.body?.redo ? disabled : false,
3167
3168
  vmCount: vmCount,
@@ -3343,7 +3344,7 @@ export async function planoList( req, res ) {
3343
3344
  $and: [
3344
3345
  { $eq: [ '$planoId', '$$plano' ] },
3345
3346
  // { $in: [ '$taskId', pendingDetails.map( ( ele ) => ele.taskId ) ] },
3346
- { $eq: [ '$taskType', 'initial' ] },
3347
+ // { $eq: [ '$taskType', 'initial' ] },
3347
3348
  ],
3348
3349
  },
3349
3350
  },
@@ -3361,13 +3362,28 @@ export async function planoList( req, res ) {
3361
3362
  in: {
3362
3363
  $concatArrays: [
3363
3364
  '$$value',
3364
- { $ifNull: [ '$$this.issues', [] ] },
3365
+ {
3366
+ $reduce: {
3367
+ input: { $ifNull: [ '$$this.issues', [] ] },
3368
+ initialValue: [],
3369
+ in: {
3370
+ $concatArrays: [
3371
+ '$$value',
3372
+ { $ifNull: [ '$$this.Details', [] ] },
3373
+ ],
3374
+ },
3375
+ },
3376
+ },
3365
3377
  ],
3366
3378
  },
3367
3379
  },
3368
3380
  },
3369
- as: 'issue',
3370
- in: { $eq: [ '$$issue.status', 'pending' ] },
3381
+ as: 'detail',
3382
+ in: {
3383
+ $or: [
3384
+ { $eq: [ '$$detail.status', 'pending' ] },
3385
+ ],
3386
+ },
3371
3387
  },
3372
3388
  },
3373
3389
  },
@@ -3738,7 +3754,7 @@ export async function planoList( req, res ) {
3738
3754
  {
3739
3755
  $match: {
3740
3756
  taskId: { $in: pendingDetails.map( ( ele ) => ele.taskId ) },
3741
- taskType: 'initial',
3757
+ // taskType: 'initial',
3742
3758
  },
3743
3759
  },
3744
3760
  {
@@ -3753,13 +3769,28 @@ export async function planoList( req, res ) {
3753
3769
  in: {
3754
3770
  $concatArrays: [
3755
3771
  '$$value',
3756
- { $ifNull: [ '$$this.issues', [] ] },
3772
+ {
3773
+ $reduce: {
3774
+ input: { $ifNull: [ '$$this.issues', [] ] },
3775
+ initialValue: [],
3776
+ in: {
3777
+ $concatArrays: [
3778
+ '$$value',
3779
+ { $ifNull: [ '$$this.Details', [] ] },
3780
+ ],
3781
+ },
3782
+ },
3783
+ },
3757
3784
  ],
3758
3785
  },
3759
3786
  },
3760
3787
  },
3761
- as: 'issue',
3762
- in: { $eq: [ '$$issue.status', 'pending' ] },
3788
+ as: 'detail',
3789
+ in: {
3790
+ $or: [
3791
+ { $eq: [ '$$detail.status', 'pending' ] },
3792
+ ],
3793
+ },
3763
3794
  },
3764
3795
  },
3765
3796
  },
@@ -15,6 +15,7 @@ import mongoose from 'mongoose';
15
15
  import * as floorService from '../service/storeBuilder.service.js';
16
16
  import * as planoStaticService from '../service/planoStaticData.service.js';
17
17
  import * as assignService from '../service/assignService.service.js';
18
+ import * as storeBuilderService from '../service/storeBuilder.service.js';
18
19
 
19
20
 
20
21
  dayjs.extend( timeZone );
@@ -112,6 +113,9 @@ async function createUser( data ) {
112
113
 
113
114
  export async function createTask( req, res ) {
114
115
  try {
116
+ if ( req.body?.floorId ) {
117
+ await storeBuilderService.updateOne( { _id: new mongoose.Types.ObjectId( req.body?.floorId ) }, { isEdited: false } );
118
+ }
115
119
  let scheduleEndTime = '11:59 PM';
116
120
  if ( req.body?.redo ) {
117
121
  if ( !req.body.taskId ) {