From 7fa3fc3c8e86bcf1b39540728b3e40ba7526b035 Mon Sep 17 00:00:00 2001 From: Leo Jeong <80350771+33tm@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:23:01 -0700 Subject: [PATCH] refresh daily + account for empty menu --- functions/src/menu.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/functions/src/menu.ts b/functions/src/menu.ts index b17f37a..33102d9 100644 --- a/functions/src/menu.ts +++ b/functions/src/menu.ts @@ -21,7 +21,7 @@ export const menu = functions.https.onCall(async () => { } const current = (await firestore.collection('gunn').doc('menu').get()).data()!; - if (DateTime.fromISO(current.timestamp).plus({ week: 1 }) > now) + if (DateTime.fromISO(current.timestamp).plus({ day: 1 }) > now) return; const { daysInMonth, month, year } = now.plus({ week: 1 }); @@ -54,15 +54,18 @@ export const menu = functions.https.onCall(async () => { } async function getMenu(date: DateTime) { - const { year, month, day } = date + const { year, month, day } = date; const [brunch, lunch] = await Promise.all(['breakfast', 'lunch'].map(async meal => { const { menu_items } = await fetch(`${nutrislice}/digest/school/henry-m-gunn-hs/menu-type/${meal}/date/${year}/${month}/${day}`) .then(res => res.json()) .catch(() => []); if (!menu_items) return; return Object.fromEntries(menu_items.map((item: string) => [item, nutrition.get(item) ?? null])); - })) - return [date.toFormat('MM-dd'), { brunch, lunch }]; + })); + return [date.toFormat('MM-dd'), { + brunch: brunch ?? null, + lunch: lunch ?? null + }]; } const days = Array