diff --git a/frontend/src/repository/LocationRepository.js b/frontend/src/repository/LocationRepository.js new file mode 100644 index 0000000..f8a7487 --- /dev/null +++ b/frontend/src/repository/LocationRepository.js @@ -0,0 +1,34 @@ +import API from "./Repository"; + + +const LocationRepsostory = { + + getSoilDetails(filters) { + return API.get(`/soil/`, { params: filters }); + }, + + getEcologicalDistrictDetails(filters) { + return API.get(`/ecologicaldistrict/`, { params: filters }); + }, + + getPropertyDetails(filters) { + return API.get(`/address/`, { params: filters }); + }, + + async getLocationData(filters) { + const [soilDetails, ecologicalDistrictDetails, propertyDetails] = await Promise.all([ + this.getSoilDetails(filters), + this.getEcologicalDistrictDetails(filters), + this.getPropertyDetails(filters) + ]); + + let locationData = {}; + locationData = soilDetails.status === 200 ? Object.assign(locationData, soilDetails.data[0]) : locationData; + locationData = ecologicalDistrictDetails.status === 200 ? Object.assign(locationData, ecologicalDistrictDetails.data[0]) : locationData; + locationData = propertyDetails.status === 200 ? Object.assign(locationData, propertyDetails.data) : locationData; + + return locationData + } +} + +export default LocationRepsostory;