Last active
September 17, 2019 12:12
-
-
Save dennbagas/29be1e9a5da153d434c80746b0c0f43f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
module.exports.index = async (req, res, next) => { | |
const rawcity = req.query.kota; | |
let city; | |
if (rawcity) { | |
city = rawcity.toLowerCase() | |
.split(' ') | |
.map((s) => s.charAt(0).toUpperCase() + s.substring(1)) | |
.join(' '); | |
} else { | |
res.send("parameter kota tidak boleh kosong"); | |
} | |
fs.readFile('cache/weather.json', (err, data) => { | |
let weather = JSON.parse(data.toString()); | |
let weatherData = weather.filter((element) => element.kota.includes(city)); | |
if (weatherData.length > 0) { | |
res.send(weatherData[0]); | |
} else { | |
res.send("kota tidak ditemukan"); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment