From 48e1ad7f77c122eafc7a54515521dffab3d1c678 Mon Sep 17 00:00:00 2001 From: Daanii Kusnanta Date: Fri, 29 Sep 2023 17:22:45 +0000 Subject: [PATCH 1/2] check for city with same name --- README.md | 6 ++++-- src/controllers/weather.js | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66bd9cc..09d5a80 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Sumber: [Data Terbuka BMKG](https://data.bmkg.go.id/). `/{provinsi}` -> :warning: Gunakan `/dki-jakarta` dan `di-yogyakarta` untuk Provinsi DKI Jakarta dan DI Yogyakarta. +> :warning: Gunakan `/dki-jakarta` dan `/di-yogyakarta` untuk Provinsi DKI Jakarta dan DI Yogyakarta. **Contoh:** @@ -234,13 +234,15 @@ Sumber: [Data Terbuka BMKG](https://data.bmkg.go.id/). ### Kota +> :warning: Selalu tambahkan `kota-` atau `kabupaten-` sebelum nama kota/kabupaten. + **Endpoint:** `/{provinsi}/{kota}` **Contoh:** -`/jawa-barat/bandung` +`/jawa-barat/kota-bandung` **Response:** diff --git a/src/controllers/weather.js b/src/controllers/weather.js index e8d03cd..19d5089 100644 --- a/src/controllers/weather.js +++ b/src/controllers/weather.js @@ -47,6 +47,8 @@ const getByCity = async (req, res) => { const weatherByCity = refactoredJsonWeathers.areas.find( (area) => area.description == toUpperFirstLetterWords(city, '-', ' ') + ) || refactoredJsonWeathers.areas.find( + (area) => area.description == toUpperFirstLetterWords(city.replace(/^(kabupaten-|kota-)/, ""), '-', ' ') ); if (!weatherByCity) { From a1d01f1e75cd0ccd6c23ec09e35b61c413c7db8c Mon Sep 17 00:00:00 2001 From: Daanii Kusnanta Date: Fri, 29 Sep 2023 17:57:48 +0000 Subject: [PATCH 2/2] change regex --- src/controllers/weather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/weather.js b/src/controllers/weather.js index 19d5089..b79702e 100644 --- a/src/controllers/weather.js +++ b/src/controllers/weather.js @@ -48,7 +48,7 @@ const getByCity = async (req, res) => { const weatherByCity = refactoredJsonWeathers.areas.find( (area) => area.description == toUpperFirstLetterWords(city, '-', ' ') ) || refactoredJsonWeathers.areas.find( - (area) => area.description == toUpperFirstLetterWords(city.replace(/^(kabupaten-|kota-)/, ""), '-', ' ') + (area) => area.description == toUpperFirstLetterWords(city.replace(/^(kabupaten\-|kota\-)/, ""), '-', ' ') ); if (!weatherByCity) {