tango-app-api-store-builder 1.0.0-beta-87 → 1.0.0-beta-89

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-87",
3
+ "version": "1.0.0-beta-89",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -4341,7 +4341,7 @@ export async function updateCrestPlanogram( req, res ) {
4341
4341
  let staticToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQ1NTE3MjQxLCJpYXQiOjE3NDU1MTM2NDEsImp0aSI6Ijg3MWVlNTA3ODY2OTQ5OTVhMTQ0YTk4NzQyNzY0MzEzIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.eGzTMGwwstr13M0Hu1Ls5-gkE_oSPMJJBL2wgygT6Ac';
4342
4342
 
4343
4343
  async function fetchStoreData( store, bearerToken, res ) {
4344
- const payload = JSON.stringify( { store_id: store.toObject().storeName } );
4344
+ const payload = JSON.stringify( { store_id: store.toObject().storeName?.toUpperCase() } );
4345
4345
 
4346
4346
  try {
4347
4347
  const response = await fetch( layoutApiUrl, {
@@ -5363,7 +5363,7 @@ export async function updateCrestPlanogram( req, res ) {
5363
5363
 
5364
5364
  const now = Date.now();
5365
5365
  const elapsedMinutes = ( now - startTime ) / 1000 / 60;
5366
- console.log( `Store name: ${storeData.storeName}, Iteration ${i + 1}: total elapsed time = ${elapsedMinutes.toFixed( 2 )} minutes` );
5366
+ console.log( `Store name: ${storeData.storeName}, Iteration ${i + 1}/${storeList?.length}: total elapsed time = ${elapsedMinutes.toFixed( 2 )} minutes` );
5367
5367
  }
5368
5368
 
5369
5369
  res.sendSuccess( 'Updated Successfully' );
@@ -553,7 +553,7 @@ export async function storeFixturesv1( req, res ) {
553
553
  {
554
554
  $or: [
555
555
  { _id: { $in: planoIds } },
556
- { storeName: { $in: req.body.id } },
556
+ { storeId: { $in: req.body.id } },
557
557
  ],
558
558
  },
559
559
  { storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, clientId: 1, validateShelfSections: 1 },
@@ -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
- 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
- }
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 ) {
@@ -2861,3 +2861,484 @@ export async function storeLayoutElements( req, res ) {
2861
2861
  return res.sendError( e, 500 );
2862
2862
  }
2863
2863
  }
2864
+
2865
+ export async function qrScan( req, res ) {
2866
+ try {
2867
+ if ( !req.body.floorId ) return res.sendError( 'Floor id is required', 400 );
2868
+
2869
+ if ( !req.body.fixtureId ) return res.sendError( 'Fixture id is required', 400 );
2870
+
2871
+ if ( !req.body.rfId ) return res.sendError( 'RFID is required', 400 );
2872
+ const fixture = await storeFixtureService.findOne(
2873
+ { _id: new mongoose.Types.ObjectId( req.body.fixtureId ) },
2874
+ { storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1 },
2875
+ );
2876
+
2877
+ if ( !fixture ) return res.sendError( 'No data found', 204 );
2878
+
2879
+ const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
2880
+
2881
+
2882
+ if ( fixture.productResolutionLevel === 'L1' ) {
2883
+ const mappingQuery = {
2884
+ planoId: req.body.planoId,
2885
+ floorId: req.body.floorId,
2886
+ fixtureId: req.body.fixtureId,
2887
+ rfId: req.body.rfId,
2888
+ };
2889
+
2890
+ const productMapping = await planoMappingService.findOne( mappingQuery );
2891
+
2892
+ if ( !productMapping ) {
2893
+ const misplacedQuery = {
2894
+ planoId: req.body.planoId,
2895
+ floorId: req.body.floorId,
2896
+ rfId: req.body.rfId,
2897
+ };
2898
+ const misplacedProductMapping = await planoMappingService.findOne( misplacedQuery );
2899
+
2900
+ if ( !misplacedProductMapping ) {
2901
+ return res.sendSuccess( { data: null, status: 'missing' } );
2902
+ }
2903
+
2904
+ const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
2905
+ delete complianceData._id;
2906
+
2907
+ let misplacedProductDetails = await planoProductService.findOne( { _id: misplacedProductMapping.toObject().productId } );
2908
+
2909
+ await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
2910
+
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
+ };
2926
+
2927
+ return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
2928
+ }
2929
+
2930
+ const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
2931
+ delete complianceData._id;
2932
+
2933
+ let productDetails = await planoProductService.findOne( { _id: productMapping.productId } );
2934
+
2935
+ await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
2936
+
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' } ),
2943
+
2944
+ ] );
2945
+
2946
+ const fixtureMetrics = {
2947
+ total: totalProducts,
2948
+ scanned: scannedProducts,
2949
+ misplaced: misplacedProducts,
2950
+ proper: properProducts,
2951
+ missing: missingProducts,
2952
+ };
2953
+
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
+ // };
2977
+
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
+ // };
3052
+
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
+ // };
3085
+
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
+ // };
3183
+
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
+ // };
3217
+
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
+ // };
3287
+
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
+ // ] );
3292
+
3293
+ // const shelfMetrics = {
3294
+ // shelfId: productMapping.toObject().shelfId,
3295
+ // isScanned: shelfCompliance >= shelfProducts/2 ? true : false };
3296
+
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 } );
3301
+
3302
+ if ( !sectionShelves.length ) return res.sendError( 'No shelves found for the Section', 400 );
3303
+
3304
+ const shelfIds = sectionShelves.map( ( shelf ) => shelf.toObject()._id );
3305
+
3306
+ const mappingQuery = await planoMappingService.findOne( { rfId: req.body.rfId, shelfId: { $in: shelfIds } } );
3307
+
3308
+ if ( !mappingQuery ) return res.sendSuccess( { data: null, fixtureMetrics: null, status: 'misplaced' } );
3309
+
3310
+ const mapingData = mappingQuery.toObject();
3311
+
3312
+ delete mapingData._id;
3313
+
3314
+ const complianceData = { ...mapingData, planoMappingId: mappingQuery.toObject()._id, compliance: 'proper' };
3315
+
3316
+ await planoComplianceService.updateOne( { date: currentDate, planoMappingId: mappingQuery.toObject()._id }, complianceData );
3317
+
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
+ };
3335
+
3336
+ return res.sendSuccess( { data: { ...mapingData, ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'proper' } );
3337
+ } else {
3338
+ return res.sendError( 'Incorrect resolution level', 400 );
3339
+ }
3340
+ } catch ( e ) {
3341
+ logger.error( { functionName: 'scanv1', error: e, message: req.body } );
3342
+ return res.sendError( e, 500 );
3343
+ }
3344
+ }
@@ -24,7 +24,7 @@ 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', isAllowedSessionHandler, validate( validateDtos.fixtureShelfProduct ), storeBuilderController.fixtureShelfProductv1 )
27
+ .post( '/FixtureShelfDetails', validate( validateDtos.fixtureShelfProduct ), storeBuilderController.fixtureShelfProductv1 )
28
28
  .post( '/scan', isAllowedSessionHandler, storeBuilderController.scanv1 )
29
29
  .post( '/updateMissing', isAllowedSessionHandler, storeBuilderController.updateMissing )
30
30
  .post( '/bulkFixtureUpload', isAllowedSessionHandler, storeBuilderController.bulkFixtureUpload )
@@ -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 );