tango-app-api-store-builder 1.0.0-beta-132 → 1.0.0-beta-134

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-132",
3
+ "version": "1.0.0-beta-134",
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.2.166",
35
+ "tango-api-schema": "^2.2.173",
36
36
  "tango-app-api-middleware": "3.1.48",
37
37
  "url": "^0.11.4",
38
38
  "winston": "^3.17.0",
@@ -78,9 +78,8 @@ export async function updateTemplate( req, res ) {
78
78
  if ( !templateDetails ) {
79
79
  return res.sendError( 'No data found', 204 );
80
80
  }
81
- if ( inputData.status == 'active' ) {
81
+ if ( inputData.status == 'complete' ) {
82
82
  let newFixture;
83
- let storeList = inputData.store;
84
83
  delete inputData.store;
85
84
  if ( req.body?.new ) {
86
85
  templateDetails = templateDetails.toObject();
@@ -88,44 +87,53 @@ export async function updateTemplate( req, res ) {
88
87
  let templateData = { ...templateDetails, ...inputData };
89
88
  newFixture = await fixtureConfigService.create( templateData );
90
89
  }
91
- await Promise.all( storeList.map( async ( ele ) => {
92
- let fixtureCapacity = inputData.shelfConfig.reduce(
93
- ( acc, ele ) => acc + ele.productPerShelf,
94
- 0,
95
- );
96
- let storeFixtureDetails = await storeFixtureService.findOne( { storeId: ele.storeId, fixtureConfigId: req.params.templateId } );
90
+ let fixtureCapacity = inputData.shelfConfig.reduce( ( acc, ele ) => {
91
+ if ( ele.shelfType == 'tray' ) {
92
+ ele.productPerShelf = ele.trayRows * ele.productPerShelf;
93
+ }
94
+ acc = acc + ele.productPerShelf;
95
+ return acc;
96
+ },
97
+ 0 );
98
+
99
+ let storeFixtureDetails = await storeFixtureService.find( { fixtureConfigId: req.params.templateId } );
100
+ if ( storeFixtureDetails.length ) {
101
+ let fixtureList = storeFixtureDetails.map( ( ele ) => ele._id );
97
102
  let fixtureData = {
98
103
  ...inputData,
99
- storeName: ele.storeName,
100
- storeId: ele.storeId,
101
104
  fixtureCapacity: fixtureCapacity,
102
- fixtureConfigId: newFixture ? newFixture._id : storeFixtureDetails.fixtureConfigId,
105
+ fixtureConfigId: newFixture ? newFixture._id : req.params.templateId,
103
106
  };
104
- await storeFixtureService.updateOne( { _id: storeFixtureDetails._id }, fixtureData );
105
- await fixtureShelfService.deleteMany( { fixtureId: storeFixtureDetails._id } );
106
- let shelfData = [];
107
- inputData.shelfConfig.forEach( ( ele, index ) => {
108
- shelfData.push( {
109
- productCategory: inputData.productCategory,
110
- productSubCategory: inputData.productCategory,
111
- shelfType: ele.shelfType,
112
- trayRows: ele.trayRows,
113
- shelfNumber: index + 1,
114
- fixtureId: storeFixtureDetails._id,
115
- clientId: req.body.clientId,
116
- planoId: storeFixtureDetails.planoId,
117
- floorId: storeFixtureDetails.floorId,
118
- productBrandName: ele.productBrandName,
119
- shelfOrder: 'LTR',
120
- shelfSplitup: 0,
121
- storeId: storeFixtureDetails.storeId,
122
- storeName: storeFixtureDetails.storeName,
123
- productPerShelf: ele.productPerShelf,
124
- sectionZone: ele.zone,
107
+ delete fixtureData._id;
108
+ delete fixtureData.status;
109
+ await storeFixtureService.updateMany( { _id: { $in: fixtureList } }, fixtureData );
110
+ await Promise.all( storeFixtureDetails.map( async ( fixture ) => {
111
+ await fixtureShelfService.deleteMany( { fixtureId: fixture } );
112
+ let shelfData = [];
113
+ inputData.shelfConfig.forEach( ( ele, index ) => {
114
+ shelfData.push( {
115
+ productCategory: inputData.productCategory,
116
+ productSubCategory: inputData.productCategory,
117
+ shelfType: ele.shelfType,
118
+ trayRows: ele.trayRows,
119
+ shelfNumber: index + 1,
120
+ fixtureId: fixture,
121
+ clientId: req.body.clientId,
122
+ planoId: fixture.planoId,
123
+ floorId: fixture.floorId,
124
+ productBrandName: ele.productBrandName,
125
+ shelfOrder: 'LTR',
126
+ shelfSplitup: 0,
127
+ storeId: fixture.storeId,
128
+ storeName: fixture.storeName,
129
+ productPerShelf: ele.productPerShelf,
130
+ sectionZone: ele.zone,
131
+ zone: ele.zone,
132
+ } );
125
133
  } );
126
- } );
127
- await fixtureShelfService.insertMany( shelfData );
128
- } ) );
134
+ await fixtureShelfService.insertMany( shelfData );
135
+ } ) );
136
+ }
129
137
  }
130
138
  await fixtureConfigService.updateOne( { _id: req.params.templateId }, inputData );
131
139
  return res.sendSuccess( 'Fixture template details updated successfully' );
@@ -473,3 +481,17 @@ export async function updateFixtureTask( req, res ) {
473
481
  logger.error( { functionName: 'updateFixtureTask', error: e } );
474
482
  }
475
483
  }
484
+
485
+ export async function getAllTemplates( req, res ) {
486
+ try {
487
+ if ( !req.body.clientId ) {
488
+ return res.sendError( 'Client Id is required', 400 );
489
+ }
490
+
491
+ const fixtureTemplates = await fixtureConfigService.find( { clientId: req.body.clientId }, { fixtureName: 1, fixtureWidth: 1, productBrandName: 1 } );
492
+
493
+ res.sendSuccess( fixtureTemplates );
494
+ } catch ( e ) {
495
+ logger.error( { functionName: 'getAllTemplates', error: e } );
496
+ }
497
+ }
@@ -13,12 +13,13 @@ import * as planoproductCategoryService from '../service/planoproductCategory.se
13
13
  import * as fixtureConfigService from '../service/fixtureConfig.service.js';
14
14
  import * as fixtureLibraryService from '../service/planoLibrary.service.js';
15
15
  import * as planoTaskService from '../service/planoTask.service.js';
16
+ import * as planoGlobalCommentService from '../service/planoGlobalComment.service.js';
16
17
  import mongoose from 'mongoose';
18
+ import * as planoRevisionService from '../service/planoRevision.service.js';
17
19
  export async function getplanoFeedback( req, res ) {
18
20
  try {
19
21
  let query = [];
20
22
 
21
-
22
23
  query.push( {
23
24
  $match: {
24
25
  planoId: new mongoose.Types.ObjectId( req.body.planoId ),
@@ -376,8 +377,25 @@ export async function getplanoFeedback( req, res ) {
376
377
 
377
378
 
378
379
  let findvmCompliance = await planoTaskService.aggregate( queryVm );
379
- console.log( findvmCompliance );
380
- res.sendSuccess( { count: findfixtureCompliance.length, layoutData: findPlanoCompliance, fixtureData: findfixtureCompliance, VmData: findvmCompliance } );
380
+
381
+
382
+ let layoutComment = await planoGlobalCommentService.find( {
383
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
384
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
385
+ taskType: 'layout',
386
+ } );
387
+ let fixtureComment = await planoGlobalCommentService.find( {
388
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
389
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
390
+ taskType: 'fixture',
391
+ } );
392
+ let vmComment = await planoGlobalCommentService.find( {
393
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
394
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
395
+ taskType: 'vm',
396
+ } );
397
+
398
+ res.sendSuccess( { layoutData: findPlanoCompliance, layoutComment: layoutComment, fixtureComment: fixtureComment, vmComment: vmComment, fixtureData: findfixtureCompliance, VmData: findvmCompliance } );
381
399
  } catch ( e ) {
382
400
  logger.error( { functionName: 'getplanoFeedback', error: e, message: req.body } );
383
401
  return res.sendError( e, 500 );
@@ -804,3 +822,106 @@ export async function updateredostatus( req, res ) {
804
822
  return res.sendError( e, 500 );
805
823
  }
806
824
  }
825
+
826
+
827
+ export async function updateGlobalComment( req, res ) {
828
+ try {
829
+ await planoGlobalCommentService.create( {
830
+ userId: req.user._id,
831
+ userName: req.user.userName,
832
+ comment: req.body.comment,
833
+ responsetype: req.body.responsetype,
834
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
835
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
836
+ taskType: req.body.taskType,
837
+ clientId: req.body.clientId,
838
+ } );
839
+
840
+ res.sendSuccess( 'updated successfully' );
841
+ } catch ( e ) {
842
+ logger.error( { functionName: 'updateGlobalComment', error: e } );
843
+ return res.sendError( e, 500 );
844
+ }
845
+ }
846
+ export async function getGlobalComment( req, res ) {
847
+ try {
848
+ let layoutComment = await planoGlobalCommentService.find( {
849
+ planoId: new mongoose.Types.ObjectId( req.body.planoId ),
850
+ floorId: new mongoose.Types.ObjectId( req.body.floorId ),
851
+ taskType: req.body.taskType,
852
+ } );
853
+ res.sendSuccess( layoutComment );
854
+ } catch ( e ) {
855
+ logger.error( { functionName: 'getGlobalComment', error: e } );
856
+ return res.sendError( e, 500 );
857
+ }
858
+ }
859
+
860
+ export async function getAllPlanoRevisions( req, res ) {
861
+ try {
862
+ const { clientId } = req.body;
863
+
864
+ if ( !clientId ) {
865
+ return res.sendError( 'Client Id is required', 400 );
866
+ }
867
+
868
+ const revisions = await planoRevisionService.find(
869
+ { clientId },
870
+ { storeName: 1, storeId: 1, planoId: 1, floorId: 1, createdAt: 1 },
871
+ );
872
+
873
+ res.sendSuccess( revisions );
874
+ } catch ( e ) {
875
+ logger.error( { functionName: 'getAllPlanoRevisions', error: e } );
876
+ res.sendError( 'Failed to fetch plano revisions', 500 );
877
+ }
878
+ }
879
+
880
+ export async function createPlanoRevision( req, res ) {
881
+ try {
882
+ const { storeName, storeId, clientId, planoId, floorId, floorData } = req.body;
883
+
884
+ if ( !storeName || !storeId || !clientId || !planoId || !floorId || !floorData ) {
885
+ return res.sendError( 'Missing required fields', 400 );
886
+ }
887
+
888
+ const newRevision = await planoRevisionService.create( {
889
+ storeName,
890
+ storeId,
891
+ clientId,
892
+ planoId,
893
+ floorId,
894
+ floorData,
895
+ } );
896
+
897
+ res.sendSuccess( newRevision );
898
+ } catch ( e ) {
899
+ logger.error( { functionName: 'createPlanoRevision', error: e } );
900
+ res.sendError( 'Failed to create plano revision', 500 );
901
+ }
902
+ }
903
+
904
+ export async function getPlanoRevisionById( req, res ) {
905
+ try {
906
+ const { id } = req.params;
907
+
908
+ if ( !id ) {
909
+ return res.sendError( 'Revision ID is required', 400 );
910
+ }
911
+
912
+ const revision = await planoRevisionService.findOne(
913
+ { _id: id },
914
+ );
915
+
916
+ if ( !revision ) {
917
+ return res.sendError( 'Plano revision not found', 404 );
918
+ }
919
+
920
+ res.sendSuccess( revision );
921
+ } catch ( e ) {
922
+ logger.error( { functionName: 'getPlanoRevisionById', error: e } );
923
+ res.sendError( 'Failed to fetch plano revision', 500 );
924
+ }
925
+ }
926
+
927
+
@@ -92,7 +92,7 @@ export async function fixtureBulkUpload( req, res ) {
92
92
 
93
93
  async function getMaxFixtureLibCode() {
94
94
  try {
95
- let getFixtureLibDetails = await planoLibraryService.find( {}, { fixtureLibCode: 1 } );
95
+ let getFixtureLibDetails = await planoLibraryService.find( { fixtureLibCode: { $exists: true } }, { fixtureLibCode: 1 } );
96
96
  if ( !getFixtureLibDetails.length ) {
97
97
  return 'FX01';
98
98
  } else {
@@ -242,7 +242,7 @@ export async function FixtureLibraryList( req, res ) {
242
242
  const matchStage = {
243
243
  clientId: req.body.clientId,
244
244
  ...( req.body?.searchValue ?
245
- { fixtureCategory: { $regex: req.body.searchValue, $options: 'i' } } :
245
+ { $or: [ { fixtureCategory: { $regex: req.body.searchValue, $options: 'i' } }, { fixtureCategorySize: { $regex: req.body.searchValue, $options: 'i' } } ] } :
246
246
  {} ),
247
247
  ...( req.body?.filter?.type?.length ?
248
248
  { fixtureType: { $in: req.body.filter.type } } :
@@ -253,6 +253,13 @@ export async function FixtureLibraryList( req, res ) {
253
253
  };
254
254
 
255
255
  const query = [
256
+ {
257
+ $addFields: {
258
+ fixtureCategorySize: {
259
+ $concat: [ '$fixtureCategory', ' - ', { $toString: '$fixtureWidth.value' }, { $toString: '$fixtureWidth.unit' } ],
260
+ },
261
+ },
262
+ },
256
263
  { $match: matchStage },
257
264
  {
258
265
  $lookup: {
@@ -284,6 +291,7 @@ export async function FixtureLibraryList( req, res ) {
284
291
  },
285
292
  {
286
293
  $project: {
294
+ fixtureCategorySize: 1,
287
295
  fixtureWidth: 1,
288
296
  fixtureHeight: 1,
289
297
  fixtureLength: 1,
@@ -1397,7 +1405,7 @@ export async function vmBulkUpload( req, res ) {
1397
1405
 
1398
1406
  async function getMaxVMLibCode() {
1399
1407
  try {
1400
- let getVMLibDetails = await vmService.find( {}, { vmLibCode: 1 } );
1408
+ let getVMLibDetails = await vmService.find( { vmLibCode: { $exists: true } }, { vmLibCode: 1 } );
1401
1409
  if ( !getVMLibDetails.length ) {
1402
1410
  return 'VM01';
1403
1411
  } else {
@@ -2323,9 +2323,9 @@ export async function updateVmData( req, res ) {
2323
2323
 
2324
2324
  // import https from 'https';
2325
2325
  // async function scrapeCrest() {
2326
- // const storeIds = [ 'LKST3020' ];
2326
+ // const storeIds = [ 'LKST506' ];
2327
2327
  // const apiUrl = 'https://api.getcrest.ai/api/ms_shelfsensei/layout/';
2328
- // const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzUwMDU1OTMxLCJpYXQiOjE3NTAwNTIzMzEsImp0aSI6IjY5MGM1YTVhYjc3NDRlMmQ5YjlhMmZkYThhODM2MGYxIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.juirYxGNCsCe75vwgL2AR9_LeFsr8r4cJmEdygRZGO0';
2328
+ // const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzUwNjA1NDA1LCJpYXQiOjE3NTA2MDE4MDUsImp0aSI6IjAxZWJmNzRkYzNkODQ2MjliNTA4YzI0MjM3MDRiYjdlIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.OnXe5ws08FwY1h0u3bLl8-dxQyrCL2mxr6c_b1lyf-Q';
2329
2329
  // const filePath = 'response.json';
2330
2330
  // let allResults = [];
2331
2331
 
@@ -7223,6 +7223,174 @@ export async function migrateCrestv1( req, res ) {
7223
7223
  }
7224
7224
  };
7225
7225
 
7226
+ const getLibraryType = ( fixtureName ) => {
7227
+ const parts = fixtureName
7228
+ .split( ' - ' )
7229
+ .map( ( str ) => str.trim() )
7230
+ .filter( Boolean );
7231
+
7232
+ let category = 'Unknown';
7233
+ let value = 3;
7234
+
7235
+ const last = parts[parts.length - 1];
7236
+ const secondLast = parts[parts.length - 2];
7237
+
7238
+ const match = last?.match( /^([\d.]+)ft$/ );
7239
+
7240
+ if ( match && secondLast ) {
7241
+ value = parseFloat( match[1] );
7242
+ value = Math.round( value * 10 ) / 10;
7243
+ if ( value % 1 === 0 ) value = Math.round( value );
7244
+
7245
+ category = secondLast;
7246
+ } else {
7247
+ if ( last?.toLowerCase() === 'ft' || last?.toLowerCase().endsWith( 'ft' ) ) {
7248
+ category = secondLast || last;
7249
+ } else {
7250
+ category = last;
7251
+ }
7252
+
7253
+ value = 3;
7254
+ }
7255
+
7256
+ return {
7257
+ fixtureCategory: category,
7258
+ fixtureWidth: { value, unit: 'ft' },
7259
+ };
7260
+ };
7261
+
7262
+
7263
+ const sampleLibrary = {
7264
+ 'clientId': '11',
7265
+ 'fixtureType': 'wall',
7266
+ 'fixtureHeight': {
7267
+ 'value': 0,
7268
+ 'unit': 'ft',
7269
+ },
7270
+ 'fixtureLength': {
7271
+ 'value': 4,
7272
+ 'unit': 'ft',
7273
+ },
7274
+ 'header': {
7275
+ 'height': {
7276
+ 'value': 0,
7277
+ 'unit': '',
7278
+ },
7279
+ },
7280
+ 'footer': {
7281
+ 'height': {
7282
+ 'value': 0,
7283
+ 'unit': '',
7284
+ },
7285
+ },
7286
+ 'fixtureCapacity': 90,
7287
+ 'status': 'complete',
7288
+ 'shelfConfig': [
7289
+ {
7290
+ 'shelfNumber': 1,
7291
+ 'shelfType': 'shelf',
7292
+ 'shelfZone': 'Top',
7293
+ 'productPerShelf': 6,
7294
+ 'trayRows': 0,
7295
+ 'label': '',
7296
+ },
7297
+ {
7298
+ 'shelfNumber': 2,
7299
+ 'shelfType': 'shelf',
7300
+ 'shelfZone': 'Top',
7301
+ 'productPerShelf': 6,
7302
+ 'trayRows': 0,
7303
+ 'label': '',
7304
+ },
7305
+ {
7306
+ 'shelfNumber': 3,
7307
+ 'shelfType': 'shelf',
7308
+ 'shelfZone': 'Top',
7309
+ 'productPerShelf': 6,
7310
+ 'trayRows': 0,
7311
+ 'label': '',
7312
+ },
7313
+ {
7314
+ 'shelfNumber': 4,
7315
+ 'shelfType': 'tray',
7316
+ 'shelfZone': 'Mid',
7317
+ 'productPerShelf': 6,
7318
+ 'trayRows': 3,
7319
+ 'label': '',
7320
+ },
7321
+ {
7322
+ 'shelfNumber': 5,
7323
+ 'shelfType': 'tray',
7324
+ 'shelfZone': 'Mid',
7325
+ 'productPerShelf': 6,
7326
+ 'trayRows': 3,
7327
+ 'label': '',
7328
+ },
7329
+ {
7330
+ 'shelfNumber': 6,
7331
+ 'shelfType': 'tray',
7332
+ 'shelfZone': 'Bottom',
7333
+ 'productPerShelf': 6,
7334
+ 'trayRows': 3,
7335
+ 'label': '',
7336
+ },
7337
+ {
7338
+ 'shelfNumber': 7,
7339
+ 'shelfType': 'tray',
7340
+ 'shelfZone': 'Bottom',
7341
+ 'productPerShelf': 6,
7342
+ 'trayRows': 3,
7343
+ 'label': '',
7344
+ },
7345
+ ],
7346
+ 'vmConfig': [
7347
+ {
7348
+ 'vmNumber': 1,
7349
+ 'vmHeightmm': 100,
7350
+ 'vmWidthmm': 905,
7351
+ 'startShelf': 1,
7352
+ 'endShelf': 2,
7353
+ 'zone': 'left',
7354
+ 'position': 'Top',
7355
+ },
7356
+ {
7357
+ 'vmNumber': 2,
7358
+ 'vmHeightmm': 100,
7359
+ 'vmWidthmm': 230,
7360
+ 'startShelf': 5,
7361
+ 'endShelf': 5,
7362
+ 'zone': 'left',
7363
+ 'position': 'Mid',
7364
+ },
7365
+ {
7366
+ 'vmNumber': 3,
7367
+ 'vmHeightmm': 100,
7368
+ 'vmWidthmm': 905,
7369
+ 'startShelf': 5,
7370
+ 'endShelf': 5,
7371
+ 'zone': 'left',
7372
+ 'position': 'Mid',
7373
+ },
7374
+ {
7375
+ 'vmNumber': 4,
7376
+ 'vmHeightmm': 100,
7377
+ 'vmWidthmm': 230,
7378
+ 'startShelf': 6,
7379
+ 'endShelf': 6,
7380
+ 'zone': 'right',
7381
+ 'position': 'Bottom',
7382
+ },
7383
+ ],
7384
+ 'fixtureStaticLength': {
7385
+ 'value': 1524,
7386
+ 'unit': 'mm',
7387
+ },
7388
+ 'fixtureStaticWidth': {
7389
+ 'value': 1220,
7390
+ 'unit': 'mm',
7391
+ },
7392
+ };
7393
+
7226
7394
 
7227
7395
  if ( !req?.body?.storeName ) {
7228
7396
  return res.sendError( 'No store supplied', 200 );
@@ -7232,19 +7400,7 @@ export async function migrateCrestv1( req, res ) {
7232
7400
  clientId: '11',
7233
7401
  $and: [
7234
7402
  { 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
- // ] } },
7403
+ // { storeName: { $in: ['LKST98', 'LKST682', 'ST185', 'ST36', 'LKST1193'] } },
7248
7404
  // { storeName: { $nin: [ 'LKST98', 'LKST1193' ] } },
7249
7405
  ],
7250
7406
  };
@@ -7478,8 +7634,31 @@ export async function migrateCrestv1( req, res ) {
7478
7634
  for ( let index = 0; index < leftFixtures.length; index++ ) {
7479
7635
  const fixture = leftFixtures[index];
7480
7636
 
7481
- const fixtureConfig = await fixtureLibraryService.findOne( { fixtureCategory: fixture.fixtureType } );
7482
- if ( !fixtureConfig ) continue;
7637
+ if ( !fixture.fixtureName ) {
7638
+ return;
7639
+ }
7640
+
7641
+ const libraryType = getLibraryType( fixture.fixtureName );
7642
+
7643
+ if ( libraryType.fixtureCategory === 'Space' ) {
7644
+ continue;
7645
+ }
7646
+
7647
+ let fixtureConfig = await fixtureLibraryService.findOne( libraryType );
7648
+
7649
+ if ( !fixtureConfig ) {
7650
+ const existingLibrary = await fixtureLibraryService.findOne( { fixtureCategory: libraryType.fixtureCategory } );
7651
+
7652
+ const insertData = {
7653
+ ...sampleLibrary,
7654
+ ...( existingLibrary ? existingLibrary.toObject() : {} ),
7655
+ ...libraryType,
7656
+ };
7657
+
7658
+ delete insertData._id;
7659
+
7660
+ fixtureConfig = await fixtureLibraryService.upsertOne( libraryType, insertData );
7661
+ }
7483
7662
  const fixtureConfigDoc = fixtureConfig.toObject();
7484
7663
 
7485
7664
  let mapKey = `${fixtureConfigDoc.fixtureCategory}${fixtureConfigDoc.fixtureWidth.value}${fixtureConfigDoc.fixtureWidth.unit},${fixture.header}`;
@@ -7495,7 +7674,7 @@ export async function migrateCrestv1( req, res ) {
7495
7674
 
7496
7675
  mapKey += ','+shelfIdentifier;
7497
7676
 
7498
- const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
7677
+ const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs?\b/g, '' )?.split( /\s*\+\s*/ ) || [];
7499
7678
 
7500
7679
  productSubBrandName.forEach( ( item ) => fixtureProductSubBrandName.add( item ) );
7501
7680
 
@@ -7749,8 +7928,31 @@ export async function migrateCrestv1( req, res ) {
7749
7928
  for ( let index = 0; index < backFixtures.length; index++ ) {
7750
7929
  const fixture = backFixtures[index];
7751
7930
 
7752
- const fixtureConfig = await fixtureLibraryService.findOne( { fixtureCategory: fixture.fixtureType } );
7753
- if ( !fixtureConfig ) continue;
7931
+ if ( !fixture.fixtureName ) {
7932
+ return;
7933
+ }
7934
+
7935
+ const libraryType = getLibraryType( fixture.fixtureName );
7936
+
7937
+ if ( libraryType.fixtureCategory === 'Space' ) {
7938
+ continue;
7939
+ }
7940
+
7941
+ let fixtureConfig = await fixtureLibraryService.findOne( libraryType );
7942
+
7943
+ if ( !fixtureConfig ) {
7944
+ const existingLibrary = await fixtureLibraryService.findOne( { fixtureCategory: libraryType.fixtureCategory } );
7945
+
7946
+ const insertData = {
7947
+ ...sampleLibrary,
7948
+ ...( existingLibrary ? existingLibrary.toObject() : {} ),
7949
+ ...libraryType,
7950
+ };
7951
+
7952
+ delete insertData._id;
7953
+
7954
+ fixtureConfig = await fixtureLibraryService.upsertOne( libraryType, insertData );
7955
+ }
7754
7956
  const fixtureConfigDoc = fixtureConfig.toObject();
7755
7957
 
7756
7958
  let mapKey = `${fixtureConfigDoc.fixtureCategory}${fixtureConfigDoc.fixtureWidth.value}${fixtureConfigDoc.fixtureWidth.unit},${fixture.header}`;
@@ -7766,7 +7968,7 @@ export async function migrateCrestv1( req, res ) {
7766
7968
 
7767
7969
  mapKey += ','+shelfIdentifier;
7768
7970
 
7769
- const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
7971
+ const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs?\b/g, '' )?.split( /\s*\+\s*/ ) || [];
7770
7972
 
7771
7973
  productSubBrandName.forEach( ( item ) => fixtureProductSubBrandName.add( item ) );
7772
7974
 
@@ -8019,8 +8221,31 @@ export async function migrateCrestv1( req, res ) {
8019
8221
  for ( let index = 0; index < rightFixtures.length; index++ ) {
8020
8222
  const fixture = rightFixtures[index];
8021
8223
 
8022
- const fixtureConfig = await fixtureLibraryService.findOne( { fixtureCategory: fixture.fixtureType } );
8023
- if ( !fixtureConfig ) continue;
8224
+ if ( !fixture.fixtureName ) {
8225
+ return;
8226
+ }
8227
+
8228
+ const libraryType = getLibraryType( fixture.fixtureName );
8229
+
8230
+ if ( libraryType.fixtureCategory === 'Space' ) {
8231
+ continue;
8232
+ }
8233
+
8234
+ let fixtureConfig = await fixtureLibraryService.findOne( libraryType );
8235
+
8236
+ if ( !fixtureConfig ) {
8237
+ const existingLibrary = await fixtureLibraryService.findOne( { fixtureCategory: libraryType.fixtureCategory } );
8238
+
8239
+ const insertData = {
8240
+ ...sampleLibrary,
8241
+ ...( existingLibrary ? existingLibrary.toObject() : {} ),
8242
+ ...libraryType,
8243
+ };
8244
+
8245
+ delete insertData._id;
8246
+
8247
+ fixtureConfig = await fixtureLibraryService.upsertOne( libraryType, insertData );
8248
+ }
8024
8249
  const fixtureConfigDoc = fixtureConfig.toObject();
8025
8250
 
8026
8251
  let mapKey = `${fixtureConfigDoc.fixtureCategory}${fixtureConfigDoc.fixtureWidth.value}${fixtureConfigDoc.fixtureWidth.unit},${fixture.header}`;
@@ -8036,7 +8261,7 @@ export async function migrateCrestv1( req, res ) {
8036
8261
 
8037
8262
  mapKey += ','+shelfIdentifier;
8038
8263
 
8039
- const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
8264
+ const productSubBrandName = shelfSection?.productName?.replace( /\s*PIDs?\b/g, '' )?.split( /\s*\+\s*/ ) || [];
8040
8265
 
8041
8266
  productSubBrandName.forEach( ( item ) => fixtureProductSubBrandName.add( item ) );
8042
8267
 
@@ -8323,10 +8548,10 @@ export async function migrateCrestv1( req, res ) {
8323
8548
  mapKey += ','+shelfIdentifier;
8324
8549
 
8325
8550
 
8326
- let productSubBrandName = fixture.centerSubMain.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
8551
+ let productSubBrandName = fixture.centerSubMain.replace( /\s*PIDs?\b/g, '' )?.split( /\s*\+\s*/ ) || [];
8327
8552
 
8328
8553
  if ( shelfSection ) {
8329
- productSubBrandName = shelfSection.name.replace( /\s*PIDs\b/g, '' )?.split( /\s*\+\s*/ ) || [];
8554
+ productSubBrandName = shelfSection.name.replace( /\s*PIDs?\b/g, '' )?.split( /\s*\+\s*/ ) || [];
8330
8555
  }
8331
8556
 
8332
8557
  productSubBrandName.forEach( ( item ) => fixtureProductSubBrandName.add( item ) );