tango-app-api-store-builder 1.0.36 → 1.0.38

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.36",
3
+ "version": "1.0.38",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -786,7 +786,7 @@ export async function updateStorePlano( req, res ) {
786
786
  { _id: new mongoose.Types.ObjectId( floorId ) },
787
787
  {
788
788
  layoutPolygon: layoutPolygon,
789
- cadLayout:false,
789
+ cadLayout: false,
790
790
  ...( req.body?.editMode === true && { isEdited: true } ),
791
791
  },
792
792
  );
@@ -1825,8 +1825,8 @@ export async function createPlanoRevision( req, res ) {
1825
1825
  await planoRevisionService.create( data );
1826
1826
 
1827
1827
  await storeBuilderService.updateOne( { _id: floorId },
1828
- { ...( req.body.type.includes( 'merchRollout' ) ) ? { merchRolloutStatus: true } :{},
1829
- ...( req.body.type.includes( 'vmRollout' ) ) ? { vmRolloutStatus: true } : {},
1828
+ { ...( req.body?.type?.includes( 'merchRollout' ) ) ? { merchRolloutStatus: true } :{},
1829
+ ...( req.body?.type?.includes( 'vmRollout' ) ) ? { vmRolloutStatus: true } : {},
1830
1830
  ...( !req.body?.type && { verificationStatus: true } ), planoProgress: 100 } );
1831
1831
 
1832
1832
  res.sendSuccess( 'Plano published successfully' );
@@ -2625,7 +2625,10 @@ function transformFixtureData( data ) {
2625
2625
 
2626
2626
  function computeStoreFixtures( data, meta ) {
2627
2627
  let fixtures = [];
2628
- const walls = data?.layoutPolygon ?? [];
2628
+ const walls = (data?.layoutPolygon ?? []).filter(e => e.elementType === 'wall').sort((a,b) => a.elementNumber - b.elementNumber);
2629
+ const allFixtures = walls.flatMap(w => w?.fixtures);
2630
+ allFixtures.forEach((f,i) => f.fixtureNumber = i + 1);
2631
+
2629
2632
  for ( let i = 1; i <= walls.length; i++ ) {
2630
2633
  const w = walls[i - 1];
2631
2634
  const wFixtures = w?.fixtures ?? [];
@@ -2769,4 +2772,4 @@ async function processFixtureTemplates(data) {
2769
2772
  }
2770
2773
 
2771
2774
  return updateStoreFixtures;
2772
- }
2775
+ }
@@ -1696,8 +1696,8 @@ export async function updateInventory( req, res ) {
1696
1696
  const element = raw[i];
1697
1697
 
1698
1698
  const updateData = {
1699
- productBrand: element.parent_brand,
1700
- productType: element.parent_category,
1699
+ productBrand: element.brand,
1700
+ productType: element.hsn_classification,
1701
1701
  productId: element.barcode,
1702
1702
  type: 'product',
1703
1703
  storeName: 'LKST1193',
@@ -13373,7 +13373,7 @@ export async function getstoreFixtureExcel( req, res ) {
13373
13373
  }
13374
13374
  let data = [];
13375
13375
  let sortOrder = [ 5, 1, 2, 3, 4 ];
13376
- for ( let store of getStoreDetails ) {
13376
+ await Promise.all( getStoreDetails.map( async ( store ) => {
13377
13377
  let uniqueFixtureNumber = 1;
13378
13378
  let storeFixturesList = await storeFixtureService.findAndSort( { storeName: store.storeName }, {}, { fixtureNumber: 1, associatedElementNumber: 1, associatedElementFixtureNumber: 1 } );
13379
13379
  storeFixturesList.sort( ( a, b ) => {
@@ -13435,7 +13435,9 @@ export async function getstoreFixtureExcel( req, res ) {
13435
13435
  );
13436
13436
  }
13437
13437
  data.push( ...storeFixtureDetails );
13438
- }
13438
+ } ) );
13439
+ // for ( let store of getStoreDetails ) {
13440
+ // }
13439
13441
  await download( data, res );
13440
13442
  } catch ( e ) {
13441
13443
  console.log( e );
@@ -13480,7 +13482,7 @@ function findMissingStores() {
13480
13482
  // findMissingStores()
13481
13483
 
13482
13484
  async function createStores() {
13483
- const storeList = [];
13485
+ const storeList = [ "LKST4500" ];
13484
13486
 
13485
13487
  for ( let index = 0; index < storeList.length; index++ ) {
13486
13488
  const storeName = storeList[index];
@@ -15105,3 +15107,330 @@ export async function getFxCode( req, res ) {
15105
15107
  }
15106
15108
  }
15107
15109
 
15110
+ export async function updatelibraryDetails( req, res ) {
15111
+ try {
15112
+ const libraryWorkBook = xlsx.readFile( './data/Fixture Library Validation.xlsx' );
15113
+ const librarySheetName = libraryWorkBook.SheetNames[0];
15114
+ const sheet = libraryWorkBook.Sheets[librarySheetName];
15115
+ let libraryData = xlsx.utils.sheet_to_json( sheet );
15116
+ libraryData = libraryData.reduce( ( acc, ele ) => {
15117
+ let uniqueName = `${ele['Fixture Name']}-${ele['Fixture Width(ft)']}`;
15118
+ if ( !acc[uniqueName] ) {
15119
+ acc[uniqueName] = {
15120
+ fixtureCategory: ele['Fixture Name'],
15121
+ fixtureWidth: {
15122
+ value: ele['Fixture Width(ft)'],
15123
+ unit: 'ft',
15124
+ },
15125
+ fixtureLength: {
15126
+ value: ele['Fixture Header Height(ft)'],
15127
+ unit: 'ft',
15128
+ },
15129
+ clientId: "11",
15130
+ fixtureCapacity: 0,
15131
+ fixtureStaticLength: {
15132
+ value: 1524,
15133
+ unit: 'ft',
15134
+ },
15135
+ fixtureStaticWidth: {
15136
+ value: 1220,
15137
+ unit: 'ft',
15138
+ },
15139
+ fixtureType: ele['Fixture Type'],
15140
+ footer: {
15141
+ height: {
15142
+ value: ele['Fixture Footer Height(ft)'],
15143
+ unit: 'ft',
15144
+ },
15145
+ isEnabled: true,
15146
+ },
15147
+ header: {
15148
+ height: {
15149
+ value: ele['Fixture Header Height(ft)'],
15150
+ unit: 'ft',
15151
+ },
15152
+ isEnabled: true,
15153
+ },
15154
+ shelfConfig: [
15155
+ {
15156
+ shelfNumber: ele['Shelf Number'],
15157
+ shelfType: ele['Shelf Type'],
15158
+ productPerShelf: ele['Product Per Shelf/Tray'],
15159
+ trayRows: ele['Shelf Type'] == 'shelf' ? 0 :ele['Tray Rows'],
15160
+ label: '',
15161
+ zone: ele['Panel Name'],
15162
+ productBrandName: [],
15163
+ productSubBrandName: [],
15164
+ productCategory: [],
15165
+ productSubCategory: [],
15166
+ },
15167
+ ],
15168
+ fixtureCapacity: ele['Product Capacity'],
15169
+ status: 'completed',
15170
+ vmConfig: [],
15171
+ };
15172
+ } else {
15173
+ acc[uniqueName].shelfConfig.push( {
15174
+ shelfNumber: ele['Shelf Number'],
15175
+ shelfType: ele['Shelf Type'],
15176
+ productPerShelf: ele['Product Per Shelf/Tray'],
15177
+ trayRows: ele['Shelf Type'] == 'shelf' ? 0 :ele['Tray Rows'],
15178
+ label: '',
15179
+ zone: ele['Panel Name'],
15180
+ productBrandName: [],
15181
+ productSubBrandName: [],
15182
+ productCategory: [],
15183
+ productSubCategory: [],
15184
+ } );
15185
+
15186
+ acc[uniqueName].fixtureCapacity = acc[uniqueName].fixtureCapacity + ele['Product Capacity'];
15187
+ }
15188
+ return acc;
15189
+ }, {} );
15190
+ libraryData = Object.values( libraryData );
15191
+ await fixtureLibraryService.deleteMany( {} );
15192
+ await fixtureLibraryService.insertMany( libraryData );
15193
+ await Promise.all( libraryData.map( async ( ele ) => {
15194
+ let fixtureTemplateDetails = await fixtureConfigService.find( { fixtureCategory: { $regex: ele?.fixtureCategory, $options: 'i' }, fixtureWidth: ele?.fixtureWidth?.value } );
15195
+ if ( fixtureTemplateDetails.length ) {
15196
+ fixtureTemplateDetails.forEach( async ( temp ) => {
15197
+ temp.fixtureName = ele?.fixtureName;
15198
+ let shelfDetails = [];
15199
+ ele.shelfConfig.forEach( ( shelf ) => {
15200
+ let findShelf = temp.shelfConfig.findIndex( ( config ) => config.shelfNumber == shelf.shelfNumber );
15201
+ if ( findShelf ) {
15202
+ shelfDetails.push( { ...findShelf, ...shelf } );
15203
+ }
15204
+ } );
15205
+ temp.shelfConfig = shelfDetails;
15206
+ await fixtureConfigService.updateOne( { _id: temp._id }, temp );
15207
+ } );
15208
+
15209
+ let fixtureDetails = await storeFixtureService.find( { fixtureConfigId: { $in: fixtureTemplateDetails.map( ( ele ) => ele._id ) } } );
15210
+ storeFixtureService.updateMany( { _id: fixtureDetails?.map( ( fixt ) => fixt._id ) }, { fixtureCategory: ele?.fixtureCategory } );
15211
+
15212
+ await Promise.all( fixtureDetails.map( ( fixt ) => {
15213
+ let fixtShelf = [];
15214
+ temp.shelfConfig.forEach( ( shelf ) => {
15215
+ fixtShelf.push( {
15216
+ "clientId": "11",
15217
+ "storeName": "LKST01",
15218
+ "storeId": "11-160",
15219
+ "planoId": fixt.planoId,
15220
+ "floorId": fixt.floorId,
15221
+ "fixtureId": fixt._id,
15222
+ "shelfNumber": shelf.shelfNumber,
15223
+ "productBrandName": shelf.productBrandName,
15224
+ "productCategory": shelf.productCategory,
15225
+ "productSubCategory": shelf.productSubCategory,
15226
+ "zone": shelf.zone,
15227
+ "shelfType": shelf.shelftype,
15228
+ "productPerShelf": shelf.productPerShelf,
15229
+ "trayRows": shelf.trayRows,
15230
+ "label": "",
15231
+ } );
15232
+ } );
15233
+ fixtureShelfService.deleteMany( { fixtureId: fixt._id } );
15234
+ fixtureShelfService.insertMany( fixtShelf );
15235
+ } ) );
15236
+ }
15237
+ } ) );
15238
+ return res.sendSuccess( 'Library updated successfully' );
15239
+ } catch ( e ) {
15240
+ console.log( e );
15241
+ return res.sendError( e, 500 );
15242
+ }
15243
+ }
15244
+
15245
+ export async function getFixtureDetails( req, res ) {
15246
+ try {
15247
+ if ( !req.body?.storeName ) {
15248
+ return res.sendError( 'StoreName is required', 400 );
15249
+ }
15250
+
15251
+ let query = [
15252
+ {
15253
+ $match: {
15254
+ storeName: req.body?.storeName,
15255
+ fixtureType: { $ne: 'other' },
15256
+ },
15257
+ },
15258
+ {
15259
+ $sort: {
15260
+ fixtureNumber: 1,
15261
+ },
15262
+ },
15263
+ {
15264
+ $group: {
15265
+ _id: '',
15266
+ fixtureData: { $push: {
15267
+ k: { $concat: [ 'Fixture', ' ', { $toString: '$fixtureNumber' } ] },
15268
+ v: '$header.label',
15269
+ },
15270
+ },
15271
+ },
15272
+ },
15273
+ {
15274
+ $project: {
15275
+ _id: 0,
15276
+ fixtureData: {
15277
+ $arrayToObject: '$fixtureData',
15278
+ },
15279
+ },
15280
+ },
15281
+ ];
15282
+ let fixtureDetails = await storeFixtureService.aggregate( query );
15283
+ return res.sendSuccess( fixtureDetails?.[0]?.fixtureData ?? {} );
15284
+ } catch ( e ) {
15285
+ logger.error( { functionName: "getFixtureDetails", error: e } );
15286
+ return res.sendError( e, 500 );
15287
+ }
15288
+ }
15289
+
15290
+
15291
+ export async function update4487Inventory( req, res ) {
15292
+ try {
15293
+ if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
15294
+ return res.sendError( 'Unauthorized', 401 );
15295
+ }
15296
+ if ( !req.files.file ) {
15297
+ return res.sendError( 'Invalid or missing Excel file', 400 );
15298
+ }
15299
+
15300
+ const workbook = xlsx.read( req.files.file.data, { type: 'buffer' } );
15301
+ const sheetName = 'Data';
15302
+ if ( !workbook.Sheets[sheetName] ) {
15303
+ return res.sendError( `Sheet "${sheetName}" not found`, 400 );
15304
+ }
15305
+
15306
+ const raw = xlsx.utils.sheet_to_json( workbook.Sheets[sheetName] );
15307
+
15308
+ req.body.pidData = [
15309
+ {
15310
+ brandName: "Fossil PIDs",
15311
+ products: [
15312
+ "SSS010368277",
15313
+ "SSS010385099",
15314
+ "SSS010349542",
15315
+ "SSS010317191",
15316
+ "SSS010342894",
15317
+ "716736762401",
15318
+ "SSS010373732",
15319
+ "SSS010400330",
15320
+ "SSS010321792",
15321
+ "SSS010319980",
15322
+ "SSS010400177",
15323
+ "SSS010317379",
15324
+ "SSS010346066",
15325
+ "SSS010380522",
15326
+ "SSS010388891",
15327
+ "SSS010414566",
15328
+ "SSS010415054",
15329
+ "SSS010415362",
15330
+ "SSS010414369",
15331
+ "SSS010386657",
15332
+ "SSS010389123",
15333
+ "SSS010387781",
15334
+ "SSS010410650",
15335
+ "SSS010415412",
15336
+ "SSS010365958",
15337
+ "SSS010334985",
15338
+ "SSS010328362",
15339
+ "SSS010363283",
15340
+ "SSS010348343",
15341
+ "SSS010310037",
15342
+ ],
15343
+ },
15344
+ {
15345
+ brandName: "Non metal Premium Shades",
15346
+ products: [
15347
+ "JJJ018678462",
15348
+ "JJJ022935328",
15349
+ "JJJ020771700",
15350
+ "JJJ023174314",
15351
+ "JJJ019179561",
15352
+ "JJJ020773709",
15353
+ "JJJ020774459",
15354
+ "JJJ020772265",
15355
+ "JJJ016156602",
15356
+ "JJJ020772770",
15357
+ ],
15358
+ },
15359
+ {
15360
+ brandName: "Metal Premium Shades",
15361
+ products: [
15362
+ "JJJ023779045",
15363
+ "JJJ020113167",
15364
+ "JJJ020105972",
15365
+ "JJJ020106210",
15366
+ "JJJ020719537",
15367
+ "JJJ020720121",
15368
+ "JJJ020110393",
15369
+ "JJJ020109352",
15370
+ "JJJ020097758",
15371
+ "JJJ020098238",
15372
+ "JJJ020097211",
15373
+ "JJJ020111248",
15374
+ "JJJ018427428",
15375
+ "JJJ020114237",
15376
+ "JJJ022726217",
15377
+ "JJJ023527761",
15378
+ "JJJ023374156",
15379
+ "JJJ020538013",
15380
+ "JJJ023201555",
15381
+ "JJJ023524847",
15382
+ "JJJ020108157",
15383
+ "JJJ023193001",
15384
+ "JJJ020715644",
15385
+ "JJJ018678462",
15386
+ "JJJ022935328",
15387
+ "JJJ020771700",
15388
+ "JJJ023174314",
15389
+ "JJJ019179561",
15390
+ "JJJ020773709",
15391
+ ],
15392
+ },
15393
+ ];
15394
+ for ( let i = 0; i < req.body.pidData.length; i++ ) {
15395
+ for ( let j=0; j<req.body.pidData[i].products.length; j++ ) {
15396
+ const element = raw.find( ( ele ) => ele.barcode == req.body.pidData[i].products[j] );
15397
+ let updateData;
15398
+ if ( element ) {
15399
+ updateData = {
15400
+ productBrand: element.brand,
15401
+ productType: element.hsn_classification,
15402
+ productId: element.barcode,
15403
+ type: 'product',
15404
+ storeName: req.body.storeName,
15405
+ clientId: '11',
15406
+ brandName: req.body.pidData[i].brandName,
15407
+ category: element.collection,
15408
+ productImageUrl: element.image_front,
15409
+ productId: req.body.pidData[i].products[j],
15410
+ };
15411
+ } else {
15412
+ updateData = {
15413
+ productBrand: 'Unknown',
15414
+ productType: 'UnKnown',
15415
+ productId: req.body.pidData[i].products[j],
15416
+ type: 'product',
15417
+ storeName: req.body.storeName,
15418
+ clientId: '11',
15419
+ brandName: req.body.pidData[i].brandName,
15420
+ category: 'Unknown',
15421
+ productImageUrl: raw?.[0]?.image_front,
15422
+ productId: req.body.pidData[i].products[j],
15423
+ };
15424
+ }
15425
+ const product = await planoProductService.create( updateData );
15426
+ console.log( product );
15427
+ }
15428
+ }
15429
+
15430
+
15431
+ return res.sendSuccess( { message: 'Product inventory updated successfully' } );
15432
+ } catch ( e ) {
15433
+ logger.error( { functionName: 'createPlanoAPI', error: e } );
15434
+ return res.sendError( e.message || 'Internal Server Error', 500 );
15435
+ }
15436
+ }
@@ -3558,7 +3558,7 @@ export async function shelfProduct( req, res ) {
3558
3558
  if ( mappingCompliance?.compliance == 'misplaced' ) {
3559
3559
  Object.keys( shelfMapping ).forEach( ( ele ) => {
3560
3560
  let eleArr = ele.split( ',' );
3561
- if ( eleArr.includes( productData.brandName.toLowerCase() ) ) {
3561
+ if ( eleArr.includes( productData?.brandName?.toLowerCase() ) ) {
3562
3562
  mappingCompliance = { ...mappingCompliance, fixtureDetails: shelfMapping[ele]?.[0] || {} };
3563
3563
  }
3564
3564
  } );
@@ -8011,6 +8011,7 @@ export async function updateProductMapping( req, res ) {
8011
8011
  await Promise.all( storeDetails.map( async ( store ) => {
8012
8012
  // let number = Number( store.storeName.replace( /\D/g, '' ) );
8013
8013
  let getLatestData = await fetch( `${JSON.parse( process.env.LAMBDAURL )?.getRFIDDetails}/${store.storeName}`, { method: 'GET' } );
8014
+
8014
8015
  if ( getLatestData.status == 200 ) {
8015
8016
  let response = await getLatestData.json();
8016
8017
  let data = response.mac_details.flatMap( ( ele ) => ele.body );
@@ -8030,7 +8031,7 @@ export async function updateProductMapping( req, res ) {
8030
8031
  fixtureDetails = fixtureDetails.find( ( fixt ) => fixt._id.toString() == getShelfDetails.fixtureId.toString() );
8031
8032
  }
8032
8033
  if ( getShelfDetails ) {
8033
- let productDetails = await planoProductService.findOne( { rfId: ele.data.idHex } );
8034
+ let productDetails = await planoProductService.findOne( { productId: ele.data.idText } );
8034
8035
  if ( productDetails ) {
8035
8036
  let data = {
8036
8037
  clientId: req.body.clientId,
@@ -8038,7 +8039,7 @@ export async function updateProductMapping( req, res ) {
8038
8039
  storeId: fixtureDetails.storeId,
8039
8040
  type: getShelfDetails?.shelfType != 'storage' ? 'product' : 'storageBox',
8040
8041
  productId: productDetails._id,
8041
- pid: productDetails.pid,
8042
+ pid: productDetails.productId,
8042
8043
  planoId: fixtureDetails.planoId,
8043
8044
  floorId: fixtureDetails.floorId,
8044
8045
  fixtureId: fixtureDetails._id,
@@ -8072,6 +8073,7 @@ export async function updateProductMapping( req, res ) {
8072
8073
  }
8073
8074
  } ) );
8074
8075
  await planoMappingService.deleteMany( { storeId: store.storeId } );
8076
+ console.log( mappingData, '@@mappingData' );
8075
8077
  let mappingInsertData = await planoMappingService.insertMany( mappingData );
8076
8078
  mappingInsertData = new Map( mappingInsertData.map( ( ele, index ) => [ index, ele ] ) );
8077
8079
  let date = dayjs().format();
@@ -1,8 +1,8 @@
1
1
  import express from 'express';
2
2
 
3
3
  import * as scriptController from '../controllers/script.controller.js';
4
- import * as collectionUpdatesController from '../controllers/collectionUpdates.controller.js';
5
4
 
5
+ import { isAllowedInternalAPIHandler } from 'tango-app-api-middleware';
6
6
 
7
7
  export const scriptRouter = express.Router();
8
8
 
@@ -47,4 +47,7 @@ scriptRouter
47
47
  .post( '/getmisMatchedGroup', scriptController.getmisMatchedGroup )
48
48
  .post( '/updateProduct', scriptController.updateProduct )
49
49
  .post( '/getFxCode', scriptController.getFxCode )
50
+ .post( '/libraryDetails', scriptController.updatelibraryDetails )
51
+ .post( '/getFixtureDetails', isAllowedInternalAPIHandler, scriptController.getFixtureDetails )
52
+ .post( '/update4487Inventory', scriptController.update4487Inventory )
50
53
  ;