Browse Source

🎨 Format code

main
Galimede 5 years ago
parent
commit
dba0301260
  1. 33
      index.js

33
index.js

@ -5,7 +5,6 @@ import axios from 'axios';
const app = fastify({ logger: true });
async function getFoxImage() {
try {
const fox = await axios.get('https://randomfox.ca/floof/');
return fox.data.image;
@ -13,21 +12,20 @@ async function getFoxImage() {
console.error(`Error : ${e}`);
return null;
}
}
async function getFactCat(amount = 0) {
try {
let fact;
if (fact <= 0) {
fact = await axios
.get(`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=1`);
fact = await axios.get(
`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=1`,
);
} else {
fact = await axios
.get(`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=${amount}`);
fact = await axios.get(
`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=${amount}`,
);
}
const filteredFacts = fact.data.map((fact) => {
@ -35,20 +33,19 @@ async function getFactCat(amount = 0) {
});
return filteredFacts;
} catch (e) {
console.error(`Error : ${e}`);
return null;
}
}
async function getHolidays(countryCode = 'FR') {
try {
const currentDate = new Date(Date.now());
const currentYear = currentDate.getFullYear();
const holidays = await axios.get(`https://date.nager.at/api/v2/PublicHolidays/2021/${countryCode}`);
const holidays = await axios.get(
`https://date.nager.at/api/v2/PublicHolidays/2021/${countryCode}`,
);
return holidays.data;
} catch (e) {
console.error(`Error : ${e}`);
@ -62,20 +59,16 @@ async function fetchApis(countryCode) {
const holidays = await getHolidays(countryCode);
return {
"foxPicture": foxImage,
"catFacts": catFacts,
"holidays": holidays
}
foxPicture: foxImage,
catFacts: catFacts,
holidays: holidays,
};
}
app.post('/', async (req, res) => {
return await fetchApis(req.body.countryCode);
});
// Run the server!
const start = async () => {
try {

Loading…
Cancel
Save