From e335fcdc129bfec6c676458afdd5936af52312a4 Mon Sep 17 00:00:00 2001 From: Spokequenouille Date: Wed, 17 Feb 2021 20:41:40 +0100 Subject: [PATCH] API working :bug: --- index.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 7697e32..c4ed3e9 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ const getCat = () => { catsFacts.push(element.text); }); resolve(catsFacts); - }).catch(fail => resolve(null)); + }).catch(camarchepas => resolve(null)); }); } @@ -22,37 +22,34 @@ const getFox = () => { .then(res => { resolve(res.data.image) }) - .catch(fail => resolve(null)); + .catch(camarchepas => resolve(null)); }); } -const getDayOffByCountry = (code ) => { +const getDayOffByCountry = (countryCode ) => { return new Promise(resolve => { - axios.get(`https://date.nager.at/api/v2/PublicHolidays/2021/${code}`) + axios.get(`https://date.nager.at/api/v2/PublicHolidays/2021/${countryCode}`) .then(res => { resolve(res.data) }) - .catch(fail => { - resolve("null"); - console.log(fail) + .catch(camarchepas => { + resolve(null); }); }); }; -const getAll = async(code) => { - console.log('le code est : ' + code) - const dayOffByCountry = await getDayOffByCountry(code); - const fox = await getFox(); - const cat = await getCat(); - return Promise.all([cat, fox, dayOffByCountry]).then(() => { +const getAll = async(countryCode) => { + const holidays = await getDayOffByCountry(countryCode); + const foxPicture = await getFox(); + const catFacts = await getCat(); + return Promise.all([catFacts, foxPicture, holidays]).then(() => { return{ - fox, cat, dayOffByCountry + foxPicture, catFacts, holidays } }) } app.post('/', async (req, res) => { - console.log("ntm " +req.body.countryCode); return getAll(req.body.countryCode); });