tango-app-api-store-builder 1.0.0-beta-89 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-store-builder",
3
- "version": "1.0.0-beta-89",
3
+ "version": "1.0.0-beta-90",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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;
@@ -2878,6 +2765,26 @@ export async function qrScan( req, res ) {
2878
2765
 
2879
2766
  const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
2880
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
+
2881
2788
 
2882
2789
  if ( fixture.productResolutionLevel === 'L1' ) {
2883
2790
  const mappingQuery = {
@@ -2904,436 +2811,65 @@ export async function qrScan( req, res ) {
2904
2811
  const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
2905
2812
  delete complianceData._id;
2906
2813
 
2907
- let misplacedProductDetails = await planoProductService.findOne( { _id: misplacedProductMapping.toObject().productId } );
2908
2814
 
2909
2815
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
2910
2816
 
2911
- const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
2912
- planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
2913
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
2914
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
2915
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
2916
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
2917
- ] );
2918
-
2919
- const fixtureMetrics = {
2920
- total: totalProducts,
2921
- scanned: scannedProducts,
2922
- misplaced: misplacedProducts,
2923
- proper: properProducts,
2924
- missing: missingProducts,
2925
- };
2817
+ const fm = await getFixtureMetrics( fixture, currentDate );
2926
2818
 
2927
- return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
2819
+ return res.sendSuccess( { data: { ...misplacedProductMapping.toObject() }, fixtureMetrics: fm, status: 'misplaced' } );
2928
2820
  }
2929
2821
 
2930
2822
  const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
2931
2823
  delete complianceData._id;
2932
2824
 
2933
- let productDetails = await planoProductService.findOne( { _id: productMapping.productId } );
2934
-
2935
2825
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
2936
2826
 
2937
- const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
2938
- planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
2939
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
2940
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
2941
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
2942
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
2827
+ const fm = await getFixtureMetrics( fixture, currentDate );
2943
2828
 
2944
- ] );
2945
2829
 
2946
- const fixtureMetrics = {
2947
- total: totalProducts,
2948
- scanned: scannedProducts,
2949
- misplaced: misplacedProducts,
2950
- proper: properProducts,
2951
- missing: missingProducts,
2952
- };
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 } );
2953
2833
 
2954
- return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'proper' } );
2955
- }
2956
- // else if ( fixture.productResolutionLevel === 'L2' ) {
2957
- // if ( !req.body.shelfId && req.body.rfId ) {
2958
- // const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
2959
- // if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
2960
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
2961
- // planoMappingService.count( { shelfId: shelf.toObject()._id } ),
2962
- // planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
2963
- // ] );
2964
- // return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
2965
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
2966
- // }
2967
-
2968
- // if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
2969
-
2970
- // const mappingQuery = {
2971
- // planoId: req.body.planoId,
2972
- // floorId: req.body.floorId,
2973
- // fixtureId: req.body.fixtureId,
2974
- // shelfId: req.body.shelfId,
2975
- // rfId: req.body.rfId,
2976
- // };
2834
+ if ( !sectionShelves.length ) return res.sendError( 'No shelves found for the Section', 400 );
2977
2835
 
2978
- // const productMapping = await planoMappingService.findOne( mappingQuery );
2979
-
2980
- // if ( !productMapping ) {
2981
- // const misplacedQuery = {
2982
- // planoId: req.body.planoId,
2983
- // floorId: req.body.floorId,
2984
- // rfId: req.body.rfId,
2985
- // };
2986
- // const misplacedProductMapping = await planoMappingService.findOne( misplacedQuery );
2987
-
2988
- // if ( !misplacedProductMapping ) {
2989
- // const shelf = await fixtureShelfService.findOne( misplacedQuery );
2990
- // if ( !shelf ) {
2991
- // return res.sendSuccess( { data: null, status: 'missing' } );
2992
- // }
2993
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
2994
- // planoMappingService.count( { shelfId: shelf.toObject()._id } ),
2995
- // planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
2996
- // ] );
2997
- // return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
2998
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
2999
- // }
3000
-
3001
- // const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
3002
- // delete complianceData._id;
3003
-
3004
- // let misplacedProductDetails = await planoProductService.findOne( { _id: misplacedProductMapping.toObject().productId } );
3005
-
3006
- // const isComplianceProper = await planoComplianceService.count( { ...misplacedQuery, date: currentDate, compliance: 'proper' } );
3007
- // if ( !isComplianceProper ) {
3008
- // await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate, compliance: { $ne: 'proper' } }, complianceData );
3009
- // }
3010
-
3011
- // const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
3012
- // planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
3013
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
3014
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
3015
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
3016
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
3017
- // ] );
3018
-
3019
- // const fixtureMetrics = {
3020
- // total: totalProducts,
3021
- // scanned: scannedProducts,
3022
- // misplaced: misplacedProducts,
3023
- // proper: properProducts,
3024
- // missing: missingProducts,
3025
- // };
3026
-
3027
- // return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
3028
- // }
3029
-
3030
- // const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
3031
- // delete complianceData._id;
3032
-
3033
- // let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
3034
-
3035
- // await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
3036
-
3037
- // const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
3038
- // planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
3039
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
3040
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
3041
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
3042
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
3043
- // ] );
3044
-
3045
- // const fixtureMetrics = {
3046
- // total: totalProducts,
3047
- // scanned: scannedProducts,
3048
- // misplaced: misplacedProducts,
3049
- // proper: properProducts,
3050
- // missing: missingProducts,
3051
- // };
2836
+ const shelfIds = sectionShelves.map( ( shelf ) => shelf.toObject()._id );
3052
2837
 
3053
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
3054
- // planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
3055
- // planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
3056
- // ] );
3057
-
3058
- // const shelfMetrics = {
3059
- // shelfId: productMapping.toObject().shelfId,
3060
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false };
3061
-
3062
-
3063
- // return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
3064
- // } else if ( fixture.productResolutionLevel === 'L3' ) {
3065
- // if ( !req.body.shelfId && req.body.rfId ) {
3066
- // const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
3067
- // if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
3068
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
3069
- // planoMappingService.count( { shelfId: shelf.toObject()._id } ),
3070
- // planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
3071
- // ] );
3072
- // return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
3073
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
3074
- // }
3075
-
3076
- // if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
3077
-
3078
- // const mappingQuery = {
3079
- // planoId: req.body.planoId,
3080
- // floorId: req.body.floorId,
3081
- // fixtureId: req.body.fixtureId,
3082
- // shelfId: req.body.shelfId,
3083
- // rfId: req.body.rfId,
3084
- // };
2838
+ const planoMapping = await planoMappingService.findOne( { rfId: req.body.rfId, shelfId: { $in: shelfIds } } );
3085
2839
 
3086
- // const productMapping = await planoMappingService.findOne( mappingQuery );
3087
-
3088
- // if ( !productMapping ) {
3089
- // const shelf = await fixtureShelfService.findOne( { _id: new mongoose.Types.ObjectId( req.body.shelfId ) } );
3090
-
3091
- // if ( !shelf ) {
3092
- // return res.sendError( 'Invalid shelf Id', 400 );
3093
- // }
3094
- // const misplacedQuery = {
3095
- // planoId: req.body.planoId,
3096
- // floorId: req.body.floorId,
3097
- // rfId: req.body.rfId,
3098
- // };
3099
- // const misplacedProductMapping = await planoMappingService.findOne( misplacedQuery );
3100
-
3101
-
3102
- // if ( !misplacedProductMapping ) {
3103
- // const shelf = await fixtureShelfService.findOne( misplacedQuery );
3104
- // if ( !shelf ) {
3105
- // return res.sendSuccess( { data: null, status: 'missing' } );
3106
- // }
3107
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
3108
- // planoMappingService.count( { shelfId: shelf.toObject()._id } ),
3109
- // planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
3110
- // ] );
3111
-
3112
- // return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
3113
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
3114
- // }
3115
-
3116
-
3117
- // const misplacedProductShelf = await fixtureShelfService.findOne( { _id: misplacedProductMapping.toObject().shelfId } );
3118
-
3119
- // let misplacedProductDetails = await planoProductService.findOne( { _id: misplacedProductMapping.toObject().productId } );
3120
-
3121
- // if ( shelf.toObject().sectionName === misplacedProductShelf.toObject().sectionName ) {
3122
- // const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'proper' };
3123
- // delete complianceData._id;
3124
-
3125
- // await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
3126
-
3127
- // const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
3128
- // planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
3129
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
3130
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
3131
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
3132
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
3133
- // ] );
3134
-
3135
- // const fixtureMetrics = {
3136
- // total: totalProducts,
3137
- // scanned: scannedProducts,
3138
- // misplaced: misplacedProducts,
3139
- // proper: properProducts,
3140
- // missing: missingProducts,
3141
- // };
3142
-
3143
-
3144
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
3145
- // planoMappingService.count( { shelfId: misplacedProductMapping.toObject().shelfId } ),
3146
- // planoComplianceService.count( { date: currentDate, shelfId: misplacedProductMapping.toObject().shelfId, compliance: 'proper' } ),
3147
- // ] );
3148
-
3149
- // const shelfMetrics = {
3150
- // shelfId: misplacedProductMapping.toObject().shelfId,
3151
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false };
3152
-
3153
- // return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) },
3154
- // fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
3155
- // } else {
3156
- // return res.sendError( 'RFID conflict with section', 400 );
3157
- // }
3158
- // }
3159
-
3160
-
3161
- // const complianceData = { ...productMapping.toObject(), compliance: 'proper' };
3162
- // delete complianceData._id;
3163
-
3164
- // let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
3165
-
3166
- // await planoComplianceService.updateOne( { ...mappingQuery, planoMappingId: productMapping.toObject()._id, date: currentDate }, complianceData );
3167
-
3168
- // const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
3169
- // planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
3170
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
3171
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
3172
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
3173
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
3174
- // ] );
3175
-
3176
- // const fixtureMetrics = {
3177
- // total: totalProducts,
3178
- // scanned: scannedProducts,
3179
- // misplaced: misplacedProducts,
3180
- // proper: properProducts,
3181
- // missing: missingProducts,
3182
- // };
2840
+ if ( !planoMapping ) {
2841
+ const locatePlano = await planoMappingService.findOne( { rfId: req.body.rfId, floorId: req.body.floorId } );
3183
2842
 
3184
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
3185
- // planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
3186
- // planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
3187
- // ] );
3188
-
3189
- // const shelfMetrics = {
3190
- // shelfId: productMapping.toObject().shelfId,
3191
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false };
3192
-
3193
- // return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
3194
- // } else if ( fixture.productResolutionLevel === 'L4' ) {
3195
- // if ( !req.body.shelfId && req.body.rfId ) {
3196
- // const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
3197
- // if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
3198
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
3199
- // planoMappingService.count( { shelfId: shelf.toObject()._id } ),
3200
- // planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
3201
- // ] );
3202
- // return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
3203
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
3204
- // }
3205
-
3206
- // if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
3207
-
3208
- // if ( !req.body.shelfPosition ) return res.sendError( 'Shelf position is required', 400 );
3209
-
3210
- // const mappingQuery = {
3211
- // planoId: req.body.planoId,
3212
- // floorId: req.body.floorId,
3213
- // fixtureId: req.body.fixtureId,
3214
- // shelfId: req.body.shelfId,
3215
- // shelfPosition: req.body.shelfPosition,
3216
- // };
2843
+ if ( !locatePlano ) {
2844
+ return res.sendSuccess( { data: null, fixtureMetrics: null, status: 'missing' } );
2845
+ }
3217
2846
 
