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

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-202",
3
+ "version": "1.0.0-beta-204",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -9549,147 +9549,148 @@ 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 });
9607
9605
 
9608
- if (!fixtureTemplateData?.length) {
9609
- return res.sendError("No shelves found for fixtureId", 404);
9606
+ const fixtureTemplateData = await fixtureShelfService.find( { fixtureId } );
9607
+
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,
9629
9630
  planoId,
9630
9631
  floorId,
9631
9632
  fixtureId,
9632
- shelfId: "temp", // will be reassigned in transformProducts
9633
- }));
9633
+ shelfId: 'temp', // will be reassigned in transformProducts
9634
+ } ) );
9634
9635
 
9635
- if(CLEAR_COL_BEFORE_INSERT) await planoMappingService.deleteMany({});
9636
+ if ( CLEAR_COL_BEFORE_INSERT ) await planoMappingService.deleteMany( {} );
9636
9637
 
9637
9638
  const shelfGroups = {
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),
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 ),
9641
9642
  };
9642
9643
 
9643
- const transformed = transformProducts(planoMappings, shelfGroups, fixtureData);
9644
+ const transformed = transformProducts( planoMappings, shelfGroups, fixtureData );
9644
9645
 
9645
- const result2 = await planoMappingService.insertMany(transformed);
9646
+ const result2 = await planoMappingService.insertMany( transformed );
9646
9647
 
9647
- res.sendSuccess({
9648
+ res.sendSuccess( {
9648
9649
  fixtureData,
9649
9650
  shelfGroups,
9650
9651
  planoMappings: result2,
9651
- });
9652
- } catch (error) {
9653
- console.log("@@ ~ error:", error);
9654
- res.sendError("Internal Server Error", 500);
9652
+ } );
9653
+ } catch ( error ) {
9654
+ console.log( '@@ ~ error:', error );
9655
+ res.sendError( 'Internal Server Error', 500 );
9655
9656
  }
9656
9657
  }
9657
9658
 
