tango-app-api-store-builder 1.0.49 → 1.0.50

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.49",
3
+ "version": "1.0.50",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -33,7 +33,7 @@
33
33
  "path": "^0.12.7",
34
34
  "selenium-webdriver": "^4.31.0",
35
35
  "sharp": "^0.34.1",
36
- "tango-api-schema": "^2.5.35",
36
+ "tango-api-schema": "^2.5.37",
37
37
  "tango-app-api-middleware": "3.1.48",
38
38
  "url": "^0.11.4",
39
39
  "winston": "^3.17.0",
@@ -948,7 +948,7 @@ export async function updateStorePlano( req, res ) {
948
948
  storeName: floorData.toObject().storeName,
949
949
  storeId: floorData.toObject().storeId,
950
950
  planoChanges: JSON.stringify( currentFixtures ),
951
-
951
+ date_string: dayjs( 'YYYY-MM-DD' ),
952
952
  };
953
953
 
954
954
  await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoLog, insertData );
@@ -1597,6 +1597,7 @@ export async function updateStoreFixture( req, res ) {
1597
1597
  storeName: currentFixture.storeName,
1598
1598
  storeId: currentFixture.storeId,
1599
1599
  planoChanges: JSON.stringify( currentFixture ),
1600
+ date_string: dayjs( 'YYYY-MM-DD' ),
1600
1601
  };
1601
1602
 
1602
1603
  await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).planoLog, insertData );
@@ -2545,7 +2546,6 @@ export async function createPlanoFromCAD( req, res ) {
2545
2546
  } );
2546
2547
  }
2547
2548
 
2548
-
2549
2549
  try {
2550
2550
  const updateStoreFixtures = await processFixtureTemplates( { fixtures: storeFixtures } );
2551
2551
 
@@ -2557,14 +2557,14 @@ export async function createPlanoFromCAD( req, res ) {
2557
2557
  } );
2558
2558
  }
2559
2559
 
2560
- return res.sendSuccess(meta);
2561
- } catch (error) {
2562
- logger.error({
2560
+ return res.sendSuccess( meta );
2561
+ } catch ( error ) {
2562
+ logger.error( {
2563
2563
  functionName: 'createPlanoFromCAD',
2564
2564
  error,
2565
- });
2565
+ } );
2566
2566
 
2567
- return res.sendError({ errMsg: 'Failed to create planogram.', errInfo: error }, 500);
2567
+ return res.sendError( { errMsg: 'Failed to create planogram.', errInfo: error }, 500 );
2568
2568
  }
2569
2569
  }
2570
2570
 
@@ -2781,21 +2781,19 @@ async function processFixtureTemplates( data ) {
2781
2781
  return updateStoreFixtures;
2782
2782
  }
2783
2783
 
2784
-
2785
- export async function approvePlanoLayout(req, res) {
2784
+ export async function approvePlanoLayout( req, res ) {
2786
2785
  try {
2787
-
2788
2786
  const { floorId } = req.body;
2789
2787
 
2790
2788
  await floorService.updateOne(
2791
- { _id: new mongoose.Types.ObjectId(floorId) },
2792
- {
2793
- isPlanoApproved: true,
2794
- },
2789
+ { _id: new mongoose.Types.ObjectId( floorId ) },
2790
+ {
2791
+ isPlanoApproved: true,
2792
+ },
2795
2793
  );
2796
- res.sendSuccess(true);
2797
- } catch (error) {
2798
- logger.error({ functionName: 'approvePlanoLayout', error: e });
2799
- res.sendError('Failed to approve planogram', 500);
2794
+ res.sendSuccess( true );
2795
+ } catch ( error ) {
2796
+ logger.error( { functionName: 'approvePlanoLayout', error: e } );
2797
+ res.sendError( 'Failed to approve planogram', 500 );
2800
2798
  }
2801
- }
2799
+ }
@@ -15412,6 +15412,7 @@ export async function update4487Inventory( req, res ) {
15412
15412
  category: element.collection,
15413
15413
  productImageUrl: element.image_front,
15414
15414
  productId: req.body.pidData[i].products[j],
15415
+ pid: element.product_id,
15415
15416
  };