3218
- // const productMapping = await planoMappingService.findOne( mappingQuery );
3219
-
3220
- // if ( !productMapping ) {
3221
- // const shelf = await fixtureShelfService.findOne( mappingQuery );
3222
- // if ( !shelf ) {
3223
- // return res.sendSuccess( { data: null, status: 'missing' } );
3224
- // }
3225
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
3226
- // planoMappingService.count( { shelfId: shelf.toObject()._id } ),
3227
- // planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
3228
- // ] );
3229
- // return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
3230
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
3231
- // }
3232
-
3233
- // if ( productMapping.toObject().rfId !== req.body.rfId ) {
3234
- // const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'misplaced' };
3235
- // delete complianceData._id;
3236
-
3237
- // let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
3238
-
3239
- // const isComplianceProper = await planoComplianceService.count( { ...mappingQuery, date: currentDate, compliance: 'proper' } );
3240
-
3241
- // if ( !isComplianceProper ) {
3242
- // await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
3243
- // }
3244
-
3245
-
3246
- // const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
3247
- // planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
3248
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
3249
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
3250
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
3251
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
3252
- // ] );
3253
-
3254
- // const fixtureMetrics = {
3255
- // total: totalProducts,
3256
- // scanned: scannedProducts,
3257
- // misplaced: misplacedProducts,
3258
- // proper: properProducts,
3259
- // missing: missingProducts,
3260
- // };
3261
-
3262
- // return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
3263
- // }
3264
-
3265
- // const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
3266
- // delete complianceData._id;
3267
-
3268
- // let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
3269
-
3270
- // await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
3271
-
3272
- // const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
3273
- // planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
3274
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
3275
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
3276
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
3277
- // planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
3278
- // ] );
3279
-
3280
- // const fixtureMetrics = {
3281
- // total: totalProducts,
3282
- // scanned: scannedProducts,
3283
- // misplaced: misplacedProducts,
3284
- // proper: properProducts,
3285
- // missing: missingProducts,
3286
- // };
2847
+ const locatePlanoData = locatePlano.toObject();
3287
2848
 
