From f3d2595b239501f338b095cdcf478bc9a7eef615 Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Fri, 22 Oct 2021 16:02:36 +1300 Subject: [PATCH] Add location repository for frontend --- frontend/src/repository/LocationRepository.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 frontend/src/repository/LocationRepository.js 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;