Refactor, last implementation was kind of stupid
This commit is contained in:
parent
51d6978124
commit
203b1015a9
32
index.mjs
32
index.mjs
|
@ -4,33 +4,27 @@ import fetch from "node-fetch";
|
||||||
const APIURI = "https://fi.jamix.cloud/apps/menuservice/rest/haku/menu/92225/1?lang=fi";
|
const APIURI = "https://fi.jamix.cloud/apps/menuservice/rest/haku/menu/92225/1?lang=fi";
|
||||||
const myArgs = process.argv.slice(2);
|
const myArgs = process.argv.slice(2);
|
||||||
|
|
||||||
function getDate() {
|
function getAllFoods(data) {
|
||||||
switch (myArgs[0]) {
|
|
||||||
case "t":
|
|
||||||
return new Date(new Date().getTime() + 24 * 60 * 60 * 1000).toISOString().slice(0, 10).replaceAll('-', '');
|
|
||||||
default:
|
|
||||||
return new Date().toISOString().slice(0, 10).replaceAll('-', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFood(data) {
|
|
||||||
const days = data[0].menuTypes[0].menus[0].days
|
const days = data[0].menuTypes[0].menus[0].days
|
||||||
const daysFiltered = days.filter((day) => String(day.date) === getDate());
|
|
||||||
|
|
||||||
const foods = [];
|
const foods = [];
|
||||||
foods.push(String(daysFiltered[0].date));
|
days.map((day) => {
|
||||||
daysFiltered[0].mealoptions.map((mealoption) => {
|
foods.push(String(day.date));
|
||||||
let str = ""
|
day.mealoptions.map((mealoption, index) => {
|
||||||
str += mealoption.name + ": "
|
let str = ""
|
||||||
mealoption.menuItems.map((menuItem, index) => {
|
str += mealoption.name + ": "
|
||||||
index !== mealoption.menuItems.length - 1 ? str += menuItem.name + ", " : str += menuItem.name;
|
mealoption.menuItems.map((menuItem, index) => {
|
||||||
|
index !== mealoption.menuItems.length - 1 ? str += menuItem.name + ", " : str += menuItem.name;
|
||||||
|
})
|
||||||
|
foods.push(str);
|
||||||
|
index === day.mealoptions.length - 1 ? foods.push("\n") : '';
|
||||||
})
|
})
|
||||||
foods.push(str);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
return foods;
|
return foods;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(APIURI)
|
fetch(APIURI)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => getFood(data).map((food) => console.log(food)));
|
.then((data) => getAllFoods(data).map(food => console.log(food)));
|
||||||
|
|
Loading…
Reference in New Issue