tango-app-api-store-builder 1.0.0-beta-88 → 1.0.0-beta-90
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
|
@@ -1081,7 +1081,7 @@ export async function fixtureShelfProductv1( req, res ) {
|
|
|
1081
1081
|
return res.sendSuccess( { ...fixture.toObject(), fixtureConfigLength: fixtureConfigDetails?.fixtureLength, products: productDetails, vms: vmDetails, productCount: productMappings.length } );
|
|
1082
1082
|
}
|
|
1083
1083
|
|
|
1084
|
-
if ( [ 'L2', 'L4' ].includes( fixture.toObject().productResolutionLevel ) ) {
|
|
1084
|
+
if ( [ 'L2', 'L3', 'L4' ].includes( fixture.toObject().productResolutionLevel ) ) {
|
|
1085
1085
|
const fixtureShelves = await fixtureShelfService.findAndSort( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) }, {}, { shelfNumber: 1 } );
|
|
1086
1086
|
// if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
|
|
1087
1087
|
const productCount = await planoMappingService.count( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
|
|
@@ -1095,21 +1095,21 @@ export async function fixtureShelfProductv1( req, res ) {
|
|
|
1095
1095
|
return res.sendSuccess( { ...fixture.toObject(), fixtureConfigLength: fixtureConfigDetails?.fixtureLength, shelves: shelfProducts, vms: vmDetails, productCount: productCount } );
|
|
1096
1096
|
}
|
|
1097
1097
|
|
|
1098
|
-
if ( fixture.toObject().productResolutionLevel === 'L3' ) {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1098
|
+
// if ( fixture.toObject().productResolutionLevel === 'L3' ) {
|
|
1099
|
+
// const fixtureShelves = await fixtureShelfService.findAndSort( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) }, {}, { shelfNumber: 1 } );
|
|
1100
|
+
// // if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
|
|
1101
|
+
// const productCount = await planoMappingService.count( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
|
|
1102
|
+
// const groupedShelves = fixtureShelves.reduce( async ( accPromise, shelf ) => {
|
|
1103
|
+
// const acc = await accPromise;
|
|
1104
|
+
// const productMappings = await planoMappingService.find( { shelfId: shelf._id, type: 'product' } );
|
|
1105
|
+
// const productDetails = await getProducts( productMappings );
|
|
1106
|
+
// const sectionName = shelf.sectionName || 'Unknown';
|
|
1107
|
+
// if ( !acc[sectionName] ) acc[sectionName] = [];
|
|
1108
|
+
// acc[sectionName].push( { ...shelf.toObject(), products: productDetails } );
|
|
1109
|
+
// return acc;
|
|
1110
|
+
// }, Promise.resolve( {} ) );
|
|
1111
|
+
// return res.sendSuccess( { ...fixture.toObject(), fixtureConfigLength: fixtureConfigDetails?.fixtureLength, categories: await groupedShelves, vms: vmDetails, productCount: productCount } );
|
|
1112
|
+
// }
|
|
1113
1113
|
|
|
1114
1114
|
return res.sendError( 'Incorrect resolution level', 400 );
|
|
1115
1115
|
} catch ( e ) {
|
|
@@ -1840,119 +1840,6 @@ export async function bulkFixtureUpload( req, res ) {
|
|
|
1840
1840
|
}
|
|
1841
1841
|
}
|
|
1842
1842
|
|
|
1843
|
-
// const data = {
|
|
1844
|
-
// floors: [
|
|
1845
|
-
// { id: '9687687',
|
|
1846
|
-
// fixtures: [
|
|
1847
|
-
// {
|
|
1848
|
-
// id: '123456',
|
|
1849
|
-
// shelves: [
|
|
1850
|
-
// {
|
|
1851
|
-
// id: '789012',
|
|
1852
|
-
// sectionName: 'top',
|
|
1853
|
-
// products: [ 'p1', 'p2' ],
|
|
1854
|
-
// },
|
|
1855
|
-
// ],
|
|
1856
|
-
// },
|
|
1857
|
-
// ],
|
|
1858
|
-
// },
|
|
1859
|
-
// ],
|
|
1860
|
-
// };
|
|
1861
|
-
|
|
1862
|
-
// import * as fs from 'fs';
|
|
1863
|
-
|
|
1864
|
-
// const data = [
|
|
1865
|
-
// {
|
|
1866
|
-
// "facility_code": "LKST98",
|
|
1867
|
-
// "product_id": 217622,
|
|
1868
|
-
// "brand": "Lenskart READERS",
|
|
1869
|
-
// "category": "Non-Power Reading",
|
|
1870
|
-
// "zone": "South",
|
|
1871
|
-
// "tlp_status": "N",
|
|
1872
|
-
// "lf_nonlf": "LF",
|
|
1873
|
-
// "kpi": "SOH",
|
|
1874
|
-
// "qty": 1,
|
|
1875
|
-
// "created_at": "01\/31\/2025",
|
|
1876
|
-
// "store_type": "COCO",
|
|
1877
|
-
// "status": "Active",
|
|
1878
|
-
// "PLC": "New Launches",
|
|
1879
|
-
// "itemcode": "CCC086062840"
|
|
1880
|
-
// }
|
|
1881
|
-
// ]
|
|
1882
|
-
|
|
1883
|
-
// const cleanData = ( data ) => {
|
|
1884
|
-
// return data.map( ( { product_id, brand, category, itemcode, facility_code } ) => ( {
|
|
1885
|
-
// productId: String( product_id ),
|
|
1886
|
-
// productBrand: brand,
|
|
1887
|
-
// productType: category,
|
|
1888
|
-
// clientId: '11',
|
|
1889
|
-
// storeName: facility_code,
|
|
1890
|
-
// itemcode,
|
|
1891
|
-
// type:'product'
|
|
1892
|
-
// } ) );
|
|
1893
|
-
// };
|
|
1894
|
-
|
|
1895
|
-
// const saveToFile = ( filename, content ) => {
|
|
1896
|
-
// const textContent = JSON.stringify( content, null, 2 );
|
|
1897
|
-
// fs.writeFileSync( filename, textContent, 'utf-8' );
|
|
1898
|
-
// console.log( `File saved as ${filename}` );
|
|
1899
|
-
// };
|
|
1900
|
-
|
|
1901
|
-
// const cleanedData = cleanData( data );
|
|
1902
|
-
// saveToFile( 'output.txt', cleanedData );
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
// Find Duplicate Ids
|
|
1906
|
-
|
|
1907
|
-
// import fs from 'fs';
|
|
1908
|
-
|
|
1909
|
-
// async function findDuplicates() {
|
|
1910
|
-
// try {
|
|
1911
|
-
// const keys1 = await planoMappingService.find( { clientId: '11' }, { rfId: 1, _id: 0 } );
|
|
1912
|
-
// const keys2 = await fixtureShelfService.find( { clientId: '11' }, { rfId: 1, _id: 0 } );
|
|
1913
|
-
|
|
1914
|
-
// const keyArray1 = keys1.map( ( doc ) => doc.toObject().rfId );
|
|
1915
|
-
// const keyArray2 = keys2.map( ( doc ) => doc.toObject().rfId );
|
|
1916
|
-
|
|
1917
|
-
// const findDuplicatesInArray = ( arr ) => {
|
|
1918
|
-
// const countMap = new Map();
|
|
1919
|
-
// arr.forEach( ( key ) => countMap.set( key, ( countMap.get( key ) || 0 ) + 1 ) );
|
|
1920
|
-
// return [ ...countMap.entries() ].filter( ( [ _, count ] ) => count > 1 ).map( ( [ key ] ) => key );
|
|
1921
|
-
// };
|
|
1922
|
-
|
|
1923
|
-
// const duplicatesInCollection1 = findDuplicatesInArray( keyArray1 );
|
|
1924
|
-
// const duplicatesInCollection2 = findDuplicatesInArray( keyArray2 );
|
|
1925
|
-
|
|
1926
|
-
// const set1 = new Set( keyArray1 );
|
|
1927
|
-
// const set2 = new Set( keyArray2 );
|
|
1928
|
-
// const duplicatesAcrossCollections = [ ...set1 ].filter( ( key ) => set2.has( key ) );
|
|
1929
|
-
|
|
1930
|
-
// let output = '';
|
|
1931
|
-
|
|
1932
|
-
// if ( duplicatesInCollection1.length > 0 ) {
|
|
1933
|
-
// output += `Duplicates within product:\n${duplicatesInCollection1.join( '\n' )}\n\n`;
|
|
1934
|
-
// }
|
|
1935
|
-
// if ( duplicatesInCollection2.length > 0 ) {
|
|
1936
|
-
// output += `Duplicates within shelf:\n${duplicatesInCollection2.join( '\n' )}\n\n`;
|
|
1937
|
-
// }
|
|
1938
|
-
// if ( duplicatesAcrossCollections.length > 0 ) {
|
|
1939
|
-
// output += `Duplicates across product & shelf:\n${duplicatesAcrossCollections.join( '\n' )}\n\n`;
|
|
1940
|
-
// }
|
|
1941
|
-
|
|
1942
|
-
// if ( output ) {
|
|
1943
|
-
// const filePath = 'duplicates.txt';
|
|
1944
|
-
// fs.writeFileSync( filePath, output, 'utf8' );
|
|
1945
|
-
// console.log( `Duplicates written to ${filePath}` );
|
|
1946
|
-
// } else {
|
|
1947
|
-
// console.log( 'No duplicates found.' );
|
|
1948
|
-
// }
|
|
1949
|
-
// } catch ( error ) {
|
|
1950
|
-
// console.error( 'Error:', error );
|
|
1951
|
-
// }
|
|
1952
|
-
// }
|
|
1953
|
-
|
|
1954
|
-
// findDuplicates();
|
|
1955
|
-
|
|
1956
1843
|
export const uploadImage = async ( req, res ) => {
|
|
1957
1844
|
try {
|
|
1958
1845
|
let imgUrl;
|
|
@@ -2861,3 +2748,133 @@ export async function storeLayoutElements( req, res ) {
|
|
|
2861
2748
|
return res.sendError( e, 500 );
|
|
2862
2749
|
}
|
|
2863
2750
|
}
|
|
2751
|
+
|
|
2752
|
+
export async function qrScan( req, res ) {
|
|
2753
|
+
try {
|
|
2754
|
+
if ( !req.body.floorId ) return res.sendError( 'Floor id is required', 400 );
|
|
2755
|
+
|
|
2756
|
+
if ( !req.body.fixtureId ) return res.sendError( 'Fixture id is required', 400 );
|
|
2757
|
+
|
|
2758
|
+
if ( !req.body.rfId ) return res.sendError( 'RFID is required', 400 );
|
|
2759
|
+
const fixture = await storeFixtureService.findOne(
|
|
2760
|
+
{ _id: new mongoose.Types.ObjectId( req.body.fixtureId ) },
|
|
2761
|
+
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1 },
|
|
2762
|
+
);
|
|
2763
|
+
|
|
2764
|
+
if ( !fixture ) return res.sendError( 'No data found', 204 );
|
|
2765
|
+
|
|
2766
|
+
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
2767
|
+
|
|
2768
|
+
async function getFixtureMetrics( fixture, currentDate ) {
|
|
2769
|
+
const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
|
|
2770
|
+
planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
|
|
2771
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
|
|
2772
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
|
|
2773
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
|
|
2774
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
|
|
2775
|
+
] );
|
|
2776
|
+
|
|
2777
|
+
const fixtureMetrics = {
|
|
2778
|
+
total: totalProducts,
|
|
2779
|
+
scanned: scannedProducts,
|
|
2780
|
+
misplaced: misplacedProducts,
|
|
2781
|
+
proper: properProducts,
|
|
2782
|
+
missing: missingProducts,
|
|
2783
|
+
};
|
|
2784
|
+
|
|
2785
|
+
return fixtureMetrics;
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
|
|
2789
|
+
if ( fixture.productResolutionLevel === 'L1' ) {
|
|
2790
|
+
const mappingQuery = {
|
|
2791
|
+
planoId: req.body.planoId,
|
|
2792
|
+
floorId: req.body.floorId,
|
|
2793
|
+
fixtureId: req.body.fixtureId,
|
|
2794
|
+
rfId: req.body.rfId,
|
|
2795
|
+
};
|
|
2796
|
+
|
|
2797
|
+
const productMapping = await planoMappingService.findOne( mappingQuery );
|
|
2798
|
+
|
|
2799
|
+
if ( !productMapping ) {
|
|
2800
|
+
const misplacedQuery = {
|
|
2801
|
+
planoId: req.body.planoId,
|
|
2802
|
+
floorId: req.body.floorId,
|
|
2803
|
+
rfId: req.body.rfId,
|
|
2804
|
+
};
|
|
2805
|
+
const misplacedProductMapping = await planoMappingService.findOne( misplacedQuery );
|
|
2806
|
+
|
|
2807
|
+
if ( !misplacedProductMapping ) {
|
|
2808
|
+
return res.sendSuccess( { data: null, status: 'missing' } );
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
|
|
2812
|
+
delete complianceData._id;
|
|
2813
|
+
|
|
2814
|
+
|
|
2815
|
+
await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
|
|
2816
|
+
|
|
2817
|
+
const fm = await getFixtureMetrics( fixture, currentDate );
|
|
2818
|
+
|
|
2819
|
+
return res.sendSuccess( { data: { ...misplacedProductMapping.toObject() }, fixtureMetrics: fm, status: 'misplaced' } );
|
|
2820
|
+
}
|
|
2821
|
+
|
|
2822
|
+
const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
|
|
2823
|
+
delete complianceData._id;
|
|
2824
|
+
|
|
2825
|
+
await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
|
|
2826
|
+
|
|
2827
|
+
const fm = await getFixtureMetrics( fixture, currentDate );
|
|
2828
|
+
|
|
2829
|
+
|
|
2830
|
+
return res.sendSuccess( { data: { ...productMapping.toObject() }, fixtureMetrics: fm, status: 'proper' } );
|
|
2831
|
+
} else if ( fixture.productResolutionLevel === 'L3' ) {
|
|
2832
|
+
const sectionShelves = await fixtureShelfService.find( { fixtureId: fixture._id, sectionName: req.body.sectionName } );
|
|
2833
|
+
|
|
2834
|
+
if ( !sectionShelves.length ) return res.sendError( 'No shelves found for the Section', 400 );
|
|
2835
|
+
|
|
2836
|
+
const shelfIds = sectionShelves.map( ( shelf ) => shelf.toObject()._id );
|
|
2837
|
+
|
|
2838
|
+
const planoMapping = await planoMappingService.findOne( { rfId: req.body.rfId, shelfId: { $in: shelfIds } } );
|
|
2839
|
+
|
|
2840
|
+
if ( !planoMapping ) {
|
|
2841
|
+
const locatePlano = await planoMappingService.findOne( { rfId: req.body.rfId, floorId: req.body.floorId } );
|
|
2842
|
+
|
|
2843
|
+
if ( !locatePlano ) {
|
|
2844
|
+
return res.sendSuccess( { data: null, fixtureMetrics: null, status: 'missing' } );
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
const locatePlanoData = locatePlano.toObject();
|
|
2848
|
+
|
|
2849
|
+
delete locatePlanoData._id;
|
|
2850
|
+
|
|
2851
|
+
const complianceData = { ...locatePlanoData, planoMappingId: locatePlano.toObject()._id, compliance: 'misplaced' };
|
|
2852
|
+
|
|
2853
|
+
await planoComplianceService.updateOne( { date: currentDate, planoMappingId: locatePlano.toObject()._id }, complianceData );
|
|
2854
|
+
|
|
2855
|
+
|
|
2856
|
+
const fm = await getFixtureMetrics( fixture, currentDate );
|
|
2857
|
+
|
|
2858
|
+
|
|
2859
|
+
return res.sendSuccess( { data: { ...locatePlano.toObject() }, fixtureMetrics: fm, status: 'misplaced' } );
|
|
2860
|
+
}
|
|
2861
|
+
|
|
2862
|
+
const mapingData = planoMapping.toObject();
|
|
2863
|
+
|
|
2864
|
+
delete mapingData._id;
|
|
2865
|
+
|
|
2866
|
+
const complianceData = { ...mapingData, planoMappingId: planoMapping.toObject()._id, compliance: 'proper' };
|
|
2867
|
+
|
|
2868
|
+
await planoComplianceService.updateOne( { date: currentDate, planoMappingId: planoMapping.toObject()._id }, complianceData );
|
|
2869
|
+
|
|
2870
|
+
const fm = await getFixtureMetrics( fixture, currentDate );
|
|
2871
|
+
|
|
2872
|
+
return res.sendSuccess( { data: { ...planoMapping.toObject() }, fixtureMetrics: fm, status: 'proper' } );
|
|
2873
|
+
} else {
|
|
2874
|
+
return res.sendError( 'Incorrect resolution level', 400 );
|
|
2875
|
+
}
|
|
2876
|
+
} catch ( e ) {
|
|
2877
|
+
logger.error( { functionName: 'scanv1', error: e, message: req.body } );
|
|
2878
|
+
return res.sendError( e, 500 );
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
@@ -24,9 +24,9 @@ storeBuilderRouter
|
|
|
24
24
|
// .post( '/scan', storeBuilderController.scan )
|
|
25
25
|
.post( '/storeLayout', isAllowedSessionHandler, validate( validateDtos.storeList ), storeBuilderController.storeLayout )
|
|
26
26
|
.post( '/storeFixtures', validate( validateDtos.storeList ), storeBuilderController.storeFixturesv1 )
|
|
27
|
-
.post( '/FixtureShelfDetails',
|
|
27
|
+
.post( '/FixtureShelfDetails', validate( validateDtos.fixtureShelfProduct ), storeBuilderController.fixtureShelfProductv1 )
|
|
28
28
|
.post( '/scan', isAllowedSessionHandler, storeBuilderController.scanv1 )
|
|
29
|
-
.post( '/updateMissing',
|
|
29
|
+
.post( '/updateMissing', storeBuilderController.updateMissing )
|
|
30
30
|
.post( '/bulkFixtureUpload', isAllowedSessionHandler, storeBuilderController.bulkFixtureUpload )
|
|
31
31
|
.post( '/uploadImage', isAllowedSessionHandler, storeBuilderController.uploadImage )
|
|
32
32
|
.post( '/storeFixturesTask', isAllowedSessionHandler, storeBuilderController.storeFixturesTask )
|
|
@@ -42,4 +42,5 @@ storeBuilderRouter
|
|
|
42
42
|
.post( '/getFixtureLengths', isAllowedSessionHandler, storeBuilderController.getFixtureLengths )
|
|
43
43
|
.post( '/getFixtureBrands', isAllowedSessionHandler, storeBuilderController.getFixtureBrands )
|
|
44
44
|
.post( '/checkPlanoExist', isAllowedSessionHandler, storeBuilderController.checkPlanoExist )
|
|
45
|
-
.post( '/storeLayoutElements', isAllowedSessionHandler, storeBuilderController.storeLayoutElements )
|
|
45
|
+
.post( '/storeLayoutElements', isAllowedSessionHandler, storeBuilderController.storeLayoutElements )
|
|
46
|
+
.post( '/qrScan', storeBuilderController.qrScan );
|