Don't put a comma in the last menuitem if there is no others left

This commit is contained in:
Your Name 2022-11-09 11:10:27 +02:00
parent 950b2ad97c
commit d1aeb50f29
2 changed files with 16 additions and 6 deletions

View File

@ -1,18 +1,28 @@
#!/usr/bin/env node
import fetch from "node-fetch";
const APIURI = "https://fi.jamix.cloud/apps/menuservice/rest/haku/menu/92225/1?lang=fi"
var todayDate = new Date().toISOString().slice(0, 10).replaceAll('-', '');
const APIURI = "https://fi.jamix.cloud/apps/menuservice/rest/haku/menu/92225/1?lang=fi";
const myArgs = process.argv.slice(2);
function getDate() {
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 daysFiltered = days.filter((day) => String(day.date) === todayDate);
const daysFiltered = days.filter((day) => String(day.date) === getDate());
const foods = [];
daysFiltered[0].mealoptions.map((mealoption) => {
let str = ""
str += mealoption.name + ": "
mealoption.menuItems.map((menuItem) => {
str += menuItem.name + ", "
mealoption.menuItems.map((menuItem, index) => {
index !== mealoption.menuItems.length - 1 ? str += menuItem.name + ", " : str += menuItem.name;
console.log(index, mealoption.menuItems.length)
})
foods.push(str);
})