tango-app-api-store-builder 1.0.55 → 1.0.56

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.55",
3
+ "version": "1.0.56",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable quotes */
2
2
  // import { writeFileSync } from 'fs';
3
3
  import xlsx from 'xlsx';
4
- import { logger, fileUpload, download } from 'tango-app-api-middleware';
4
+ import { logger, fileUpload, download, chunkArray } from 'tango-app-api-middleware';
5
5
  import * as storeBuilderService from '../service/storeBuilder.service.js';
6
6
  import * as storeService from '../service/store.service.js';
7
7
  import * as planoService from '../service/planogram.service.js';
@@ -15650,7 +15650,7 @@ export async function insertAntennaMappingData( req, res ) {
15650
15650
  { "shelfNumber": 2, "antennaNo": [ 8 ] },
15651
15651
  { "shelfNumber": 3, "antennaNo": [ 5 ] },
15652
15652
  { "shelfNumber": 4, "antennaNo": [ 4 ] },
15653
- { "shelfNumber": 5, "antennaNo": [ 3 ] },
15653
+ { "shelfNumber": 5, "antennaNo": [ 22 ] },
15654
15654
  { "shelfNumber": 6, "antennaNo": [ 2 ] },
15655
15655
  { "shelfNumber": 7, "antennaNo": [ 1 ] },
15656
15656
  ],