3288
- // const [ shelfProducts, shelfCompliance ] = await Promise.all( [
3289
- // planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
3290
- // planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
3291
- // ] );
2849
+ delete locatePlanoData._id;
3292
2850
 
3293
- // const shelfMetrics = {
3294
- // shelfId: productMapping.toObject().shelfId,
3295
- // isScanned: shelfCompliance >= shelfProducts/2 ? true : false };
2851
+ const complianceData = { ...locatePlanoData, planoMappingId: locatePlano.toObject()._id, compliance: 'misplaced' };
3296
2852
 
3297
- // return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
3298
- // }
3299
- else if ( fixture.productResolutionLevel === 'L3' ) {
3300
- const sectionShelves = await fixtureShelfService.find( { fixtureId: fixture._id, sectionName: req.body.sectionName } );
2853
+ await planoComplianceService.updateOne( { date: currentDate, planoMappingId: locatePlano.toObject()._id }, complianceData );
3301
2854
 
3302
- if ( !sectionShelves.length ) return res.sendError( 'No shelves found for the Section', 400 );
3303
2855
 
3304
- const shelfIds = sectionShelves.map( ( shelf ) => shelf.toObject()._id );
2856
+ const fm = await getFixtureMetrics( fixture, currentDate );
3305
2857
 
3306
- const mappingQuery = await planoMappingService.findOne( { rfId: req.body.rfId, shelfId: { $in: shelfIds } } );
3307
2858
 
3308
- if ( !mappingQuery ) return res.sendSuccess( { data: null, fixtureMetrics: null, status: 'misplaced' } );
2859
+ return res.sendSuccess( { data: { ...locatePlano.toObject() }, fixtureMetrics: fm, status: 'misplaced' } );
2860
+ }
3309
2861
 
3310
- const mapingData = mappingQuery.toObject();
2862
+ const mapingData = planoMapping.toObject();
3311
2863
 
3312
2864
  delete mapingData._id;
3313
2865
 
3314
- const complianceData = { ...mapingData, planoMappingId: mappingQuery.toObject()._id, compliance: 'proper' };
2866
+ const complianceData = { ...mapingData, planoMappingId: planoMapping.toObject()._id, compliance: 'proper' };
3315
2867
 
3316
- await planoComplianceService.updateOne( { date: currentDate, planoMappingId: mappingQuery.toObject()._id }, complianceData );
2868
+ await planoComplianceService.updateOne( { date: currentDate, planoMappingId: planoMapping.toObject()._id }, complianceData );
3317
2869
 
3318
- let productDetails = await planoProductService.findOne( { _id: mapingData.productId } );
3319
-
3320
- const [ totalProducts, scannedProducts, misplacedProducts, properProducts, missingProducts ] = await Promise.all( [
3321
- planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
3322
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
3323
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
3324
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
3325
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
3326
- ] );
3327
-
3328
- const fixtureMetrics = {
3329
- total: totalProducts,
3330
- scanned: scannedProducts,
3331
- misplaced: misplacedProducts,
3332
- proper: properProducts,
3333
- missing: missingProducts,
3334
- };
2870
+ const fm = await getFixtureMetrics( fixture, currentDate );
3335
2871
 
3336
- return res.sendSuccess( { data: { ...mapingData, ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'proper' } );
2872
+ return res.sendSuccess( { data: { ...planoMapping.toObject() }, fixtureMetrics: fm, status: 'proper' } );
3337
2873
  } else {
3338
2874
  return res.sendError( 'Incorrect resolution level', 400 );
3339
2875
  }
@@ -26,7 +26,7 @@ storeBuilderRouter
26
26
  .post( '/storeFixtures', validate( validateDtos.storeList ), storeBuilderController.storeFixturesv1 )
27
27
  .post( '/FixtureShelfDetails', validate( validateDtos.fixtureShelfProduct ), storeBuilderController.fixtureShelfProductv1 )
28
28
  .post( '/scan', isAllowedSessionHandler, storeBuilderController.scanv1 )
29
- .post( '/updateMissing', isAllowedSessionHandler, storeBuilderController.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 )