Don't put a comma in the last menuitem if there is no others left
This commit is contained in:
parent
950b2ad97c
commit
d1aeb50f29
20
index.mjs
20
index.mjs
|
@ -1,18 +1,28 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import fetch from "node-fetch";
|
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";
|
||||||
var todayDate = new Date().toISOString().slice(0, 10).replaceAll('-', '');
|
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) {
|
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) === todayDate);
|
const daysFiltered = days.filter((day) => String(day.date) === getDate());
|
||||||
const foods = [];
|
const foods = [];
|
||||||
daysFiltered[0].mealoptions.map((mealoption) => {
|
daysFiltered[0].mealoptions.map((mealoption) => {
|
||||||
let str = ""
|
let str = ""
|
||||||
str += mealoption.name + ": "
|
str += mealoption.name + ": "
|
||||||
mealoption.menuItems.map((menuItem) => {
|
mealoption.menuItems.map((menuItem, index) => {
|
||||||
str += menuItem.name + ", "
|
index !== mealoption.menuItems.length - 1 ? str += menuItem.name + ", " : str += menuItem.name;
|
||||||
|
console.log(index, mealoption.menuItems.length)
|
||||||
})
|
})
|
||||||
foods.push(str);
|
foods.push(str);
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"start": "node index.mjs"
|
"start": "node index.mjs"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"faifood": "index.mjs"
|
"faifood": "index.mjs"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
Loading…
Reference in New Issue