tango-app-api-store-builder 1.0.0-beta-12 → 1.0.0-beta-13
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
|
@@ -780,51 +780,109 @@ export async function fixtureShelfProductv1( req, res ) {
|
|
|
780
780
|
|
|
781
781
|
if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
|
|
782
782
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
783
|
+
if ( planogram.toObject().productResolutionLevel === 'L3' ) {
|
|
784
|
+
const groupedShelves = await ( async () => {
|
|
785
|
+
const shelfProducts = await Promise.all(
|
|
786
|
+
fixtureShelves.map( async ( shelf ) => {
|
|
787
|
+
const productMappings = await planoMappingService.find( { shelfId: shelf._id } );
|
|
788
|
+
|
|
789
|
+
if ( !productMappings.length ) {
|
|
790
|
+
return { ...shelf.toObject(), products: [] };
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const productIds = productMappings.map( ( mapping ) => mapping.productId );
|
|
794
|
+
const products = await planoProductService.find( { _id: { $in: productIds } } );
|
|
795
|
+
const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
|
|
796
|
+
|
|
797
|
+
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
798
|
+
|
|
799
|
+
const productDetails = await Promise.all(
|
|
800
|
+
productMappings.map( async ( mapping ) => {
|
|
801
|
+
const productData = productMap.get( mapping.productId.toString() );
|
|
802
|
+
if ( !productData ) {
|
|
803
|
+
return { ...mapping.toObject(), status: '' };
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const mappingCompliance = await planoComplianceService.findOne( {
|
|
807
|
+
shelfId: mapping.shelfId,
|
|
808
|
+
shelfPosition: mapping.shelfPosition,
|
|
809
|
+
date: currentDate,
|
|
810
|
+
} );
|
|
811
|
+
|
|
812
|
+
const status = mappingCompliance ? mappingCompliance.compliance : 'missing';
|
|
813
|
+
|
|
814
|
+
return {
|
|
815
|
+
...mapping.toObject(),
|
|
816
|
+
...productData,
|
|
817
|
+
status,
|
|
818
|
+
};
|
|
819
|
+
} ),
|
|
820
|
+
);
|
|
821
|
+
|
|
822
|
+
return {
|
|
823
|
+
...shelf.toObject(),
|
|
824
|
+
products: productDetails,
|
|
825
|
+
};
|
|
826
|
+
} ),
|
|
827
|
+
);
|
|
786
828
|
|
|
787
|
-
|
|
788
|
-
|
|
829
|
+
return shelfProducts.reduce( ( acc, shelf ) => {
|
|
830
|
+
const sectionName = shelf.sectionName || 'Unknown';
|
|
831
|
+
if ( !acc[sectionName] ) {
|
|
832
|
+
acc[sectionName] = [];
|
|
789
833
|
}
|
|
834
|
+
acc[sectionName].push( shelf );
|
|
835
|
+
return acc;
|
|
836
|
+
}, {} );
|
|
837
|
+
} )();
|
|
838
|
+
return res.sendSuccess( { ...fixture.toObject(), categories: groupedShelves } );
|
|
839
|
+
} else if ( planogram.toObject().productResolutionLevel === 'L4' || planogram.toObject().productResolutionLevel === 'L5' ) {
|
|
840
|
+
const shelfProducts = await Promise.all(
|
|
841
|
+
fixtureShelves.map( async ( shelf ) => {
|
|
842
|
+
const productMappings = await planoMappingService.find( { shelfId: shelf._id } );
|
|
843
|
+
|
|
844
|
+
if ( !productMappings.length ) {
|
|
845
|
+
return { ...shelf.toObject(), products: [] };
|
|
846
|
+
}
|
|
790
847
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
848
|
+
const productIds = productMappings.map( ( mapping ) => mapping.productId );
|
|
849
|
+
const products = await planoProductService.find( { _id: { $in: productIds } } );
|
|
850
|
+
const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
|
|
851
|
+
|
|
852
|
+
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
853
|
+
|
|
854
|
+
const productDetails = await Promise.all(
|
|
855
|
+
productMappings.map( async ( mapping ) => {
|
|
856
|
+
const productData = productMap.get( mapping.productId.toString() );
|
|
857
|
+
if ( !productData ) {
|
|
858
|
+
return { ...mapping.toObject(), status: '' };
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
const mappingCompliance = await planoComplianceService.findOne( {
|
|
862
|
+
shelfId: mapping.shelfId,
|
|
863
|
+
shelfPosition: mapping.shelfPosition,
|
|
864
|
+
date: currentDate,
|
|
865
|
+
} );
|
|
866
|
+
|
|
867
|
+
const status = mappingCompliance ? mappingCompliance.compliance : 'missing';
|
|
868
|
+
|
|
869
|
+
return {
|
|
870
|
+
...mapping.toObject(),
|
|
871
|
+
...productData,
|
|
872
|
+
status,
|
|
873
|
+
};
|
|
874
|
+
} ),
|
|
875
|
+
);
|
|
876
|
+
|
|
877
|
+
return {
|
|
878
|
+
...shelf.toObject(),
|
|
879
|
+
products: productDetails,
|
|
880
|
+
};
|
|
881
|
+
} ),
|
|
882
|
+
);
|
|
883
|
+
|
|
884
|
+
return res.sendSuccess( { ...fixture.toObject(), shelves: shelfProducts } );
|
|
885
|
+
}
|
|
828
886
|
} catch ( e ) {
|
|
829
887
|
logger.error( { functionName: 'fixtureShelfProductv1', error: e, message: req.body } );
|
|
830
888
|
return res.sendError( e, 500 );
|
|
@@ -975,7 +1033,75 @@ export async function scanv1( req, res ) {
|
|
|
975
1033
|
|
|
976
1034
|
if ( !planogram ) return res.sendError( 'No data found', 204 );
|
|
977
1035
|
|
|
978
|
-
if ( planogram.productResolutionLevel === '
|
|
1036
|
+
if ( planogram.productResolutionLevel === 'L3' ) {
|
|
1037
|
+
if ( !req.body.floorId ) return res.sendError( 'Floor id is required', 400 );
|
|
1038
|
+
|
|
1039
|
+
if ( !req.body.rfId ) return res.sendError( 'RFID is required', 400 );
|
|
1040
|
+
|
|
1041
|
+
if ( !req.body.fixtureId ) return res.sendError( 'Fixture id is required', 400 );
|
|
1042
|
+
|
|
1043
|
+
if ( !req.body.shelfId && req.body.rfId ) {
|
|
1044
|
+
const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
|
|
1045
|
+
if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
|
|
1046
|
+
return res.sendSuccess( shelf.toObject()._id );
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
|
|
1050
|
+
|
|
1051
|
+
const mappingQuery = {
|
|
1052
|
+
planoId: req.body.planoId,
|
|
1053
|
+
floorId: req.body.floorId,
|
|
1054
|
+
fixtureId: req.body.fixtureId,
|
|
1055
|
+
shelfId: req.body.shelfId,
|
|
1056
|
+
rfId: req.body.rfId,
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
const productMapping = await planoMappingService.findOne( mappingQuery );
|
|
1060
|
+
|
|
1061
|
+
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
1062
|
+
|
|
1063
|
+
if ( !productMapping ) {
|
|
1064
|
+
const shelf = await fixtureShelfService.findOne( { _id: new mongoose.Types.ObjectId( req.body.shelfId ) } );
|
|
1065
|
+
|
|
1066
|
+
if ( !shelf ) {
|
|
1067
|
+
return res.sendError( 'Invalid shelf Id', 400 );
|
|
1068
|
+
}
|
|
1069
|
+
const misplacedQuery = {
|
|
1070
|
+
planoId: req.body.planoId,
|
|
1071
|
+
floorId: req.body.floorId,
|
|
1072
|
+
rfId: req.body.rfId,
|
|
1073
|
+
};
|
|
1074
|
+
const misplacedProductMapping = await planoMappingService.findOne( misplacedQuery );
|
|
1075
|
+
|
|
1076
|
+
if ( !misplacedProductMapping ) {
|
|
1077
|
+
return res.sendError( 'No product found for the RFID', 400 );
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
let misplacedProductDetails = await planoProductService.findOne( { _id: misplacedProductMapping.toObject().productId } );
|
|
1081
|
+
|
|
1082
|
+
if ( shelf.toObject().sectionName === misplacedProductMapping.toObject().category ) {
|
|
1083
|
+
const complianceData = { ...misplacedProductMapping.toObject(), compliance: 'proper' };
|
|
1084
|
+
delete complianceData._id;
|
|
1085
|
+
|
|
1086
|
+
await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
|
|
1087
|
+
return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject(): {} ) }, status: true } );
|
|
1088
|
+
} else {
|
|
1089
|
+
const complianceData = { ...misplacedProductMapping.toObject(), compliance: 'misplaced' };
|
|
1090
|
+
delete complianceData._id;
|
|
1091
|
+
|
|
1092
|
+
await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
|
|
1093
|
+
return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject(): {} ) }, status: false } );
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
const complianceData = { ...productMapping.toObject(), compliance: 'proper' };
|
|
1099
|
+
delete complianceData._id;
|
|
1100
|
+
|
|
1101
|
+
await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
|
|
1102
|
+
|
|
1103
|
+
return res.sendSuccess( { data: productMapping.toObject(), status: true } );
|
|
1104
|
+
} else if ( planogram.productResolutionLevel === 'L4' || planogram.productResolutionLevel === 'L5' ) {
|
|
979
1105
|
if ( !req.body.floorId ) return res.sendError( 'Floor id is required', 400 );
|
|
980
1106
|
|
|
981
1107
|
if ( !req.body.rfId ) return res.sendError( 'RFID is required', 400 );
|