15416
15417
  } else {
15417
15418
  updateData = {
@@ -15425,6 +15426,7 @@ export async function update4487Inventory( req, res ) {
15425
15426
  category: 'Unknown',
15426
15427
  productImageUrl: raw?.[0]?.image_front,
15427
15428
  productId: req.body.pidData[i].products[j],
15429
+ pid: element.product_id,
15428
15430
  };
15429
15431
  }
15430
15432
  const product = await planoProductService.create( updateData );
@@ -15617,8 +15619,8 @@ export async function insertAntennaMappingData( req, res ) {
15617
15619
  { "shelfNumber": 3, "antennaNo": [ 10 ] },
15618
15620
  { "shelfNumber": 4, "antennaNo": [ 8 ] },
15619
15621
  { "shelfNumber": 5, "antennaNo": [ 12 ] },
15620
- { "shelfNumber": 6, "antennaNo": [ 4 ] },
15621
- { "shelfNumber": 7, "antennaNo": [ 9 ] },
15622
+ { "shelfNumber": 6, "antennaNo": [ 9 ] },
15623
+ { "shelfNumber": 7, "antennaNo": [ 4 ] },
15622
15624
  { "shelfNumber": 8, "antennaNo": [ 3 ] },
15623
15625
  ],
15624
15626
  },
@@ -15871,13 +15873,13 @@ export async function get4487FixtureDetails( req, res ) {
15871
15873
  }
15872
15874
  }
15873
15875
 
