From b57b019295270031bc4c9d093e44443ff2429571 Mon Sep 17 00:00:00 2001 From: Matthew Oslan Date: Thu, 6 Jun 2019 16:17:06 -0400 Subject: [PATCH] Add default implementations to WeatherProvider --- routes/weather.ts | 10 ---------- routes/weatherProviders/WeatherProvider.ts | 14 ++++++++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/routes/weather.ts b/routes/weather.ts index 257dff8..4b7856f 100644 --- a/routes/weather.ts +++ b/routes/weather.ts @@ -184,11 +184,6 @@ function checkWeatherRestriction( adjustmentValue: number, weather: WateringData export const getWeatherData = async function( req: express.Request, res: express.Response ) { const location: string = getParameter(req.query.loc); - if ( !weatherProvider.getWeatherData ) { - res.send( "Error: selected WeatherProvider does not support getWeatherData" ); - return; - } - let coordinates: GeoCoordinates; try { coordinates = await resolveCoordinates( location ); @@ -263,11 +258,6 @@ export const getWateringData = async function( req: express.Request, res: expres let timeData: TimeData = getTimeData( coordinates ); let wateringData: WateringData; if ( adjustmentMethod !== ADJUSTMENT_METHOD.MANUAL || checkRestrictions ) { - if ( !weatherProvider.getWateringData ) { - res.send( "Error: selected WeatherProvider does not support getWateringData" ); - return; - } - try { wateringData = await weatherProvider.getWateringData( coordinates ); } catch ( err ) { diff --git a/routes/weatherProviders/WeatherProvider.ts b/routes/weatherProviders/WeatherProvider.ts index 5581860..4826df2 100644 --- a/routes/weatherProviders/WeatherProvider.ts +++ b/routes/weatherProviders/WeatherProvider.ts @@ -5,15 +5,21 @@ export class WeatherProvider { * Retrieves weather data necessary for watering level calculations. * @param coordinates The coordinates to retrieve the watering data for. * @return A Promise that will be resolved with the WateringData if it is successfully retrieved, - * or rejected with an error message if an error occurs while retrieving the WateringData. + * or rejected with an error message if an error occurs while retrieving the WateringData or the WeatherProvider + * does not support this method. */ - getWateringData?( coordinates : GeoCoordinates ): Promise< WateringData >; + getWateringData( coordinates : GeoCoordinates ): Promise< WateringData > { + throw "Selected WeatherProvider does not support getWateringData"; + } /** * Retrieves the current weather data for usage in the mobile app. * @param coordinates The coordinates to retrieve the weather for * @return A Promise that will be resolved with the WeatherData if it is successfully retrieved, - * or rejected with an error message if an error occurs while retrieving the WeatherData. + * or rejected with an error message if an error occurs while retrieving the WeatherData or the WeatherProvider does + * not support this method. */ - getWeatherData?( coordinates : GeoCoordinates ): Promise< WeatherData >; + getWeatherData( coordinates : GeoCoordinates ): Promise< WeatherData > { + throw "Selected WeatherProvider does not support getWeatherData"; + } }