tango-app-api-store-builder 1.0.0-beta-112 → 1.0.0-beta-114

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.
@@ -14,6 +14,7 @@ import * as processedTaskService from '../service/processedTaskservice.js';
14
14
  // import * as planoComplianceService from '../service/planoCompliance.service.js';
15
15
  // import * as planoTaskComplianceService from '../service/planoTask.service.js';
16
16
  // import * as planoQrConversionRequestService from '../service/planoQrConversionRequest.service.js';
17
+ import * as planoProductCategoryService from '../service/planoproductCategory.service.js';
17
18
  import * as fixtureConfigService from '../service/fixtureConfig.service.js';
18
19
  import * as fixtureLibraryService from '../service/planoLibrary.service.js';
19
20
  import mongoose from 'mongoose';
@@ -2322,62 +2323,62 @@ export async function updateVmData( req, res ) {
2322
2323
 
2323
2324
  // import https from 'https';
2324
2325
  // async function scrapeCrest() {
2325
- // const storeIds = [ 'LKST2567' ];
2326
+ // const storeIds = [ 'LKST494' ];
2326
2327
  // const apiUrl = 'https://api.getcrest.ai/api/ms_shelfsensei/layout/';
2327
- // const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQ5MTEyNDYxLCJpYXQiOjE3NDkxMDg4NjEsImp0aSI6ImYzMDhmN2M3YzBlYjQ4NWU5YjVmNTJjZjRjNTkxNTM2IiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.zXRf9dgtrIhjnUJSKyLqbB8FRnTT0a-hOBos0gvKsJY';
2328
+ // const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQ5NzkxNzUzLCJpYXQiOjE3NDk3ODgxNTMsImp0aSI6IjhmNDY4MTY0NTY5NTQ0YTU4OWJjMDU2NmU0ZGE0ZjI3IiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.wHQ2RPML7Jr6yE0V0mNvIrtUT8mFrvp7sBBtH6bhlSc';
2328
2329
  // const filePath = 'response.json';
2329
2330
  // let allResults = [];
2330
2331
 
2331
- // if ( fs.existsSync( filePath ) ) {
2332
- // try {
2333
- // const existingData = fs.readFileSync( filePath, 'utf8' );
2334
- // allResults = JSON.parse( existingData );
2335
- // if ( !Array.isArray( allResults ) ) {
2332
+ // if ( fs.existsSync( filePath ) ) {
2333
+ // try {
2334
+ // const existingData = fs.readFileSync( filePath, 'utf8' );
2335
+ // allResults = JSON.parse( existingData );
2336
+ // if ( !Array.isArray( allResults ) ) {
2337
+ // allResults = [];
2338
+ // }
2339
+ // } catch ( error ) {
2340
+ // console.error( 'Error reading existing JSON file:', error.message );
2336
2341
  // allResults = [];
2337
2342
  // }
2338
- // } catch ( error ) {
2339
- // console.error( 'Error reading existing JSON file:', error.message );
2340
- // allResults = [];
2341
2343
  // }
2342
- // }
2343
2344
 
2344
- // for ( const storeId of storeIds ) {
2345
- // try {
2346
- // const result = await new Promise( ( resolve ) => {
2347
- // const payload = JSON.stringify( { store_id: storeId } );
2348
- // const options = {
2349
- // method: 'POST',
2350
- // headers: {
2351
- // 'Authorization': `Bearer ${bearerToken}`,
2352
- // 'Content-Type': 'application/json',
2353
- // 'Content-Length': Buffer.byteLength( payload ),
2354
- // },
2355
- // };
2356
-
2357
- // const req = https.request( apiUrl, options, ( res ) => {
2358
- // let data = '';
2359
- // res.on( 'data', ( chunk ) => {
2360
- // data += chunk;
2361
- // } );
2362
- // res.on( 'end', () => {
2363
- // try {
2364
- // const jsonData = JSON.parse( data );
2365
- // const result = { storeName: storeId, data: jsonData };
2366
- // allResults.push( result );
2367
- // fs.writeFileSync( filePath, JSON.stringify( allResults, null, 2 ) );
2368
- // console.log( 'Received Data:', result );
2369
- // resolve( result );
2370
- // } catch ( error ) {
2371
- // console.error( `Error parsing JSON for ${storeId}:`, error.message );
2372
- // resolve( { storeName: storeId, data: null } );
2373
- // }
2345
+ // for ( const storeId of storeIds ) {
2346
+ // try {
2347
+ // const result = await new Promise( ( resolve ) => {
2348
+ // const payload = JSON.stringify( { store_id: storeId } );
2349
+ // const options = {
2350
+ // method: 'POST',
2351
+ // headers: {
2352
+ // 'Authorization': `Bearer ${bearerToken}`,
2353
+ // 'Content-Type': 'application/json',
2354
+ // 'Content-Length': Buffer.byteLength( payload ),
2355
+ // },
2356
+ // };
2357
+
2358
+ // const req = https.request( apiUrl, options, ( res ) => {
2359
+ // let data = '';
2360
+ // res.on( 'data', ( chunk ) => {
2361
+ // data += chunk;
2362
+ // } );
2363
+ // res.on( 'end', () => {
2364
+ // try {
2365
+ // const jsonData = JSON.parse( data );
2366
+ // const result = { storeName: storeId, data: jsonData };
2367
+ // allResults.push( result );
2368
+ // fs.writeFileSync( filePath, JSON.stringify( allResults, null, 2 ) );
2369
+ // console.log( 'Received Data:', result );
2370
+ // resolve( result );
2371
+ // } catch ( error ) {
2372
+ // console.error( `Error parsing JSON for ${storeId}:`, error.message );
2373
+ // resolve( { storeName: storeId, data: null } );
2374
+ // }
2375
+ // } );
2374
2376
  // } );
2375
- // } );
2376
2377
 
2377
- // req.on( 'error', ( error ) => {
2378
- // console.error( `Error fetching data for ${storeId}:`, error.message );
2379
- // resolve( { storeName: storeId, data: null } );
2380
- // } );
2378
+ // req.on( 'error', ( error ) => {
2379
+ // console.error( `Error fetching data for ${storeId}:`, error.message );
2380
+ // resolve( { storeName: storeId, data: null } );
2381
+ // } );
2381
2382
 
2382
2383
  // req.write( payload );
2383
2384
  // req.end();
@@ -7223,32 +7224,6 @@ export async function migrateCrestv1( req, res ) {
7223
7224
  };
7224
7225
 
7225
7226
 
7226
- async function generateFixtureTemplateName( baseName, fixtureWidth ) {
7227
- function escapeRegex( str ) {
7228
- return str.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
7229
- }
7230
-
7231
- const escapedBase = escapeRegex( baseName );
7232
- const regexPattern = new RegExp( `^Template-(\\d+)-${escapedBase}$` );
7233
-
7234
- const existingFixtures = await fixtureConfigService.find( {
7235
- fixtureName: { $regex: new RegExp( `^Template-(\\d+)-${escapedBase}$` ) },
7236
- fixtureWidth: fixtureWidth,
7237
- } );
7238
-
7239
- const usedNumbers = existingFixtures
7240
- .map( ( doc ) => {
7241
- const match = doc.fixtureName.match( regexPattern );
7242
- return match ? parseInt( match[1], 10 ) : null;
7243
- } )
7244
- .filter( ( num ) => num !== null );
7245
-
7246
- const nextNumber = usedNumbers.length > 0 ? Math.max( ...usedNumbers ) + 1 : 1;
7247
-
7248
- return `Template-${nextNumber}-${baseName}`;
7249
- }
7250
-
7251
-
7252
7227
  if ( !req?.body?.storeName ) {
7253
7228
  return res.sendError( 'No store supplied', 200 );
7254
7229
  }
@@ -7256,8 +7231,20 @@ export async function migrateCrestv1( req, res ) {
7256
7231
  let storeQuery = {
7257
7232
  clientId: '11',
7258
7233
  $and: [
7259
- { storeName: req.body.storeName },
7260
- // { storeName: { $in: [ 'LKST98' ] } },
7234
+ // { storeName: req.body.storeName },
7235
+ { storeName: { $in: [
7236
+ 'LKST81',
7237
+ 'LKST682',
7238
+ 'LKST351',
7239
+ 'LKST1193',
7240
+ 'LKST98',
7241
+ 'LKST01',
7242
+ 'LKST266',
7243
+ 'LKST495',
7244
+ 'LKST2280',
7245
+ 'LKST599',
7246
+ 'LKST267',
7247
+ ] } },
7261
7248
  // { storeName: { $nin: [ 'LKST98', 'LKST1193' ] } },
7262
7249
  ],
7263
7250
  };
@@ -7280,6 +7267,8 @@ export async function migrateCrestv1( req, res ) {
7280
7267
  for ( let i = 0; i < storeList.length; i++ ) {
7281
7268
  const storeData = await fetchStoreData( storeList[i], staticToken, res );
7282
7269
 
7270
+ console.log( JSON.stringify( storeData ) );
7271
+
7283
7272
  if ( storeData?.data?.message !== 'SUCCESS' ) continue;
7284
7273
 
7285
7274
 
@@ -7522,6 +7511,16 @@ export async function migrateCrestv1( req, res ) {
7522
7511
  };
7523
7512
  } );
7524
7513
 
7514
+ [ ...fixtureProductSubBrandName ].forEach( async ( brand ) => {
7515
+ const upsertData = {
7516
+ clientId: '11',
7517
+ brandName: brand,
7518
+ brandDetails: [],
7519
+ };
7520
+
7521
+ await planoProductCategoryService.upsertOne( { brandName: brand }, upsertData );
7522
+ } );
7523
+
7525
7524
  const vmConfig = fixture.productZones?.flatMap( ( zone ) => {
7526
7525
  const vms = zone.products.filter( ( vm ) => vm.isMerchandisingElement );
7527
7526
  const vmConfig = fixtureConfigDoc.vmConfig.filter( ( vm ) => vm.position === zone.zoneName );
@@ -7532,13 +7531,20 @@ export async function migrateCrestv1( req, res ) {
7532
7531
 
7533
7532
  if ( vm.productName === 'Creatr' && zone.zoneName === 'Mid' ) {
7534
7533
  configData = vmConfig.find( ( config ) => config.vmWidthmm === 905 );
7535
- configData.zone = 'stretch';
7536
7534
  }
7537
7535
 
7538
7536
  if ( vm.productName === 'Creatr' && zone.zoneName === 'Mid' && pids.length ) {
7539
7537
  configData = vmConfig.find( ( config ) => config.vmWidthmm === 230 );
7540
7538
  }
7541
7539
 
7540
+ if ( configData.vmWidthmm === 905 ) {
7541
+ configData.zone = 'stretch';
7542
+ }
7543
+
7544
+ if ( configData.vmWidthmm === 230 ) {
7545
+ configData.zone = 'left';
7546
+ }
7547
+
7542
7548
  if ( !configData ) return;
7543
7549
 
7544
7550
  const vmIdentifier = `vm${k+1}=${vm.productName}+${configData.vmHeightmm}+${configData.vmWidthmm}+${configData.startShelf}+${configData.endShelf}+${configData.zone}`;
@@ -7571,6 +7577,8 @@ export async function migrateCrestv1( req, res ) {
7571
7577
  },
7572
7578
  status: 'complete',
7573
7579
  vmBrand: vmTemplate.vmBrand,
7580
+ vmType: 'LKVM',
7581
+
7574
7582
  };
7575
7583
  if ( vmTemplate?.imageUrl ) {
7576
7584
  const parsedUrl = new URL( vmTemplate.imageUrl );
@@ -7619,11 +7627,28 @@ export async function migrateCrestv1( req, res ) {
7619
7627
  startYPosition: vmTemplate.startYPosition,
7620
7628
  endYPosition: vmTemplate.endYPosition,
7621
7629
  xZone: vmTemplate.xZone,
7630
+ yZone: 'stretch',
7631
+
7622
7632
  };
7623
7633
  } ) );
7624
7634
 
7625
- const baseFixtureName = `${fixtureConfigDoc.fixtureCategory}`;
7626
- const uniqueFixtureName = await generateFixtureTemplateName( baseFixtureName, fixtureConfigDoc.fixtureWidth );
7635
+ const existingTemplateWithMaxIndex = await fixtureConfigService.sortAndFindOne(
7636
+ { fixtureCategory: fixtureConfigDoc.fixtureCategory,
7637
+ fixtureWidth: fixtureConfigDoc.fixtureWidth }, {}, { templateIndex: -1 } );
7638
+
7639
+ let templateIndex = 1;
7640
+
7641
+ if ( existingTemplateWithMaxIndex.length ) {
7642
+ const isTemplateSimilar = await fixtureConfigService.findOne( { crestMapKey: mapKey } );
7643
+
7644
+ if ( isTemplateSimilar ) {
7645
+ templateIndex = isTemplateSimilar.toObject().templateIndex;
7646
+ } else {
7647
+ templateIndex = existingTemplateWithMaxIndex[0].toObject().templateIndex + 1;
7648
+ }
7649
+ }
7650
+
7651
+ const templateName = `Template-${templateIndex}-${fixtureConfigDoc.fixtureCategory}`;
7627
7652
 
7628
7653
 
7629
7654
  const fixtureTemplateData = {
@@ -7631,7 +7656,8 @@ export async function migrateCrestv1( req, res ) {
7631
7656
  'shelfConfig': shelfTemplate,
7632
7657
  'vmConfig': vmTemplate,
7633
7658
  'clientId': fixtureConfigDoc.clientId,
7634
- 'fixtureName': uniqueFixtureName,
7659
+ 'fixtureName': templateName,
7660
+ 'templateIndex': templateIndex,
7635
7661
  'header': {
7636
7662
  label: fixture.header ? fixture.header : fixture.fixtureSubname[0],
7637
7663
  isEnabled: true,
@@ -7754,6 +7780,16 @@ export async function migrateCrestv1( req, res ) {
7754
7780
  };
7755
7781
  } );
7756
7782
 
7783
+ [ ...fixtureProductSubBrandName ].forEach( async ( brand ) => {
7784
+ const upsertData = {
7785
+ clientId: '11',
7786
+ brandName: brand,
7787
+ brandDetails: [],
7788
+ };
7789
+
7790
+ await planoProductCategoryService.upsertOne( { brandName: brand }, upsertData );
7791
+ } );
7792
+
7757
7793
  const vmConfig = fixture.productZones?.flatMap( ( zone ) => {
7758
7794
  const vms = zone.products.filter( ( vm ) => vm.isMerchandisingElement );
7759
7795
  const vmConfig = fixtureConfigDoc.vmConfig.filter( ( vm ) => vm.position === zone.zoneName );
@@ -7771,6 +7807,14 @@ export async function migrateCrestv1( req, res ) {
7771
7807
  configData = vmConfig.find( ( config ) => config.vmWidthmm === 230 );
7772
7808
  }
7773
7809
 
7810
+ if ( configData.vmWidthmm === 905 ) {
7811
+ configData.zone = 'stretch';
7812
+ }
7813
+
7814
+ if ( configData.vmWidthmm === 230 ) {
7815
+ configData.zone = 'left';
7816
+ }
7817
+
7774
7818
  if ( !configData ) return;
7775
7819
 
7776
7820
  const vmIdentifier = `vm${k+1}=${vm.productName}+${configData.vmHeightmm}+${configData.vmWidthmm}+${configData.startShelf}+${configData.endShelf}+${configData.zone}`;
@@ -7803,6 +7847,7 @@ export async function migrateCrestv1( req, res ) {
7803
7847
  },
7804
7848
  status: 'complete',
7805
7849
  vmBrand: vmTemplate.vmBrand,
7850
+ vmType: 'LKVM',
7806
7851
  };
7807
7852
  if ( vmTemplate?.imageUrl ) {
7808
7853
  const parsedUrl = new URL( vmTemplate.imageUrl );
@@ -7852,11 +7897,28 @@ export async function migrateCrestv1( req, res ) {
7852
7897
  startYPosition: vmTemplate.startYPosition,
7853
7898
  endYPosition: vmTemplate.endYPosition,
7854
7899
  xZone: vmTemplate.xZone,
7900
+ yZone: 'stretch',
7855
7901
  };
7856
7902
  } ) );
7857
7903
 
7858
- const baseFixtureName = `${fixtureConfigDoc.fixtureCategory}`;
7859
- const uniqueFixtureName = await generateFixtureTemplateName( baseFixtureName, fixtureConfigDoc.fixtureWidth );
7904
+ const existingTemplateWithMaxIndex = await fixtureConfigService.sortAndFindOne(
7905
+ { fixtureCategory: fixtureConfigDoc.fixtureCategory,
7906
+ fixtureWidth: fixtureConfigDoc.fixtureWidth }, {}, { templateIndex: -1 } );
7907
+
7908
+ let templateIndex = 1;
7909
+
7910
+ if ( existingTemplateWithMaxIndex.length ) {
7911
+ const isTemplateSimilar = await fixtureConfigService.findOne( { crestMapKey: mapKey } );
7912
+
7913
+ if ( isTemplateSimilar ) {
7914
+ templateIndex = isTemplateSimilar.toObject().templateIndex;
7915
+ } else {
7916
+ templateIndex = existingTemplateWithMaxIndex[0].toObject().templateIndex + 1;
7917
+ }
7918
+ }
7919
+
7920
+
7921
+ const templateName = `Template-${templateIndex}-${fixtureConfigDoc.fixtureCategory}`;
7860
7922
 
7861
7923
 
7862
7924
  const fixtureTemplateData = {
@@ -7864,7 +7926,8 @@ export async function migrateCrestv1( req, res ) {
7864
7926
  'shelfConfig': shelfTemplate,
7865
7927
  'vmConfig': vmTemplate,
7866
7928
  'clientId': fixtureConfigDoc.clientId,
7867
- 'fixtureName': uniqueFixtureName,
7929
+ 'fixtureName': templateName,
7930
+ 'templateIndex': templateIndex,
7868
7931
  'header': {
7869
7932
  label: fixture.header ? fixture.header : fixture.fixtureSubname[0],
7870
7933
  isEnabled: true,
@@ -7987,6 +8050,17 @@ export async function migrateCrestv1( req, res ) {
7987
8050
  };
7988
8051
  } );
7989
8052
 
8053
+ [ ...fixtureProductSubBrandName ].forEach( async ( brand ) => {
8054
+ const upsertData = {
8055
+ clientId: '11',
8056
+ brandName: brand,
8057
+ brandDetails: [],
8058
+ };
8059
+
8060
+ await planoProductCategoryService.upsertOne( { brandName: brand }, upsertData );
8061
+ } );
8062
+
8063
+
7990
8064
  const vmConfig = fixture.productZones?.flatMap( ( zone ) => {
7991
8065
  const vms = zone.products.filter( ( vm ) => vm.isMerchandisingElement );
7992
8066
  const vmConfig = fixtureConfigDoc.vmConfig.filter( ( vm ) => vm.position === zone.zoneName );
@@ -8004,6 +8078,14 @@ export async function migrateCrestv1( req, res ) {
8004
8078
  configData = vmConfig.find( ( config ) => config.vmWidthmm === 230 );
8005
8079
  }
8006
8080
 
8081
+ if ( configData.vmWidthmm === 905 ) {
8082
+ configData.zone = 'stretch';
8083
+ }
8084
+
8085
+ if ( configData.vmWidthmm === 230 ) {
8086
+ configData.zone = 'left';
8087
+ }
8088
+
8007
8089
  if ( !configData ) return;
8008
8090
 
8009
8091
  const vmIdentifier = `vm${k+1}=${vm.productName}+${configData.vmHeightmm}+${configData.vmWidthmm}+${configData.startShelf}+${configData.endShelf}+${configData.zone}`;
@@ -8036,6 +8118,7 @@ export async function migrateCrestv1( req, res ) {
8036
8118
  },
8037
8119
  status: 'complete',
8038
8120
  vmBrand: vmTemplate.vmBrand,
8121
+ vmType: 'LKVM',
8039
8122
  };
8040
8123
  if ( vmTemplate?.imageUrl ) {
8041
8124
  const parsedUrl = new URL( vmTemplate.imageUrl );
@@ -8084,11 +8167,28 @@ export async function migrateCrestv1( req, res ) {
8084
8167
  startYPosition: vmTemplate.startYPosition,
8085
8168
  endYPosition: vmTemplate.endYPosition,
8086
8169
  xZone: vmTemplate.xZone,
8170
+ yZone: 'stretch',
8087
8171
  };
8088
8172
  } ) );
8089
8173
 
8090
- const baseFixtureName = `${fixtureConfigDoc.fixtureCategory}`;
8091
- const uniqueFixtureName = await generateFixtureTemplateName( baseFixtureName, fixtureConfigDoc.fixtureWidth );
8174
+ const existingTemplateWithMaxIndex = await fixtureConfigService.sortAndFindOne(
8175
+ { fixtureCategory: fixtureConfigDoc.fixtureCategory,
8176
+ fixtureWidth: fixtureConfigDoc.fixtureWidth }, {}, { templateIndex: -1 } );
8177
+
8178
+ let templateIndex = 1;
8179
+
8180
+ if ( existingTemplateWithMaxIndex.length ) {
8181
+ const isTemplateSimilar = await fixtureConfigService.findOne( { crestMapKey: mapKey } );
8182
+
8183
+ if ( isTemplateSimilar ) {
8184
+ templateIndex = isTemplateSimilar.toObject().templateIndex;
8185
+ } else {
8186
+ templateIndex = existingTemplateWithMaxIndex[0].toObject().templateIndex + 1;
8187
+ }
8188
+ }
8189
+
8190
+
8191
+ const templateName = `Template-${templateIndex}-${fixtureConfigDoc.fixtureCategory}`;
8092
8192
 
8093
8193
 
8094
8194
  const fixtureTemplateData = {
@@ -8096,7 +8196,8 @@ export async function migrateCrestv1( req, res ) {
8096
8196
  'shelfConfig': shelfTemplate,
8097
8197
  'vmConfig': vmTemplate,
8098
8198
  'clientId': fixtureConfigDoc.clientId,
8099
- 'fixtureName': uniqueFixtureName,
8199
+ 'fixtureName': templateName,
8200
+ 'templateIndex': templateIndex,
8100
8201
  'header': {
8101
8202
  label: fixture.header ? fixture.header : fixture.fixtureSubname[0],
8102
8203
  isEnabled: true,
@@ -8240,6 +8341,17 @@ export async function migrateCrestv1( req, res ) {
8240
8341
  };
8241
8342
  } );
8242
8343
 
8344
+ [ ...fixtureProductSubBrandName ].forEach( async ( brand ) => {
8345
+ const upsertData = {
8346
+ clientId: '11',
8347
+ brandName: brand,
8348
+ brandDetails: [],
8349
+ };
8350
+
8351
+ await planoProductCategoryService.upsertOne( { brandName: brand }, upsertData );
8352
+ } );
8353
+
8354
+
8243
8355
  const vmConfig = fixture.centerSuperSubMain?.flatMap( ( vm ) => {
8244
8356
  if ( !vm?.isVisualMerchandiser ) {
8245
8357
  return [];
@@ -8252,7 +8364,7 @@ export async function migrateCrestv1( req, res ) {
8252
8364
  {
8253
8365
  startYPosition: configData1.startShelf,
8254
8366
  endYPosition: configData1.endShelf,
8255
- xZone: configData1.zone,
8367
+ xZone: 'left',
8256
8368
  vmName: vm.name + ' - 1',
8257
8369
  vmHeight: configData1.vmHeightmm,
8258
8370
  vmWidth: configData1.vmWidthmm,
@@ -8260,7 +8372,8 @@ export async function migrateCrestv1( req, res ) {
8260
8372
  {
8261
8373
  startYPosition: configData2.startShelf,
8262
8374
  endYPosition: configData2.endShelf,
8263
- xZone: configData2.zone,
8375
+ xZone: 'stretch',
8376
+ yZone: 'stretch',
8264
8377
  vmName: vm.name + ' - 2',
8265
8378
  vmHeight: configData2.vmHeightmm,
8266
8379
  vmWidth: configData2.vmWidthmm,
@@ -8282,6 +8395,7 @@ export async function migrateCrestv1( req, res ) {
8282
8395
  },
8283
8396
  status: 'complete',
8284
8397
  vmBrand: vmTemplate.vmBrand,
8398
+ vmType: 'LKVM',
8285
8399
  };
8286
8400
 
8287
8401
  const vmDetails = await planoVmService.upsertOne(
@@ -8296,11 +8410,29 @@ export async function migrateCrestv1( req, res ) {
8296
8410
  startYPosition: vmTemplate.startYPosition,
8297
8411
  endYPosition: vmTemplate.endYPosition,
8298
8412
  xZone: vmTemplate.xZone,
8413
+ yZone: 'stretch',
8414
+
8299
8415
  };
8300
8416
  } ) );
8301
8417
 
8302
- const baseFixtureName = `${fixtureConfigDoc.fixtureCategory}`;
8303
- const uniqueFixtureName = await generateFixtureTemplateName( baseFixtureName, fixtureConfigDoc.fixtureWidth );
8418
+ const existingTemplateWithMaxIndex = await fixtureConfigService.sortAndFindOne(
8419
+ { fixtureCategory: fixtureConfigDoc.fixtureCategory,
8420
+ fixtureWidth: fixtureConfigDoc.fixtureWidth }, {}, { templateIndex: -1 } );
8421
+
8422
+ let templateIndex = 1;
8423
+
8424
+ if ( existingTemplateWithMaxIndex.length ) {
8425
+ const isTemplateSimilar = await fixtureConfigService.findOne( { crestMapKey: mapKey } );
8426
+
8427
+ if ( isTemplateSimilar ) {
8428
+ templateIndex = isTemplateSimilar.toObject().templateIndex;
8429
+ } else {
8430
+ templateIndex = existingTemplateWithMaxIndex[0].toObject().templateIndex + 1;
8431
+ }
8432
+ }
8433
+
8434
+
8435
+ const templateName = `Template-${templateIndex}-${fixtureConfigDoc.fixtureCategory}`;
8304
8436
 
8305
8437
 
8306
8438
  const fixtureTemplateData = {
@@ -8308,7 +8440,8 @@ export async function migrateCrestv1( req, res ) {
8308
8440
  'shelfConfig': shelfTemplate,
8309
8441
  'vmConfig': vmTemplate,
8310
8442
  'clientId': fixtureConfigDoc.clientId,
8311
- 'fixtureName': uniqueFixtureName,
8443
+ 'fixtureName': templateName,
8444
+ 'templateIndex': templateIndex,
8312
8445
  'header': {
8313
8446
  label: fixture.centerSubMain,
8314
8447
  isEnabled: true,