15874
- export async function getstoreMBQFixtureExcel(req, res) {
15876
+ export async function getstoreMBQFixtureExcel( req, res ) {
15875
15877
  try {
15876
- const fromDate = new Date(dayjs().subtract(1, 'day').format('YYYY-MM-DD'));
15877
- let toDate = new Date(dayjs().subtract(1, 'day').format('YYYY-MM-DD'));
15878
+ const fromDate = new Date( dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' ) );
15879
+ let toDate = new Date( dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' ) );
15878
15880
  const userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
15879
- toDate = new Date(toDate.getTime() - userTimezoneOffset);
15880
- toDate.setUTCHours(23, 59, 59, 59);
15881
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
15882
+ toDate.setUTCHours( 23, 59, 59, 59 );
15881
15883
 
15882
15884
  let query = [
15883
15885
  {
@@ -15898,45 +15900,45 @@ export async function getstoreMBQFixtureExcel(req, res) {
15898
15900
  },
15899
15901
  ];
15900
15902
 
15901
- let planorevisions = await planoRevisionService.aggregate(query);
15903
+ let planorevisions = await planoRevisionService.aggregate( query );
15902
15904
  let data = [];
15903
- let sortOrder = [5, 1, 2, 3, 4];
15905
+ let sortOrder = [ 5, 1, 2, 3, 4 ];
15904
15906
 
15905
- await Promise.all(planorevisions.map(async (revision) => {
15906
- let wallFixtures = revision?.data?.floorData?.layoutPolygon.flatMap((ele) => ele.fixtures);
15907
+ await Promise.all( planorevisions.map( async ( revision ) => {
15908
+ let wallFixtures = revision?.data?.floorData?.layoutPolygon.flatMap( ( ele ) => ele.fixtures );
15907
15909
  let centerFixtures = revision?.data?.floorData?.centerFixture;
15908
- let storeFixturesList = [...wallFixtures, ...centerFixtures];
15910
+ let storeFixturesList = [ ...wallFixtures, ...centerFixtures ];
15909
15911
 
15910
- storeFixturesList.sort((a, b) => {
15911
- const floorDiff = b.floorId.toString().localeCompare(a.floorId.toString());
15912
- if (floorDiff !== 0) return floorDiff;
15912
+ storeFixturesList.sort( ( a, b ) => {
15913
+ const floorDiff = b.floorId.toString().localeCompare( a.floorId.toString() );
15914
+ if ( floorDiff !== 0 ) return floorDiff;
15913
15915
 
15914
- if (a.fixtureType !== b.fixtureType) {
15916
+ if ( a.fixtureType !== b.fixtureType ) {
15915
15917
  return a.fixtureType === "wall" ? -1 : 1;
15916
15918
  }
15917
15919
 
15918
- if (a.fixtureType === "wall") {
15920
+ if ( a.fixtureType === "wall" ) {
15919
15921
  const orderDiff =
15920
- sortOrder.indexOf(a.associatedElementNumber) -
15921
- sortOrder.indexOf(b.associatedElementNumber);
15922
+ sortOrder.indexOf( a.associatedElementNumber ) -
15923
+ sortOrder.indexOf( b.associatedElementNumber );
15922
15924
 
15923
- if (orderDiff !== 0) return orderDiff;
15925
+ if ( orderDiff !== 0 ) return orderDiff;
15924
15926
 
15925
15927
  return (
15926
- (a.associatedElementFixtureNumber || 0) -
15927
- (b.associatedElementFixtureNumber || 0)
15928
+ ( a.associatedElementFixtureNumber || 0 ) -
15929
+ ( b.associatedElementFixtureNumber || 0 )
15928
15930
  );
15929
15931
  }
15930
15932
 
15931
15933
  return 0;
15932
- });
15934
+ } );
15933
15935
 
15934
15936
 
15935
15937
  let storeFixtureDetails = [];
15936
- for (let ele of storeFixturesList) {
15937
- let shelfDetails = await fixtureShelfService.findAndSort({ fixtureId: ele._id }, {}, { shelfNumber: 1 });
15938
+ for ( let ele of storeFixturesList ) {
15939
+ let shelfDetails = await fixtureShelfService.findAndSort( { fixtureId: ele._id }, {}, { shelfNumber: 1 } );
15938
15940
 
15939
- storeFixtureDetails.push({
15941
+ storeFixtureDetails.push( {
15940
15942
  "Store Code": ele.storeName,
15941
15943
  "Wall": ele?.associatedElementNumber ?? 'floor',
15942
15944
  "Unique Fixture Number": 'FX - ' + ele.fixtureNumber,
@@ -15949,91 +15951,148 @@ export async function getstoreMBQFixtureExcel(req, res) {
15949
15951
  },
15950
15952
  );
15951
15953
  }
15952
- data.push(...storeFixtureDetails);
15953
- }));
15954
+ data.push( ...storeFixtureDetails );
15955
+ } ) );
15954
15956
 
15955
15957
 
15956
15958
  // ------------------------------------------------
15957
- const originalSend = res.send.bind(res);
15959
+ const originalSend = res.send.bind( res );
15958
15960
 
15959
- res.send = async (buffer) => {
15960
- const uploadDate = dayjs().format('DD-MM-YYYY');
15961
- const uploadTime = dayjs().format('HH-mm-ss');
15961
+ res.send = async ( buffer ) => {
15962
+ const uploadDate = dayjs().format( 'DD-MM-YYYY' );
15963
+ const uploadTime = dayjs().format( 'HH-mm-ss' );
15962
15964
  const fileName = `mbq_${uploadTime}.xlsx`;
15963
15965
 
15964
- const tempFilePath = path.join(os.tmpdir(), fileName);
15966
+ const tempFilePath = path.join( os.tmpdir(), fileName );
15965
15967
 
15966
15968
  try {
15967
15969
  // 1️⃣ Write buffer to temp file
15968
- fs.writeFileSync(tempFilePath, buffer);
15970
+ fs.writeFileSync( tempFilePath, buffer );
15969
15971
 
15970
15972
  // 2️⃣ Create multipart form with REAL FILE
15971
15973
  const formData = new FormData();
15972
15974
  formData.append(
15973
- 'file',
15974
- fs.createReadStream(tempFilePath),
15975
- fileName
15975
+ 'file',
15976
+ fs.createReadStream( tempFilePath ),
15977
+ fileName,
15976
15978
  );
15977
15979
 
15978
15980
  // 3️⃣ Upload using node-fetch
15979
15981
  const response = await fetch(
15980
- `${JSON.parse(process.env.LAMBDAURL).mbqFileUpload}` +
15981
- `?date=${uploadDate}&filename=${encodeURIComponent(fileName)}`,
15982
- {
15983
- method: 'POST',
15984
- body: formData,
15985
- headers: formData.getHeaders()
15986
- }
15982
+ `${JSON.parse( process.env.LAMBDAURL ).mbqFileUpload}` +
15983
+ `?date=${uploadDate}&filename=${encodeURIComponent( fileName )}`,
15984
+ {
15985
+ method: 'POST',
15986
+ body: formData,
15987
+ headers: formData.getHeaders(),
15988
+ },
15987
15989
  );
15988
15990
 
15989
15991
  const resultText = await response.text();
15990
15992
 
15991
- if (response.ok) {
15992
- logger.info({
15993
+ if ( response.ok ) {
15994
+ logger.info( {
15993
15995
  functionName: 'MBQUploadSuccess',
15994
15996
  fileName,
15995
15997
  uploadDate,
15996
- result: resultText
15997
- });
15998
+ result: resultText,
15999
+ } );
15998
16000
  } else {
15999
- logger.error({
16001
+ logger.error( {
16000
16002
  functionName: 'MBQUploadFailed',
16001
16003
  status: response.status,
16002
16004
  fileName,
16003
16005
  uploadDate,
16004
- result: resultText
16005
- });
16006
+ result: resultText,
16007
+ } );
16006
16008
  }
16007
-
16008
- } catch (err) {
16009
- logger.error({
16009
+ } catch ( err ) {
16010
+ logger.error( {
16010
16011
  functionName: 'MBQUploadError',
16011
16012
  fileName,
16012
16013
  uploadDate,
16013
- error: err
16014
- });
16014
+ error: err,
16015
+ } );
16015
16016
  } finally {
16016
16017
  // 4️⃣ Cleanup temp file
16017
- if (fs.existsSync(tempFilePath)) {
16018
- fs.unlinkSync(tempFilePath);
16018
+ if ( fs.existsSync( tempFilePath ) ) {
16019
+ fs.unlinkSync( tempFilePath );
16019
16020
  }
16020
16021
  }
16021
16022
 
16022
16023
  // 5️⃣ Continue normal download
16023
- return originalSend(buffer);
16024
+ return originalSend( buffer );
16024
16025
  };
16025
16026
 
16026
16027
 
16027
16028
  // ------------------------------------------------
16028
16029
 
16029
- if (!data.length) {
16030
- return res.sendError('No data available for export', 204);
16030
+ if ( !data.length ) {
16031
+ return res.sendError( 'No data available for export', 204 );
16031
16032
  }
16032
16033
 
16033
- await download(data, res);
16034
- } catch (e) {
16035
- logger.error({ functionName: "getstoreMBQFixtureExcel", error: e });
16036
- return res.sendError(e, 500);
16034
+ await download( data, res );
16035
+ } catch ( e ) {
16036
+ logger.error( { functionName: "getstoreMBQFixtureExcel", error: e } );
16037
+ return res.sendError( e, 500 );
16038
+ }
16039
+ }
16040
+
16041
+ export async function get4487FixtureData( req, res ) {
16042
+ try {
16043
+ let fixtureDetails = await storeFixtureService.find( { planoId: new mongoose.Types.ObjectId( '690b2b9dc27523201d101bbb' ), fixtureType: { $ne: 'other' } } );
16044
+ let data = [];
16045
+ if ( fixtureDetails.length ) {
16046
+ for ( let fixt of fixtureDetails ) {
16047
+ console.log( fixt );
16048
+ let uniqueNumber = 'FX' + fixt.fixtureNumber?.toString()?.padStart( 2, '0' );
16049
+ let inputData = {
16050
+ Bucket: JSON.parse( process.env.BUCKET )?.storeBuilder,
16051
+ file_path: `fixtureImage/${uniqueNumber}.jpeg`,
16052
+ };
16053
+ let fixtureImage = await signedUrl( inputData );
16054
+ let headerData = {
16055
+ Bucket: JSON.parse( process.env.BUCKET )?.storeBuilder,
16056
+ file_path: `fixtureImage/${uniqueNumber}VM.png`,
16057
+ };
16058
+ let fixtureHeaderImage = await signedUrl( headerData );
16059
+ let query = [
16060
+ {
16061
+ $match: {
16062
+ fixtureId: fixt._id,
16063
+ },
16064
+ },
16065
+ ];
16066
+ let shelfDetails = await fixtureShelfService.aggregate( query );
16067
+ for ( let section of shelfDetails ) {
16068
+ let productDetails = await planoMappingService.find( { shelfId: section._id }, { pid: 1 } );
16069
+ productDetails.forEach( ( product ) => {
16070
+ if ( product.pid ) {
16071
+ data.push( {
16072
+ productId: product.pid,
16073
+ storeCode: 'LKST4487',
16074
+ fixtureId: uniqueNumber,
16075
+ fixtureNumber: fixt.associatedElementFixtureNumber,
16076
+ fixtureName: fixt.fixtureName,
16077
+ fixtureTitle: fixt?.header?.label,
16078
+ uniqueFixtureNumber: fixt.fixtureNumber,
16079
+ fixtureHeaderImageUrl: fixtureImage,
16080
+ fullFixtureImageUrl: fixtureHeaderImage,
16081
+ section: fixt?.associatedElementNumber ? section.zone : 'Full',
16082
+ shelfNumber: section.shelfNumber,
16083
+ wallNumber: fixt?.associatedElementNumber ?? 'floor',
16084
+ lastUpdatedAt: dayjs( fixt.updatedAt ).valueOf(),
16085
+ } );
16086
+ }
16087
+ } );
16088
+ }
16089
+ }
16090
+ }
16091
+ return res.sendSuccess( data );
16092
+ } catch ( e ) {
16093
+ console.log( e );
16094
+ logger.error( { functionName: 'get4487FixtureData', error: e } );
16095
+ return res.sendError( e, 500 );
16037
16096
  }
16038
16097
  }
16039
16098
 
@@ -2794,7 +2794,7 @@ export async function storeFixturesv2( req, res ) {
2794
2794
  planograms.map( async ( planogram ) => {
2795
2795
  const floors = await storeBuilderService.find(
2796
2796
  { planoId: planogram._id, ...( req.body?.floorId && { _id: req.body.floorId } ) },
2797
- { floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1, planoProgress: 1, updatedAt: 1, verificationStatus: 1, merchRolloutStatus: 1, vmRolloutStatus: 1, cadLayout: 1,isPlanoApproved:1 },
2797
+ { floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1, planoProgress: 1, updatedAt: 1, verificationStatus: 1, merchRolloutStatus: 1, vmRolloutStatus: 1, cadLayout: 1, isPlanoApproved: 1 },
2798
2798
  );
2799
2799
 
2800
2800
  const floorsWithFixtures = await Promise.all(
@@ -3616,7 +3616,7 @@ export async function shelfProduct( req, res ) {
3616
3616
  let notProperCount = shelfProducts.flatMap( ( ele ) => ele?.products.map( ( prod ) => prod?.status ) )?.filter( ( ele ) => ele != 'proper' )?.length;
3617
3617
 
3618
3618
  if ( fixtureCompliance == 100 && notProperCount ) {
3619
- nonProperpercentage = ( notProperCount /fixtureCompliance ) * 100;
3619
+ let nonProperpercentage = ( notProperCount /fixtureCompliance ) * 100;
3620
3620
 
3621
3621
  fixtureCompliance = fixtureCompliance - nonProperpercentage;
3622
3622
  }
@@ -6063,6 +6063,12 @@ export async function planoList( req, res ) {
6063
6063
  }
6064
6064
  }
6065
6065
 
6066
+ if (inputData.filter?.planoStrategy) {
6067
+ orQuery.push({
6068
+ planoStrategy: req.body?.filter?.planoStrategy,
6069
+ });
6070
+ }
6071
+
6066
6072
  if ( orQuery.length ) {
6067
6073
  query.push( {
6068
6074
  $match: {
@@ -8023,6 +8029,7 @@ export async function searchProduct( req, res ) {
8023
8029
  export async function updateProductMapping( req, res ) {
8024
8030
  try {
8025
8031
  let storeDetails = await storeService.find( { clientId: req.body.clientId, ...( req.body.stores && { storeName: { $in: req.body.stores } } ), status: 'active' }, { storeId: 1, storeName: 1 } );
8032
+ console.log( storeDetails, 'storeDetails' );
8026
8033
  if ( !storeDetails.length ) {
8027
8034
  return res.sendError( 'No data found', 204 );
8028
8035
  }
@@ -8053,9 +8060,6 @@ export async function updateProductMapping( req, res ) {
8053
8060
  } else {
8054
8061
  fixtureShelfDetails = fixtureDetails.find( ( fixt ) => fixt._id.toString() == getShelfDetails.fixtureId.toString() );
8055
8062
  }
8056
- if ( macDetails?.MAC == 'A4-E8-A3-91-7F-05' ) {
8057
- console.log( ele?.data?.antenna, fixtureShelfDetails?._id );
8058
- }
8059
8063
  logger.error( { data: fixtureShelfDetails, antennaNo: ele.data.antenna, macId: ele?.data?.MAC } );
8060
8064
  if ( getShelfDetails && fixtureShelfDetails ) {
8061
8065
  let productDetails = await planoProductService.findOne( { productId: ele.data.idText } );
@@ -8066,7 +8070,8 @@ export async function updateProductMapping( req, res ) {
8066
8070
  storeId: fixtureShelfDetails.storeId,
8067
8071
  type: getShelfDetails?.shelfType != 'storage' ? 'product' : 'storageBox',
8068
8072
  productId: productDetails._id,
8069
- pid: productDetails.productId,
8073
+ rfId: productDetails.productId,
8074
+ pid: productDetails.pid,
8070
8075
  planoId: fixtureShelfDetails.planoId,
8071
8076
  floorId: fixtureShelfDetails.floorId,
8072
8077
  fixtureId: fixtureShelfDetails._id,
@@ -8075,12 +8080,11 @@ export async function updateProductMapping( req, res ) {
8075
8080
  mappingData.push( data );
8076
8081
 
8077
8082
  // let mappingDetails = await planoMappingService.create( data );
8078
-
8079
8083
  let productData = {
8080
8084
  'planoMappingId': '',
8081
8085
  'date': dayjs().format( 'YYYY-MM-DD' ),
8082
8086
  'clientId': req.body.clientId,
8083
- 'compliance': getShelfDetails?.shelfType != 'storage' ? getShelfDetails.productBrandName.includes( productDetails.brandName ) ? 'proper' : 'misplaced' : '',
8087
+ 'compliance': getShelfDetails?.shelfType != 'storage' ? ( getShelfDetails.productBrandName.includes( productDetails.brandName ) || fixtureShelfDetails.templateGroupName == productDetails.brandGroup )? 'proper' : 'misplaced' : '',
8084
8088
  'fixtureId': fixtureShelfDetails._id,
8085
8089
  'floorId': fixtureShelfDetails.floorId,
8086
8090
  'planoId': fixtureShelfDetails.planoId,
@@ -8090,6 +8094,7 @@ export async function updateProductMapping( req, res ) {
8090
8094
  'storeId': fixtureShelfDetails.storeId,
8091
8095
  'storeName': fixtureShelfDetails.storeName,
8092
8096
  'type': getShelfDetails?.shelfType != 'storage' ? 'product' : 'storageBox',
8097
+ 'createdAt': dayjs( response?.mac_details?.[0]?.last_modified ).format(),
8093
8098
  };
8094
8099
  complianceData.push( productData );
8095
8100
 
@@ -8113,6 +8118,114 @@ export async function updateProductMapping( req, res ) {
8113
8118
  }
8114
8119
  }
8115
8120
 
8121
+ // await Promise.all( response?.mac_details?.map( async ( macDetails ) => {
8122
+ // } ) );
8123
+ await planoMappingService.deleteMany( { storeId: store.storeId } );
8124
+ let mappingInsertData = await planoMappingService.insertMany( mappingData );
8125
+ mappingInsertData = new Map( mappingInsertData.map( ( ele, index ) => [ index, ele ] ) );
8126
+ // let date = dayjs().format();
8127
+ complianceData.forEach( ( compliance, index ) => {
8128
+ compliance.planoMappingId = mappingInsertData.get( index );
8129
+ // compliance.createdAt = date;
8130
+ } );
8131
+ await planoComplianceService.insertMany( complianceData );
8132
+ // const ws = xlsx.utils.json_to_sheet( excelData );
8133
+ // const wb = xlsx.utils.book_new();
8134
+ // xlsx.utils.book_append_sheet( wb, ws, 'data' );
8135
+ // const buffer = xlsx.write( wb, { type: 'buffer', bookType: 'xlsx' } );
8136
+ // fs.writeFileSync( './items.xlsx', buffer );
8137
+ }
8138
+ } ) );
8139
+ return res.sendSuccess( 'Updated successfully' );
8140
+ } catch ( e ) {
8141
+ console.log( e );
8142
+ logger.error( { functionName: 'updateMapping', error: e } );
8143
+ return res.sendError( e, 500 );
8144
+ }
8145
+ }
8146
+
8147
+ export async function updateProductMappingNew( req, res ) {
8148
+ try {
8149
+ let storeDetails = await storeService.find( { clientId: req.body.clientId, ...( req.body.stores && { storeName: { $in: req.body.stores } } ), status: 'active' }, { storeId: 1, storeName: 1 } );
8150
+ console.log( storeDetails, 'storeDetails' );
8151
+ if ( !storeDetails.length ) {
8152
+ return res.sendError( 'No data found', 204 );
8153
+ }
8154
+ await Promise.all( storeDetails.map( async ( store ) => {
8155
+ // let number = Number( store.storeName.replace( /\D/g, '' ) );
8156
+ const getLatestData = await fetch(
8157
+ JSON.parse( process.env.LAMBDAURL ).getRFIDDetails,
8158
+ {
8159
+ method: 'POST',
8160
+ headers: { 'Content-Type': 'application/json' },
8161
+ body: JSON.stringify( { store_name: store.storeName, date: dayjs().format( 'YYYY-MM-DD' ) } ),
8162
+ },
8163
+ );
8164
+ // let getLatestData = await fetch( `${JSON.parse( process.env.LAMBDAURL )?.getRFIDDetails}`, { method: 'POST' },{} );
8165
+ if ( getLatestData.status == 200 ) {
8166
+ let response = await getLatestData.json();
8167
+ logger.error( { data: response } );
8168
+ // let data = response.mac_details.flatMap( ( ele ) => ele.body );
8169
+ let mappingData = [];
8170
+ let complianceData = [];
8171
+ let excelData = [];
8172
+ await Promise.all( response.map( async ( ele ) => {
8173
+ let fixtureTemplate = await storeFixtureService.findOne( { _id: ele?.fixtureId }, { templateGroupName: 1 } );
8174
+ let productDetails = await planoProductService.find( { productId: { $in: ele.final_idText } } );
8175
+ if ( productDetails.length ) {
8176
+ for ( let product of productDetails ) {
8177
+ let data = {
8178
+ clientId: req.body.clientId,
8179
+ storeName: store.storeName,
8180
+ storeId: store.storeId,
8181
+ type: ele?.shelfType != 'storage' ? 'product' : 'storageBox',
8182
+ productId: product._id,
8183
+ pid: productDetails.pid,
8184
+ rfId: product.productId,
8185
+ planoId: new mongoose.Types.ObjectId( ele?.planoId ),
8186
+ floorId: new mongoose.Types.ObjectId( ele?.floorId ),
8187
+ fixtureId: new mongoose.Types.ObjectId( ele?.fixtureId ),
8188
+ ...( ele?.shelfType && { shelfId: new mongoose.Types.ObjectId( ele?._id ) } ),
8189
+ };
8190
+ mappingData.push( data );
8191
+
8192
+ // let mappingDetails = await planoMappingService.create( data );
8193
+ let productData = {
8194
+ 'planoMappingId': '',
8195
+ 'date': dayjs().format( 'YYYY-MM-DD' ),
8196
+ 'clientId': req.body.clientId,
8197
+ 'compliance': ele?.shelfType != 'storage' ? ( ele.productBrandName.split( ',' ).includes( product.brandName ) || fixtureTemplate.templateGroupName == product.brandGroup )? 'proper' : 'misplaced' : '',
8198
+ 'fixtureId': ele.fixtureId,
8199
+ 'floorId': ele.floorId,
8200
+ 'planoId': ele.planoId,
8201
+ 'productId': product._id,
8202
+ 'rfId': ele.idHex,
8203
+ 'shelfId': ele._id,
8204
+ 'storeId': store.storeId,
8205
+ 'storeName': store.storeName,
8206
+ 'type': ele?.shelfType != 'storage' ? 'product' : 'storageBox',
8207
+ };
8208
+ complianceData.push( productData );
8209
+
8210
+
8211
+ excelData.push( {
8212
+ wallNumber: ele.wallNo ?? '',
8213
+ fixtureNumber: ele.fixtureNo,
8214
+ fixtureId: ele.fixtureId.toString(),
8215
+ readerId: ele?.mac,
8216
+ antennaNo: ele.antennaNo.toString(),
8217
+ pid: ele.final_idText,
8218
+ productName: product?.brandName,
8219
+ shelfId: ele?.shelfNumber ?? 'storage',
8220
+ } );
8221
+ }
8222
+
8223
+ // await planoComplianceService.create( productData );
8224
+ } else {
8225
+ logger.error( { data: 'pid mapping is missing', pid: ele?.final_idText } );
8226
+ }
8227
+ } ) );
8228
+
8116
8229
  // await Promise.all( response?.mac_details?.map( async ( macDetails ) => {
8117
8230
  // } ) );
8118
8231
  await planoMappingService.deleteMany( { storeId: store.storeId } );
@@ -8568,6 +8681,7 @@ export async function getPlanogramList( req, res ) {
8568
8681
  $match: {
8569
8682
  clientId,
8570
8683
  storeId: { $in: allowedStoreIds },
8684
+ ...(filter?.planoStrategy ? { planoStrategy: filter?.planoStrategy } : {}),
8571
8685
  },
8572
8686
  },
8573
8687
  { $sort: { _id: -1 } },
@@ -8667,6 +8781,7 @@ export async function getPlanogramList( req, res ) {
8667
8781
  },
8668
8782
  ];
8669
8783
 
8784
+
8670
8785
  if ( filter?.compliance?.length === 2 ) {
8671
8786
  const [ minC, maxC ] = filter.compliance.map( Number );
8672
8787
  pipeline.push( {
@@ -9247,6 +9362,7 @@ export async function getShelfDetails( req, res ) {
9247
9362
  associatedElementNumber: 1,
9248
9363
  associatedElementFixtureNumber: 1,
9249
9364
  label: '$header.label',
9365
+ storage: '$footer.antennaNo',
9250
9366
  },
9251
9367
  },
9252
9368
  ];
@@ -9257,10 +9373,15 @@ export async function getShelfDetails( req, res ) {
9257
9373
  let shelfDetails = await fixtureShelfService.findOne( { fixtureId: { $in: fixtureDetails.map( ( ele ) => ele._id ) }, antennaNo: { $in: [ req.body?.antenna ] } } );
9258
9374
 
9259
9375
  if ( !shelfDetails ) {
9260
- return res.sendError( 'No antenna found', 204 );
9376
+ fixtureDetails = fixtureDetails.find( ( ele ) => ele.storage.includes( req.body?.antenna ) );
9377
+ if ( !fixtureDetails ) {
9378
+ return res.sendError( 'No antenna found', 204 );
9379
+ }
9380
+ }
9381
+ if ( shelfDetails ) {
9382
+ fixtureDetails = fixtureDetails.find( ( ele ) => ele._id.toString() == shelfDetails.fixtureId.toString() );
9261
9383
  }
9262
- fixtureDetails = fixtureDetails.find( ( ele ) => ele._id.toString() == shelfDetails.fixtureId.toString() );
9263
- return res.sendSuccess( { ...shelfDetails.toObject(), associatedElementNumber: fixtureDetails?.associatedElementNumber, associatedElementFixtureNumber: fixtureDetails?.associatedElementFixtureNumber, isCl: fixtureDetails.label == 'CL' } );
9384
+ return res.sendSuccess( { ...shelfDetails?.toObject(), associatedElementNumber: fixtureDetails?.associatedElementNumber, associatedElementFixtureNumber: fixtureDetails?.associatedElementFixtureNumber, isCl: fixtureDetails.label == 'CL', ...( !shelfDetails && { antennaNo: fixtureDetails?.storage } ) } );
9264
9385
  } catch ( e ) {
9265
9386
  logger.error( { functionName: 'getShelfDetails', error: e } );
9266
9387
  return res.sendError( e, 500 );
@@ -52,4 +52,5 @@ scriptRouter
52
52
  .post( '/update4487Inventory', scriptController.update4487Inventory )
53
53
  .get( '/4487FixtureDetails', scriptController.get4487FixtureDetails )
54
54
  .post( '/getstoreMBQFixtureExcel', scriptController.getstoreMBQFixtureExcel )
55
+ .get( '/get4487FixtureData', scriptController.get4487FixtureData )
55
56
  ;