tango-app-api-store-builder 1.0.0-beta-69 → 1.0.0-beta-71

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-69",
3
+ "version": "1.0.0-beta-71",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -21,6 +21,7 @@
21
21
  "express-fileupload": "^1.5.1",
22
22
  "handlebars": "^4.7.8",
23
23
  "joi": "^17.13.3",
24
+ "jszip": "^3.10.1",
24
25
  "mongodb": "^6.12.0",
25
26
  "nodemon": "^3.1.9",
26
27
  "tango-api-schema": "^2.2.77",
@@ -14,6 +14,8 @@ import * as planoTaskService from '../service/planoTask.service.js';
14
14
  // import * as planoQrConversionRequestService from '../service/planoQrConversionRequest.service.js';
15
15
  import * as fixtureConfigService from '../service/fixtureConfig.service.js';
16
16
  import mongoose from 'mongoose';
17
+ import JSZip from 'jszip';
18
+
17
19
 
18
20
  export async function getStoreNames( req, res ) {
19
21
  try {
@@ -1774,3 +1776,185 @@ export async function getProdTaskData( req, res ) {
1774
1776
  return res.sendError( e.message || 'Internal Server Error', 500 );
1775
1777
  }
1776
1778
  }
1779
+
1780
+ export async function updatelayoutFeedback( req, res ) {
1781
+ try {
1782
+ if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
1783
+ return res.sendError( 'Unauthorized', 401 );
1784
+ }
1785
+ const layoutFeedbacks = await planoTaskService.find( { type: 'layout' } );
1786
+
1787
+ for ( let i = 0; i < layoutFeedbacks.length; i++ ) {
1788
+ const layoutDoc = layoutFeedbacks[i].toObject();
1789
+
1790
+ const [ q1, q2, q3 ] = layoutDoc.answers;
1791
+
1792
+ if ( q1.value === false ) {
1793
+ const floor = await storeBuilderService.findOne( { _id: layoutDoc.floorId } );
1794
+
1795
+ const floorDoc = floor.toObject();
1796
+
1797
+ const fixtures = await storeFixtureService.find( { floorId: floorDoc._id } );
1798
+
1799
+ const constantFixtureLength = 1220;
1800
+ const constantDetailedFixtureLength = 1220;
1801
+
1802
+ const constantFixtureWidth = 610;
1803
+ const constantDetailedFixtureWidth = 1524;
1804
+
1805
+ const mmToFeet = 305;
1806
+
1807
+
1808
+ function roundToTwo( num ) {
1809
+ return Math.round( num * 100 ) / 100;
1810
+ }
1811
+
1812
+ const leftFixtures = fixtures.filter( ( fixture ) => fixture.toObject().associatedElementType === 'wall' && fixture.toObject().associatedElementNumber === 1 && fixture.toObject().fixtureType === 'wall' );
1813
+ const rightFixtures = fixtures.filter( ( fixture ) => fixture.toObject().associatedElementType === 'wall' && fixture.toObject().associatedElementNumber === 3 && fixture.toObject().fixtureType === 'wall' );
1814
+ const floorFixtures = fixtures.filter( ( fixture ) => fixture.toObject().fixtureType === 'floor' );
1815
+ const backFixtures = fixtures.filter( ( fixture ) => fixture.toObject().associatedElementType === 'wall' && fixture.toObject().associatedElementNumber === 2 && fixture.toObject().fixtureType === 'wall' );
1816
+
1817
+ q2.correctedFixture.forEach( ( cf ) => {
1818
+ switch ( cf.alignment ) {
1819
+ case 'Wall 1':
1820
+ leftFixtures.push( {} );
1821
+ break;
1822
+ case 'Wall 2':
1823
+ backFixtures.push( {} );
1824
+ break;
1825
+ case 'Wall 3':
1826
+ rightFixtures.push( {} );
1827
+ break;
1828
+
1829
+ default:
1830
+ break;
1831
+ }
1832
+ } );
1833
+
1834
+
1835
+ const leftXDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1836
+ const leftXDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
1837
+
1838
+ const leftYDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantFixtureWidth / mmToFeet ) ) ) : 0;
1839
+ const leftYDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantDetailedFixtureWidth / mmToFeet ) ) ) : 0;
1840
+
1841
+ const rightXDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1842
+ const rightXDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
1843
+
1844
+ const rightYDistanceFeet = rightFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
1845
+ const rightYDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( constantDetailedFixtureWidth / mmToFeet ) ): 0;
1846
+
1847
+ const maxFixturesPerRow = floorFixtures.length > 4 ? 3 : 2;
1848
+ const totalRows = Math.ceil( floorFixtures.length / maxFixturesPerRow );
1849
+ const floorXDistanceFeet = floorFixtures.length ? roundToTwo( ( maxFixturesPerRow * ( constantFixtureLength / mmToFeet ) ) ) : 0;
1850
+ const floorXDetailedDistanceFeet = floorFixtures.length ? roundToTwo( ( maxFixturesPerRow * ( constantDetailedFixtureLength / mmToFeet ) ) ): 0;
1851
+
1852
+ const floorYDistanceFeet = floorFixtures.length ? roundToTwo( ( totalRows * ( constantFixtureWidth/ mmToFeet ) ) ): 0;
1853
+ const floorYDetailedDistanceFeet = floorFixtures.length ? roundToTwo( totalRows * ( constantDetailedFixtureWidth/mmToFeet ) ): 0;
1854
+
1855
+ const backXDistanceFeet = backFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
1856
+ const backXDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( constantDetailedFixtureLength / mmToFeet ) ) : 0;
1857
+
1858
+ const backYDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantFixtureLength / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantFixtureWidth )/mmToFeet ) ) ) : 0;
1859
+ const backYDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantDetailedFixtureWidth / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth )/mmToFeet ) ) ): 0;
1860
+
1861
+ const maxXDistance = Math.max( leftXDistanceFeet, rightXDistanceFeet, floorXDistanceFeet );
1862
+ const maxXDetailedDistance = Math.max( leftXDetailedDistanceFeet, rightXDetailedDistanceFeet, floorXDetailedDistanceFeet );
1863
+
1864
+ const maxYDistance = Math.max( floorYDistanceFeet, backYDistanceFeet );
1865
+ const maxYDetailedDistance = Math.max( floorYDetailedDistanceFeet, backYDetailedDistanceFeet );
1866
+
1867
+
1868
+ const finalXDistance = maxXDistance < ( backXDistanceFeet + floorXDistanceFeet )? ( ( backXDistanceFeet + floorXDistanceFeet ) + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : ( floorFixtures.length && backFixtures.length ) ? ( maxXDistance + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : maxXDistance;
1869
+ const finalXDetailedDistance = maxXDetailedDistance < ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet )? ( ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : ( floorFixtures.length && backFixtures.length ) ? ( maxXDetailedDistance + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : maxXDetailedDistance;
1870
+
1871
+ const finalYDistance = maxYDistance < ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) ? ( ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) + ( ( 2 * constantFixtureWidth )/mmToFeet ) ) : ( maxYDistance + ( ( constantFixtureWidth )/mmToFeet ) );
1872
+ const finalYDetailedDistance = maxYDetailedDistance < ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) ? ( ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureWidth )/mmToFeet ) ) : ( maxYDetailedDistance + ( ( constantDetailedFixtureWidth )/mmToFeet ) );
1873
+
1874
+ const layoutPolygon = [
1875
+ {
1876
+ elementType: 'wall',
1877
+ distance: roundToTwo( finalXDistance ),
1878
+ unit: 'ft',
1879
+ direction: 'right',
1880
+ angle: 90,
1881
+ elementNumber: 1,
1882
+ detailedDistance: roundToTwo( finalXDetailedDistance ),
1883
+ },
1884
+ {
1885
+ elementType: 'wall',
1886
+ distance: roundToTwo( finalYDistance ),
1887
+ unit: 'ft',
1888
+ direction: 'down',
1889
+ angle: 90,
1890
+ elementNumber: 2,
1891
+ detailedDistance: roundToTwo( finalYDetailedDistance ),
1892
+ },
1893
+ {
1894
+ elementType: 'wall',
1895
+ distance: roundToTwo( finalXDistance ),
1896
+ unit: 'ft',
1897
+ direction: 'left',
1898
+ angle: 90,
1899
+ elementNumber: 3,
1900
+ detailedDistance: roundToTwo( finalXDetailedDistance ),
1901
+ },
1902
+ {
1903
+ elementType: 'wall',
1904
+ distance: roundToTwo( ( ( finalYDistance * 40 ) / 100 ) ),
1905
+ unit: 'ft',
1906
+ direction: 'up',
1907
+ angle: 90,
1908
+ elementNumber: 4,
1909
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
1910
+ },
1911
+ {
1912
+ elementType: 'entrance',
1913
+ distance: roundToTwo( ( ( finalYDistance * 20 ) / 100 ) ),
1914
+ unit: 'ft',
1915
+ direction: 'up',
1916
+ angle: 90,
1917
+ elementNumber: 1,
1918
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 30 ) / 100 ) ),
1919
+ },
1920
+ {
1921
+ elementType: 'wall',
1922
+ distance: roundToTwo( ( ( finalYDistance * 40 ) / 100 ) ),
1923
+ unit: 'ft',
1924
+ direction: 'up',
1925
+ angle: 90,
1926
+ elementNumber: 5,
1927
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
1928
+ },
1929
+ ];
1930
+
1931
+ console.log( layoutPolygon, floorDoc._id );
1932
+ }
1933
+ }
1934
+ } catch ( e ) {
1935
+ logger.error( { functionName: 'updatelayoutFeedback', error: e } );
1936
+ return res.sendError( e.message || 'Internal Server Error', 500 );
1937
+ }
1938
+ }
1939
+
1940
+ export async function extractZipFileNames( req, res ) {
1941
+ try {
1942
+ if ( req?.headers?.authorization?.split( ' ' )[1] !== 'hwjXfCD6TgMvc82cuSGZ9bNv9MuXsaiQ6uvx' ) {
1943
+ return res.sendError( 'Unauthorized', 401 );
1944
+ }
1945
+
1946
+ if ( !req.files.file ) {
1947
+ return res.sendError( 'No file uploaded', 400 );
1948
+ }
1949
+
1950
+ const zip = new JSZip();
1951
+ const zipContents = await zip.loadAsync( req.files.file.data );
1952
+
1953
+ const fileNames = Object.keys( zipContents.files );
1954
+
1955
+ return res.sendSuccess( { fileNames } );
1956
+ } catch ( e ) {
1957
+ logger.error( { functionName: 'extractZipFileNames', error: e } );
1958
+ return res.sendError( e.message || 'Internal Server Error', 500 );
1959
+ }
1960
+ }
@@ -395,7 +395,11 @@ export async function storeLayout( req, res ) {
395
395
 
396
396
  const storeLayout = await Promise.all(
397
397
  planograms.map( async ( planogram ) => {
398
- const floors = await storeBuilderService.find( { planoId: planogram._id }, { floorName: 1, layoutPolygon: 1 } );
398
+ const floorList = await storeBuilderService.find( { planoId: planogram._id }, { floorName: 1, layoutPolygon: 1, crestLayout: true } );
399
+
400
+ const floors = floorList.map( ( floor ) => {
401
+ return floor.toObject();
402
+ } );
399
403
  return {
400
404
  ...planogram.toObject(),
401
405
  floors,
@@ -2041,6 +2045,7 @@ export async function storeFixturesTask( req, res ) {
2041
2045
  const compliance = await planoTaskComplianceService.findOne( {
2042
2046
  fixtureId: fixture._id,
2043
2047
  type: req.body?.type ? req.body.type : 'fixture',
2048
+ date_string: req.body?.date,
2044
2049
  }, { status: 1 } );
2045
2050
 
2046
2051
  const shelves = await fixtureShelfService.find( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 } );
@@ -2743,3 +2748,58 @@ export const checkPlanoExist = async ( req, res ) => {
2743
2748
  return res.sendError( 'Internal Server Error', 500 );
2744
2749
  }
2745
2750
  };
2751
+
2752
+ export async function storeLayoutElements( req, res ) {
2753
+ try {
2754
+ // const planoIds = req.body.id.map( ( id ) => new mongoose.Types.ObjectId( id ) );
2755
+
2756
+ const planograms = await planoService.find(
2757
+ { _id: new mongoose.Types.ObjectId( req.body.id ) },
2758
+ { storeId: 1, storeName: 1, planoId: '$_id' },
2759
+ );
2760
+
2761
+ if ( !planograms?.length ) {
2762
+ return res.sendError( 'No data found', 204 );
2763
+ }
2764
+
2765
+ const storeLayout = await Promise.all(
2766
+ planograms.map( async ( planogram ) => {
2767
+ const floorList = await storeBuilderService.find(
2768
+ { planoId: planogram._id },
2769
+ { floorName: 1, layoutPolygon: 1, crestLayout: 1 },
2770
+ );
2771
+
2772
+ const floors = floorList.map( ( floor ) => {
2773
+ if ( floor.toObject()?.crestLayout ) {
2774
+ return {
2775
+ floorName: 'floor 1',
2776
+ layoutPolygon: [ 'wall 1', 'wall 2', 'wall 3', 'centre' ],
2777
+ };
2778
+ } else {
2779
+ const layoutPolygon = floor
2780
+ .toObject()
2781
+ ?.layoutPolygon.map( ( element ) => {
2782
+ return `${element?.elementType} ${element?.elementNumber}`;
2783
+ } );
2784
+ layoutPolygon.push( 'centre' );
2785
+ return {
2786
+ ...floor.toObject(),
2787
+ layoutPolygon,
2788
+ };
2789
+ }
2790
+ } );
2791
+
2792
+ return {
2793
+ ...planogram.toObject(),
2794
+ floors,
2795
+ };
2796
+ } ),
2797
+ );
2798
+
2799
+ return res.sendSuccess( storeLayout );
2800
+ } catch ( e ) {
2801
+ logger.error( { functionName: 'storeLayoutv1', error: e, message: req.body } );
2802
+ return res.sendError( e, 500 );
2803
+ }
2804
+ }
2805
+
@@ -16,4 +16,6 @@ scriptRouter
16
16
  .post( '/updateinventory', scriptController.updateInventory )
17
17
  .post( '/updateRfidProduct', scriptController.updateRfidProduct )
18
18
  .post( '/updateRfidProduct2', scriptController.updateRfidProduct2 )
19
- .post( '/getProdTaskData', scriptController.getProdTaskData );
19
+ .post( '/getProdTaskData', scriptController.getProdTaskData )
20
+ .post( '/updateLayoutFeedback', scriptController.updatelayoutFeedback )
21
+ .post( '/getFileNames', scriptController.extractZipFileNames );
@@ -40,4 +40,5 @@ storeBuilderRouter
40
40
  .post( '/getFixtureTypes', isAllowedSessionHandler, storeBuilderController.getFixtureTypes )
41
41
  .post( '/getFixtureLengths', isAllowedSessionHandler, storeBuilderController.getFixtureLengths )
42
42
  .post( '/getFixtureBrands', isAllowedSessionHandler, storeBuilderController.getFixtureBrands )
43
- .post( '/checkPlanoExist', isAllowedSessionHandler, storeBuilderController.checkPlanoExist );
43
+ .post( '/checkPlanoExist', isAllowedSessionHandler, storeBuilderController.checkPlanoExist )
44
+ .post( '/storeLayoutElements', isAllowedSessionHandler, storeBuilderController.storeLayoutElements );