@@ -15662,7 +15662,7 @@ export async function insertAntennaMappingData( req, res ) {
15662
15662
  "storageBoxAntennaNo": [ 9, 10, 11, 12, 13 ],
15663
15663
  "shelfConfig": [
15664
15664
  { "shelfNumber": 1, "antennaNo": [ 21 ] },
15665
- { "shelfNumber": 2, "antennaNo": [ 22 ] },
15665
+ { "shelfNumber": 2, "antennaNo": [ 25 ] },
15666
15666
  { "shelfNumber": 3, "antennaNo": [ 18, 24 ] },
15667
15667
  { "shelfNumber": 4, "antennaNo": [ 19, 20 ] },
15668
15668
  { "shelfNumber": 5, "antennaNo": [ 14, 15 ] },
@@ -15671,66 +15671,66 @@ export async function insertAntennaMappingData( req, res ) {
15671
15671
  ],
15672
15672
  },
15673
15673
  {
15674
- "fixtureNumber": 16,
15674
+ "fixtureNumber": 18,
15675
15675
  "readerId": "A4-E8-A3-91-7E-FC",
15676
- "storageBoxAntennaNo": [ 11, 14, 8 ],
15676
+ "storageBoxAntennaNo": [ 13, 10, 2 ],
15677
15677
  "shelfConfig": [
15678
- { "shelfNumber": 1, "antennaNo": [ 15 ] },
15679
- { "shelfNumber": 2, "antennaNo": [ 12, 18 ] },
15680
- { "shelfNumber": 3, "antennaNo": [ 9, 10 ] },
15678
+ { "shelfNumber": 1, "antennaNo": [ 24, 9 ] },
15679
+ { "shelfNumber": 2, "antennaNo": [ 12, 11 ] },
15680
+ { "shelfNumber": 3, "antennaNo": [ 20, 25 ] },
15681
15681
  ],
15682
15682
  },
15683
15683
  {
15684
- "fixtureNumber": 17,
15684
+ "fixtureNumber": 20,
15685
15685
  "readerId": "A4-E8-A3-91-7E-FC",
15686
- "storageBoxAntennaNo": [ 2, 3, 1 ],
15686
+ "storageBoxAntennaNo": [ 3, 15, 1 ],
15687
15687
  "shelfConfig": [
15688
- { "shelfNumber": 1, "antennaNo": [ 5, 16 ] },
15689
- { "shelfNumber": 2, "antennaNo": [ 4, 13 ] },
15690
- { "shelfNumber": 3, "antennaNo": [ 17, 7 ] },
15688
+ { "shelfNumber": 1, "antennaNo": [ 5, 18 ] },
15689
+ { "shelfNumber": 2, "antennaNo": [ 7, 17 ] },
15690
+ { "shelfNumber": 3, "antennaNo": [ 4, 16 ] },
15691
15691
  ],
15692
15692
  },
15693
15693
  {
15694
- "fixtureNumber": 19,
15694
+ "fixtureNumber": 21,
15695
15695
  "readerId": "A4-E8-A3-91-7E-FC",
15696
15696
  "storageBoxAntennaNo": [],
15697
15697
  "shelfConfig": [
15698
- { "shelfNumber": 1, "antennaNo": [ 28, 29 ] },
15699
- { "shelfNumber": 2, "antennaNo": [ 19, 25 ] },
15700
- { "shelfNumber": 3, "antennaNo": [ 26, 27 ] },
15698
+ { "shelfNumber": 1, "antennaNo": [ 26, 22 ] },
15699
+ { "shelfNumber": 2, "antennaNo": [ 19, 23 ] },
15700
+ { "shelfNumber": 3, "antennaNo": [ 14, 18 ] },
15701
15701
  ],
15702
15702
  },
15703
15703
  {
15704
- "fixtureNumber": 18,
15704
+ "fixtureNumber": 17,
15705
15705
  "wallNumber": null,
15706
15706
  "readerId": "A4-E8-A3-91-7F-05",
15707
- "storageBoxAntennaNo": [ 17, 18, 23, 24 ],
15707
+ "storageBoxAntennaNo": [ 20, 18, 3 ],
15708
15708
  "shelfConfig": [
15709
- { "shelfNumber": 1, "antennaNo": [ 21, 22 ] },
15710
- { "shelfNumber": 2, "antennaNo": [ 25, 27 ] },
15711
- { "shelfNumber": 3, "antennaNo": [ 19, 20 ] },
15709
+ { "shelfNumber": 1, "antennaNo": [ 17, 25 ] },
15710
+ { "shelfNumber": 2, "antennaNo": [ 10, 15 ] },
15711
+ { "shelfNumber": 3, "antennaNo": [ 6, 19 ] },
15712
15712
  ],
15713
15713
  },
15714
15714
  {
15715
- "fixtureNumber": 20,
15715
+ "fixtureNumber": 16,
15716
15716
  "wallNumber": null,
15717
15717
  "readerId": "A4-E8-A3-91-7F-05",
15718
- "storageBoxAntennaNo": [ 8, 2, 3, 29 ],
15718
+ "storageBoxAntennaNo": [ 8, 2, 21, 27, 32 ],
15719
15719
  "shelfConfig": [
15720
- { "shelfNumber": 1, "antennaNo": [ 10, 11 ] },
15721
- { "shelfNumber": 2, "antennaNo": [ 7, 15 ] },
15722
- { "shelfNumber": 3, "antennaNo": [ 5, 16 ] },
15720
+ { "shelfNumber": 1, "antennaNo": [ 22, 11 ] },
15721
+ { "shelfNumber": 2, "antennaNo": [ 4, 16 ] },
15722
+ { "shelfNumber": 3, "antennaNo": [ 9, 28 ] },
15723
15723
  ],
15724
15724
  },
15725
15725
  {
15726
- "fixtureNumber": 21,
15726
+ "fixtureNumber": 19,
15727
15727
  "wallNumber": null,
15728
15728
  "readerId": "A4-E8-A3-91-7F-05",
15729
15729
  "storageBoxAntennaNo": [],
15730
15730
  "shelfConfig": [
15731
- { "shelfNumber": 1, "antennaNo": [ 12, 4 ] },
15732
- { "shelfNumber": 2, "antennaNo": [ 9, 14 ] },
15733
- { "shelfNumber": 3, "antennaNo": [ 1, 13 ] },
15731
+ { "shelfNumber": 1, "antennaNo": [ 12, 1 ] },
15732
+ { "shelfNumber": 2, "antennaNo": [ 23, 14 ] },
15733
+ { "shelfNumber": 3, "antennaNo": [ 13, 29 ] },
15734
15734
  ],
15735
15735
  },
15736
15736
 
@@ -15759,7 +15759,7 @@ export async function insertAntennaMappingData( req, res ) {
15759
15759
  if ( readerId ) {
15760
15760
  await storeFixtureService.updateOne(
15761
15761
  { _id: fixtureId },
15762
- { $set: { readerId: readerId } },
15762
+ { readerId: readerId },
15763
15763
  );
15764
15764
  console.log( `Updated fixture ${fixtureNumber} readerId:`, readerId );
15765
15765
  }
@@ -16044,7 +16044,6 @@ export async function get4487FixtureData( req, res ) {
16044
16044
  let data = [];
16045
16045
  if ( fixtureDetails.length ) {
16046
16046
  for ( let fixt of fixtureDetails ) {
16047
- console.log( fixt );
16048
16047
  let uniqueNumber = 'FX' + fixt.fixtureNumber?.toString()?.padStart( 2, '0' );
16049
16048
  let inputData = {
16050
16049
  Bucket: JSON.parse( process.env.BUCKET )?.storeBuilder,
@@ -16065,19 +16064,20 @@ export async function get4487FixtureData( req, res ) {
16065
16064
  ];
16066
16065
  let shelfDetails = await fixtureShelfService.aggregate( query );
16067
16066
  for ( let section of shelfDetails ) {
16068
- let productDetails = await planoMappingService.find( { shelfId: section._id }, { pid: 1 } );
16067
+ let productDetails = await planoMappingService.find( { shelfId: section._id }, { pid: 1, barCode: 1 } );
16069
16068
  productDetails.forEach( ( product ) => {
16070
- if ( product.pid ) {
16069
+ if ( product.pid != '0' ) {
16071
16070
  data.push( {
16072
16071
  productId: product.pid,
16073
16072
  storeCode: 'LKST4487',
16073
+ barCode: product.barCode,
16074
16074
  fixtureId: uniqueNumber,
16075
- fixtureNumber: fixt.associatedElementFixtureNumber,
16076
- fixtureName: fixt.fixtureName,
16075
+ // fixtureNumber: fixt.associatedElementFixtureNumber,
16076
+ // fixtureName: fixt.fixtureName,
16077
16077
  fixtureTitle: fixt?.header?.label,
16078
- uniqueFixtureNumber: fixt.fixtureNumber,
16079
- fixtureHeaderImageUrl: fixtureImage,
16080
- fullFixtureImageUrl: fixtureHeaderImage,
16078
+ // uniqueFixtureNumber: fixt.fixtureNumber,
16079
+ fixtureHeaderImageUrl: fixt.fixtureType == 'floor' ? fixtureImage: fixtureHeaderImage,
16080
+ fullFixtureImageUrl: fixtureImage,
16081
16081
  section: fixt?.associatedElementNumber ? section.zone : 'Full',
16082
16082
  shelfNumber: section.shelfNumber,
16083
16083
  wallNumber: fixt?.associatedElementNumber ?? 'floor',
@@ -16088,7 +16088,23 @@ export async function get4487FixtureData( req, res ) {
16088
16088
  }
16089
16089
  }
16090
16090
  }
16091
- return res.sendSuccess( data );
16091
+
16092
+ const fetchWithCookies = fetchCookie( fetch );
16093
+ let splitArray = await chunkArray( data, 50 );
16094
+ for ( let chunk of splitArray ) {
16095
+ let uploadData = await fetchWithCookies( `https://api-gateway.juno.lenskart.com/v2/lenskart-personalize/fixture-mappings/bulk`, {
16096
+ method: 'POST',
16097
+ headers: {
16098
+ 'Content-Type': 'application/json',
16099
+ 'Cookie': '__cf_bm=MkKoKWIxlAN21LorpSTh6yRib4s2TL_RFWTLDAdNA0I-1769622733-1.0.1.1-5KpHJzGgnbtf01g7DoWkWUlTMLssLy1qKcfj4avp_R7E6Q6gvda.1NblcCfBdqCcKJ.GhiTRx1hcqhVmVZq4X3j6.gt4LGo4vYX9YjpN2O4',
16100
+ },
16101
+ body: JSON.stringify( { data: chunk } ),
16102
+ } );
16103
+
16104
+ console.log( uploadData );
16105
+ }
16106
+
16107
+ return res.sendSuccess( chunkArray );
16092
16108
  } catch ( e ) {
16093
16109
  console.log( e );
16094
16110
  logger.error( { functionName: 'get4487FixtureData', error: e } );
@@ -8245,7 +8245,7 @@ export async function updateProductMappingNew( req, res ) {
8245
8245
  'planoMappingId': '',
8246
8246
  'date': dayjs().format( 'YYYY-MM-DD' ),
8247
8247
  'clientId': req.body.clientId,
8248
- 'compliance': ele?.shelfType != 'storage' ? ( ele?.productBrandName?.split( ',' ).includes( product?.brandName ) || fixtureTemplate?.templateGroupName == product?.brandGroup )? 'proper' : 'misplaced' : '',
8248
+ 'compliance': ele?.shelfType != 'storage' ? ( ele?.productBrandName?.split( ',' )?.map( ( element ) => element.trim() )?.includes( product?.brandName ) || fixtureTemplate?.templateGroupName == product?.brandGroup )? 'proper' : 'misplaced' : '',
8249
8249
  'fixtureId': ele?.fixtureId,
8250
8250
  'floorId': ele?.floorId,
8251
8251
  'planoId': ele?.planoId,
@@ -8304,14 +8304,13 @@ export async function updateProductMappingNew( req, res ) {
8304
8304
 
8305
8305
  export async function calculateCompliance( req, res ) {
8306
8306
  try {
8307
- let clFixtures = await storeFixtureService.findOne( { 'header.label': 'CL' }, { _id: 1 } );
8307
+ let clFixtures = await storeFixtureService.findOne( { 'planoId': req.body.planoId, 'floorId': req.body.floorId, 'header.label': 'CL' }, { _id: 1 } );
8308
8308
  let query = [
8309
8309
  {
8310
8310
  $match: {
8311
8311
  planoId: new mongoose.Types.ObjectId( req.body.planoId ),
8312
8312
  floorId: new mongoose.Types.ObjectId( req.body.floorId ),
8313
8313
  storeName: req.body.storeName,
8314
- compliance: 'proper',
8315
8314
  date: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
8316
8315
  fixtureId: { $ne: clFixtures._id },
8317
8316
  },
@@ -8319,7 +8318,6 @@ export async function calculateCompliance( req, res ) {
8319
8318
  {
8320
8319
  $group: {
8321
8320
  _id: '$createdAt',
8322
- count: { $sum: 1 },
8323
8321
  },
8324
8322
  },
8325
8323
  {
@@ -8406,7 +8404,23 @@ export async function calculateCompliance( req, res ) {
8406
8404
  },
8407
8405
  ];
8408
8406
  let getCompliance = await planoComplianceService.aggregate( query );
8407
+ let fixtureDetails = await storeFixtureService.find( { planoId: new mongoose.Types.ObjectId( req.body.planoId ), floorId: new mongoose.Types.ObjectId( req.body.floorId ), _id: { $ne: clFixtures._id }, fixtureType: { $ne: 'other' } }, { _id: 1, fixtureCapacity: 1 } );
8408
+
8409
+ getCompliance = await Promise.all( getCompliance.map( async ( ele ) => {
8410
+ ele['count'] =0;
8411
+ if ( ele.date ) {
8412
+ let properCount = 0;
8413
+ for ( let fixture of fixtureDetails ) {
8414
+ let planoDetails = await planoComplianceService.find( { createdAt: new Date( ele.date ), fixtureId: fixture._id, compliance: 'proper' } );
8415
+ properCount = properCount + ( ( planoDetails.length / fixture.fixtureCapacity ) * 100 );
8416
+ }
8417
+
8418
+
8419
+ ele['count'] = Math.floor( properCount / fixtureDetails.length );
8409
8420
 
8421
+ return ele;
8422
+ }
8423
+ } ) );
8410
8424
  let result = {
8411
8425
  merchCompliance: 0,
8412
8426
  previousMerchCompliance: 0,
@@ -8414,27 +8428,28 @@ export async function calculateCompliance( req, res ) {
8414
8428
  lastCheck: null,
8415
8429
  };
8416
8430
  if ( getCompliance.length ) {
8417
- let productCountQuery = [
8418
- {
8419
- $match: {
8420
- planoId: new mongoose.Types.ObjectId( req.body.planoId ),
8421
- floorId: new mongoose.Types.ObjectId( req.body.floorId ),
8422
- },
8423
- },
8424
- {
8425
- $group: {
8426
- _id: '$floorId',
8427
- productCount: { $sum: '$fixtureCapacity' },
8428
- },
8429
- },
8430
- {
8431
- $project: {
8432
- _id: 0,
8433
- productCount: 1,
8434
- },
8435
- },
8436
- ];
8437
- let totalProducts = await storeFixtureService.aggregate( productCountQuery );
8431
+ // let productCountQuery = [
8432
+ // {
8433
+ // $match: {
8434
+ // planoId: new mongoose.Types.ObjectId( req.body.planoId ),
8435
+ // floorId: new mongoose.Types.ObjectId( req.body.floorId ),
8436
+ // fixtureId: { $ne: clFixtures._id },
8437
+ // },
8438
+ // },
8439
+ // {
8440
+ // $group: {
8441
+ // _id: '$floorId',
8442
+ // productCount: { $sum: '$fixtureCapacity' },
8443
+ // },
8444
+ // },
8445
+ // {
8446
+ // $project: {
8447
+ // _id: 0,
8448
+ // productCount: 1,
8449
+ // },
8450
+ // },
8451
+ // ];
8452
+ // let totalProducts = await storeFixtureService.aggregate( productCountQuery );
8438
8453
  // function formatPercentage( value ) {
8439
8454
  // if ( value >= 100 ) return 100;
8440
8455
 
@@ -8442,22 +8457,22 @@ export async function calculateCompliance( req, res ) {
8442
8457
 
8443
8458
  // return Number.isInteger( truncated ) ? Math.trunc( truncated ) : truncated;
8444
8459
  // }
8445
- if ( totalProducts.length ) {
8446
- result.merchCompliance = Math.floor( ( getCompliance?.[0]?.count / totalProducts?.[0]?.productCount ) * 100 );
8447
- let previousMerchCompliance = getCompliance?.[1]?.count ? Math.floor( ( getCompliance?.[1]?.count / totalProducts?.[0]?.productCount ) * 100 ) : 0;
8448
- if ( getCompliance.length > 1 && result.merchCompliance != previousMerchCompliance ) {
8449
- if ( result.merchCompliance > previousMerchCompliance ) {
8450
- let diff = result.merchCompliance - previousMerchCompliance;
8451
- result.previousMerchCompliance = diff;
8452
- result.rateIncrease = true;
8453
- } else {
8454
- let diff = previousMerchCompliance - result.merchCompliance;
8455
- result.previousMerchCompliance = diff;
8456
- result.rateIncrease = false;
8457
- }
8460
+ // if ( totalProducts.length ) {
8461
+ result.merchCompliance = getCompliance?.[0]?.count;
8462
+ let previousMerchCompliance = getCompliance?.[1]?.count ? getCompliance?.[1]?.count : 0;
8463
+ if ( getCompliance.length > 1 && result.merchCompliance != previousMerchCompliance ) {
8464
+ if ( result.merchCompliance > previousMerchCompliance ) {
8465
+ let diff = result.merchCompliance - previousMerchCompliance;
8466
+ result.previousMerchCompliance = diff;
8467
+ result.rateIncrease = true;
8468
+ } else {
8469
+ let diff = previousMerchCompliance - result.merchCompliance;
8470
+ result.previousMerchCompliance = diff;
8471
+ result.rateIncrease = false;
8458
8472
  }
8459
- result.lastCheck = `${getCompliance?.[0]?.time}`;
8460
8473
  }
8474
+ result.lastCheck = `${getCompliance?.[0]?.time}`;
8475
+ // }
8461
8476
  }
8462
8477
  return res.sendSuccess( result );
8463
8478
  } catch ( e ) {