9658
- function transformProducts(products, shelvesByZone, fixtureData) {
9659
+ function transformProducts( products, shelvesByZone, fixtureData ) {
9659
9660
  const result = [];
9660
9661
 
9661
9662
  // Build lookup: pid → zone
9662
9663
  const pidToZone = {};
9663
- for (const [zone, pids] of Object.entries(fixtureData)) {
9664
- pids.forEach(pid => {
9664
+ for ( const [ zone, pids ] of Object.entries( fixtureData ) ) {
9665
+ pids.forEach( ( pid ) => {
9665
9666
  pidToZone[pid] = zone;
9666
- });
9667
+ } );
9667
9668
  }
9668
9669
 
9669
9670
  // Group products by zone
9670
9671
  const productsByZone = {};
9671
- for (const doc of products) {
9672
+ for ( const doc of products ) {
9672
9673
  const zone = pidToZone[doc.pid];
9673
- if (!zone) continue;
9674
- if (!productsByZone[zone]) productsByZone[zone] = [];
9675
- productsByZone[zone].push(doc);
9674
+ if ( !zone ) continue;
9675
+ if ( !productsByZone[zone] ) productsByZone[zone] = [];
9676
+ productsByZone[zone].push( doc );
9676
9677
  }
9677
9678
 
9678
9679
  // Round-robin distribute products across shelves
9679
- for (const [zone, docs] of Object.entries(productsByZone)) {
9680
+ for ( const [ zone, docs ] of Object.entries( productsByZone ) ) {
9680
9681
  const shelves = shelvesByZone[zone] || [];
9681
- if (shelves.length === 0) {
9682
- result.push(...docs);
9682
+ if ( shelves.length === 0 ) {
9683
+ result.push( ...docs );
9683
9684
  continue;
9684
9685
  }
9685
9686
 
9686
- docs.forEach((doc, idx) => {
9687
+ docs.forEach( ( doc, idx ) => {
9687
9688
  const shelfId = shelves[idx % shelves.length]; // cycle through shelves
9688
- result.push({
9689
+ result.push( {
9689
9690
  ...doc,
9690
- shelfId
9691
- });
9692
- });
9691
+ shelfId,
9692
+ } );
9693
+ } );
9693
9694
  }
9694
9695
 
9695
9696
  return result;
@@ -5575,10 +5575,39 @@ export async function getPlanoStoreList( req, res ) {
5575
5575
  if ( !storeDetails.length ) {
5576
5576
  return res.sendError( 'No data found', 204 );
5577
5577
  }
5578
- let planoDetails = await planoService.find( { storeId: { $in: storeDetails.map( ( ele ) => ele.storeId ) } }, { _id: 1, storeName: 1, storeId: 1 } );
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 );
5579
5594
  return res.sendSuccess( planoDetails );
5580
5595
  } catch ( e ) {
5581
5596
  logger.error( { functionName: 'getPlanoStoreList', error: e } );
5582
5597
  return res.sendError( e, 500 );
5583
5598
  }
5584
5599
  }
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
+ }
@@ -15,7 +15,8 @@ import * as floorService from '../service/storeBuilder.service.js';
15
15
  import * as planoStaticService from '../service/planoStaticData.service.js';
16
16
  import * as assignService from '../service/assignService.service.js';
17
17
  import * as storeBuilderService from '../service/storeBuilder.service.js';
18
- // import * as storeFixtureService from '../service/storeFixture.service.js';
18
+ import * as storeFixtureService from '../service/storeFixture.service.js';
19
+ import * as fixtureShelfService from '../service/fixtureShelf.service.js';
19
20
 
20
21
 
21
22
  dayjs.extend( timeZone );
@@ -676,8 +677,6 @@ export async function updateAnswersv2( req, res ) {
676
677
  if ( !taskDetails ) {
677
678
  return res.sendError( 'No data found', 204 );
678
679
  }
679
- console.log( req.body.answers[0] );
680
- console.log( req.body.answers[0].issues[0] );
681
680
  let data = {
682
681
  fixtureId: req.body.fixtureId,
683
682
  answers: req.body.answers,
@@ -692,8 +691,6 @@ export async function updateAnswersv2( req, res ) {
692
691
  storeId: req.body?.storeId,
693
692
  date_string: dayjs().format( 'YYYY-MM-DD' ),
694
693
  };
695
- console.log( '111111', data.answers[0] );
696
- console.log( '111111', data.answers[0].issues[0] );
697
694
  if ( req.body.type === 'layout' ) {
698
695
  await planoTaskService.updateOne( { planoId: req.body.planoId, taskType: req.body.taskType, floorId: req.body.floorId, fixtureId: req.body.fixtureId, type: req.body.type, ...( taskDetails?._id ) ? { taskId: taskDetails?._id } : {} }, data );
699
696
  } else {
@@ -713,6 +710,35 @@ export async function updateAnswersv2( req, res ) {
713
710
  await sendMessageToQueue( `${sqs.url}${sqs.storeBuilder}`, JSON.stringify( sqsData ) );
714
711
  }
715
712
 
713
+ if ( req.body.type === 'fixture' ) {
714
+ let fixtureData = await storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( req.body.fixtureId ) } );
715
+
716
+ if ( fixtureData ) {
717
+ fixtureData = fixtureData?.toObject();
718
+
719
+ let fixtureShelves = await fixtureShelfService.find( { fixtureId: fixtureData._id } );
720
+
721
+ if ( fixtureShelves.length ) {
722
+ fixtureShelves = fixtureShelves.map( ( shelf ) => shelf?.toObject() );
723
+
724
+ fixtureData.shelfConfig = fixtureShelves;
725
+ }
726
+ }
727
+
728
+ let sqsData = {
729
+ bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
730
+ date_string: dayjs().format( 'YYYY-MM-DD' ),
731
+ storeName: data?.storeName,
732
+ imagePath: data?.answers[0]?.image,
733
+ fixtureId: req.body.fixtureId,
734
+ fixtureData: fixtureData,
735
+ };
736
+
737
+ const sqs = JSON.parse( process.env.SQS );
738
+ await sendMessageToQueue( `${sqs.url}${sqs.fixtureImageProcess}`, JSON.stringify( sqsData ) );
739
+ }
740
+
741
+
716
742
  return res.sendSuccess( 'Fixture details updated successfully' );
717
743
  } catch ( e ) {
718
744
  logger.error( { functionName: 'updateAnswers', error: e } );
@@ -55,4 +55,5 @@ 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 )
58
59
  .get( '/getPlanoStoreList', isAllowedSessionHandler, storeBuilderController.getPlanoStoreList );