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

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-204",
3
+ "version": "1.0.0-beta-206",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -9549,148 +9549,147 @@ async function updateHeaders() {
9549
9549
  } );
9550
9550
  }
9551
9551
 
9552
- export async function productMappings( req, res ) {
9552
+ export async function productMappings(req, res) {
9553
9553
  try {
9554
9554
  const CLEAR_COL_BEFORE_INSERT = false;
9555
- if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
9556
- return res.sendError( 'Unauthorized', 401 );
9555
+ if (req?.headers?.authorization?.split(" ")[1] !== "hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx") {
9556
+ return res.sendError("Unauthorized", 401);
9557
9557
  }
9558
9558
 
9559
- if ( !req.files?.file ) {
9560
- return res.sendError( 'Excel file is required', 400 );
9559
+ if (!req.files?.file) {
9560
+ return res.sendError("Excel file is required", 400);
9561
9561
  }
9562
9562
 
9563
- const payload = JSON.parse( req.body.payload );
9563
+ const payload = JSON.parse(req.body.payload);
9564
9564
 
9565
9565
  const { fixtureId, Top, Mid, Bottom } = payload;
9566
9566
 
9567
- const storeName = 'LKST98';
9568
- const storeId = '11-4';
9567
+ const storeName = "LKST98";
9568
+ const storeId = "11-4";
9569
9569
 
9570
- if ( !fixtureId ) {
9571
- return res.sendError( 'fixtureId is required', 400 );
9570
+ if (!fixtureId) {
9571
+ return res.sendError("fixtureId is required", 400);
9572
9572
  }
9573
9573
 
9574
9574
  const fixtureData = { Top, Mid, Bottom };
9575
9575
 
9576
- const workbook = xlsx.read( req.files.file.data, { type: 'buffer' } );
9577
- const sheetName = 'Unique Mapping';
9578
- const raw = xlsx.utils.sheet_to_json( workbook.Sheets[sheetName] );
9576
+ const workbook = xlsx.read(req.files.file.data, { type: "buffer" });
9577
+ const sheetName = "Unique Mapping";
9578
+ const raw = xlsx.utils.sheet_to_json(workbook.Sheets[sheetName]);
9579
9579
 
9580
- const pidsList = Object.values( fixtureData ).flat();
9580
+ const pidsList = Object.values(fixtureData).flat();
9581
9581
 
9582
9582
  let pDetailsList = [];
9583
- for ( const pid of pidsList ) {
9584
- const pDetails = raw.find( ( pd ) => pd['product_id'] == pid );
9585
- if ( pDetails ) {
9586
- pDetailsList.push( {
9587
- clientId: '11',
9583
+ for (const pid of pidsList) {
9584
+ const pDetails = raw.find((pd) => pd["product_id"] == pid);
9585
+ if (pDetails) {
9586
+ pDetailsList.push({
9587
+ clientId: "11",
9588
9588
  productId: pDetails.product_id,
9589
9589
  productName: pDetails.parent_brand,
9590
9590
  pid: pDetails.product_id,
9591
9591
  rfId: pDetails.barcode,
9592
9592
  productImageUrl: pDetails.image_front,
9593
- productType: pDetails.classification_name ?? '',
9594
- brandName: pDetails.collection ?? '',
9595
- category: pDetails.collection_group ?? '',
9596
- subCategory: pDetails.sub_collection ?? '',
9597
- type: 'product',
9598
- } );
9593
+ productType: pDetails.classification_name ?? "",
9594
+ brandName: pDetails.collection ?? "",
9595
+ category: pDetails.collection_group ?? "",
9596
+ subCategory: pDetails.sub_collection ?? "",
9597
+ type: "product",
9598
+ });
9599
9599
  }
9600
9600
  }
9601
9601
 
9602
- if ( CLEAR_COL_BEFORE_INSERT ) await planoProductService.deleteMany( {} );
9602
+ if(CLEAR_COL_BEFORE_INSERT) await planoProductService.deleteMany({});
9603
9603
 
9604
9604
  // const uniqueProducts = await fixtureShelfService.find();
9605
+
9606
+ const fixtureTemplateData = await fixtureShelfService.find({ fixtureId });
9605
9607
 
9606
- const fixtureTemplateData = await fixtureShelfService.find( { fixtureId } );
9607
-
9608
- if ( !fixtureTemplateData?.length ) {
9609
- return res.sendError( 'No shelves found for fixtureId', 404 );
9608
+ if (!fixtureTemplateData?.length) {
9609
+ return res.sendError("No shelves found for fixtureId", 404);
9610
9610
  }
9611
9611
 
9612
9612
  const planoId = fixtureTemplateData[0].planoId;
9613
9613
  const floorId = fixtureTemplateData[0].floorId;
9614
9614
 
9615
- const fixtureShelve = fixtureTemplateData.map( ( f ) => ( {
9615
+ const fixtureShelve = fixtureTemplateData.map((f) => ({
9616
9616
  id: f._id,
9617
9617
  zone: f.zone,
9618
- } ) );
9619
-
9620
- const result = await planoProductService.insertMany( pDetailsList );
9618
+ }));
9619
+
9620
+ const result = await planoProductService.insertMany(pDetailsList);
9621
9621
 
9622
- let planoMappings = result.map( ( pd ) => ( {
9623
- clientId: '11',
9622
+ let planoMappings = result.map((pd) => ({
9623
+ clientId: "11",
9624
9624
  storeName: storeName,
9625
9625
  storeId: storeId,
9626
- type: 'product',
9626
+ type: "product",
9627
9627
  productId: pd._id,
9628
9628
  pid: pd.pid,
9629
- rfId: pd.rfId,
9630
9629
  planoId,
9631
9630
  floorId,
9632
9631
  fixtureId,
9633
- shelfId: 'temp', // will be reassigned in transformProducts
9634
- } ) );
9632
+ shelfId: "temp", // will be reassigned in transformProducts
9633
+ }));
9635
9634
 
9636
- if ( CLEAR_COL_BEFORE_INSERT ) await planoMappingService.deleteMany( {} );
9635
+ if(CLEAR_COL_BEFORE_INSERT) await planoMappingService.deleteMany({});
9637
9636
 
9638
9637
  const shelfGroups = {
9639
- Top: fixtureShelve.filter( ( f ) => f.zone === 'Top' ).map( ( f ) => f.id ),
9640
- Mid: fixtureShelve.filter( ( f ) => f.zone === 'Mid' ).map( ( f ) => f.id ),
9641
- Bottom: fixtureShelve.filter( ( f ) => f.zone === 'Bottom' ).map( ( f ) => f.id ),
9638
+ Top: fixtureShelve.filter((f) => f.zone === "Top").map((f) => f.id),
9639
+ Mid: fixtureShelve.filter((f) => f.zone === "Mid").map((f) => f.id),
9640
+ Bottom: fixtureShelve.filter((f) => f.zone === "Bottom").map((f) => f.id),
9642
9641
  };
9643
9642
 
9644
- const transformed = transformProducts( planoMappings, shelfGroups, fixtureData );
9643
+ const transformed = transformProducts(planoMappings, shelfGroups, fixtureData);
9645
9644
 
9646
- const result2 = await planoMappingService.insertMany( transformed );
9645
+ const result2 = await planoMappingService.insertMany(transformed);
9647
9646
 
9648
- res.sendSuccess( {
9647
+ res.sendSuccess({
9649
9648
  fixtureData,
9650
9649
  shelfGroups,
9651
9650
  planoMappings: result2,
9652
- } );
9653
- } catch ( error ) {
9654
- console.log( '@@ ~ error:', error );
9655
- res.sendError( 'Internal Server Error', 500 );
9651
+ });
9652
+ } catch (error) {
9653
+ console.log("@@ ~ error:", error);
9654
+ res.sendError("Internal Server Error", 500);
9656
9655
  }
9657
9656
  }
9658
9657
 
9659
- function transformProducts( products, shelvesByZone, fixtureData ) {
9658
+ function transformProducts(products, shelvesByZone, fixtureData) {
9660
9659
  const result = [];
9661
9660
 
9662
9661
  // Build lookup: pid → zone
9663
9662
  const pidToZone = {};
9664
- for ( const [ zone, pids ] of Object.entries( fixtureData ) ) {
9665
- pids.forEach( ( pid ) => {
9663
+ for (const [zone, pids] of Object.entries(fixtureData)) {
9664
+ pids.forEach(pid => {
9666
9665
  pidToZone[pid] = zone;
9667
- } );
9666
+ });
9668
9667
  }
9669
9668
 
9670
9669
  // Group products by zone
9671
9670
  const productsByZone = {};
9672
- for ( const doc of products ) {
9671
+ for (const doc of products) {
9673
9672
  const zone = pidToZone[doc.pid];
9674
- if ( !zone ) continue;
9675
- if ( !productsByZone[zone] ) productsByZone[zone] = [];
9676
- productsByZone[zone].push( doc );
9673
+ if (!zone) continue;
9674
+ if (!productsByZone[zone]) productsByZone[zone] = [];
9675
+ productsByZone[zone].push(doc);
9677
9676
  }
9678
9677
 
9679
9678
  // Round-robin distribute products across shelves
9680
- for ( const [ zone, docs ] of Object.entries( productsByZone ) ) {
9679
+ for (const [zone, docs] of Object.entries(productsByZone)) {
9681
9680
  const shelves = shelvesByZone[zone] || [];
9682
- if ( shelves.length === 0 ) {
9683
- result.push( ...docs );
9681
+ if (shelves.length === 0) {
9682
+ result.push(...docs);
9684
9683
  continue;
9685
9684
  }
9686
9685
 
9687
- docs.forEach( ( doc, idx ) => {
9686
+ docs.forEach((doc, idx) => {
9688
9687
  const shelfId = shelves[idx % shelves.length]; // cycle through shelves
9689
- result.push( {
9688
+ result.push({
9690
9689
  ...doc,
9691
- shelfId,
9692
- } );
9693
- } );
9690
+ shelfId
9691
+ });
9692
+ });
9694
9693
  }
9695
9694
 
9696
9695
  return result;
@@ -1430,7 +1430,7 @@ export async function scanv1( req, res ) {
1430
1430
 
1431
1431
  export async function updateMissing( req, res ) {
1432
1432
  try {
1433
- const { planoId, fixtureId } = req.body;
1433
+ const { planoId, fixtureId, zone } = req.body;
1434
1434
 
1435
1435
  const [ planogram, fixture ] = await Promise.all( [
1436
1436
  planoService.findOne(
@@ -1447,12 +1447,11 @@ export async function updateMissing( req, res ) {
1447
1447
 
1448
1448
  const fixtureShelves = await fixtureShelfService.find( {
1449
1449
  fixtureId: new mongoose.Types.ObjectId( fixtureId ),
1450
+ ...( zone ? { zone } : {} ),
1450
1451
  } );
1451
1452
 
1452
1453
  if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
1453
1454
 
1454
- console.log( 'called' );
1455
-
1456
1455
  await Promise.all(
1457
1456
  fixtureShelves.map( async ( shelf ) => {
1458
1457
  const productMappings = await planoMappingService.find( { shelfId: shelf._id } );
@@ -5575,39 +5574,10 @@ export async function getPlanoStoreList( req, res ) {
5575
5574
  if ( !storeDetails.length ) {
5576
5575
  return res.sendError( 'No data found', 204 );
5577
5576
  }
5578
- let query = [
5579
- {
5580
- $match: {
5581
- storeId: { $in: storeDetails.map( ( ele ) => ele.storeId ) },
5582
- },
5583
- },
5584
- {
5585
- $group: {
5586
- _id: '$storeId',
5587
- storeName: { $first: '$storeName' },
5588
- planoId: { $first: '$planoId' },
5589
- floorId: { $first: '$_id' },
5590
- },
5591
- },
5592
- ];
5593
- let planoDetails = await storeBuilderService.aggregate( query );
5577
+ let planoDetails = await planoService.find( { storeId: { $in: storeDetails.map( ( ele ) => ele.storeId ) } }, { _id: 1, storeName: 1, storeId: 1 } );
5594
5578
  return res.sendSuccess( planoDetails );
5595
5579
  } catch ( e ) {
5596
5580
  logger.error( { functionName: 'getPlanoStoreList', error: e } );
5597
5581
  return res.sendError( e, 500 );
5598
5582
  }
5599
5583
  }
5600
-
5601
-
5602
- export async function getScandid( req, res ) {
5603
- try {
5604
- let getScanId = await planoStaticData.findOne( { type: 'app' } );
5605
- if ( !getScanId ) {
5606
- return res.sendError( 'No data found', 204 );
5607
- }
5608
- return res.sendSuccess( getScanId );
5609
- } catch ( e ) {
5610
- logger.error( { functionName: 'getScandid', error: e } );
5611
- return res.sendError( e, 500 );
5612
- }
5613
- }
@@ -55,5 +55,4 @@ storeBuilderRouter
55
55
  .get( '/getPlanoUser', isAllowedSessionHandler, storeBuilderController.getPlanoUser )
56
56
  .post( '/planoRolloutList', isAllowedSessionHandler, storeBuilderController.getRolloutDetails )
57
57
  .get( '/getRolloutTaskDetails', isAllowedSessionHandler, storeBuilderController.getRolloutTaskDetails )
58
- .get( '/getScandid', storeBuilderController.getScandid )
59
58
  .get( '/getPlanoStoreList', isAllowedSessionHandler, storeBuilderController.getPlanoStoreList );