From 9761e4b0aa87498b1e7ff4fba1c41dc7123522e2 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Fri, 3 May 2024 19:43:27 +0100 Subject: [PATCH] Cache errors Missing `;` --- front/src/lib/cart.ts | 9 ++++----- front/src/lib/test-api.ts | 34 ++++++++++++++++----------------- front/src/pages/PageItem.svelte | 2 +- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/front/src/lib/cart.ts b/front/src/lib/cart.ts index f4e66f8..fc60d55 100644 --- a/front/src/lib/cart.ts +++ b/front/src/lib/cart.ts @@ -1,7 +1,6 @@ -import type { Writable } from "svelte/store"; -import { get, writable } from "svelte/store"; +import { type Writable, get, writable } from "svelte/store"; -import { type CartItem } from './types'; +import {type CartItem, type Item } from './types'; import { getItemByUUID, postVerifyCart } from "./test-api"; @@ -32,14 +31,14 @@ function createCartStore() { }); } else { await getItemByUUID(uuid) - .then((data) => { + .then((data: Item) => { cart.update((cart: Record) => Object.assign({}, cart, {[uuid]: { uuid: uuid, amount: amount, data: data, }}) - ) + ); }); } diff --git a/front/src/lib/test-api.ts b/front/src/lib/test-api.ts index dfb551f..e5b2317 100644 --- a/front/src/lib/test-api.ts +++ b/front/src/lib/test-api.ts @@ -2,10 +2,7 @@ import { type CartItem, type Item } from './types'; import TestData from './test-data'; -let cache = { - announcement_banner: undefined, - popular_today: undefined, -}; +let cache: Record = {}; // @ts-ignore @@ -16,28 +13,28 @@ async function fakeDelay(timeout: number = 1000) { export async function getAnnouncements(): Promise<{image: string}> { - if (cache.announcement_banner) { - return cache.announcement_banner; + if (cache["announcement_banner"] !== undefined) { + return cache["announcement_banner"]; } - await fakeDelay(200) + await fakeDelay(200); const data = { image: "/BannerExampleImage.jpg", }; - cache.announcement_banner = data; + cache["announcement_banner"] = data; return data; } export async function getPopularToday(): Promise { - if (cache.popular_today) { - return cache.popular_today; + if (cache["popular_today"] !== undefined) { + return cache["popular_today"]; } - await fakeDelay(200) + await fakeDelay(200); const data: Item[] = TestData; - cache.popular_today = data; + cache["popular_today"] = data; return data; } @@ -63,7 +60,7 @@ export async function getMenuItems(): Promise<{name: string, items: Item[]}[]> { export async function getItemsByUUID(items: string[]): Promise { - await fakeDelay(200) + await fakeDelay(200); let data: Item[] = []; @@ -103,7 +100,7 @@ export async function getItemByUUID(uuid: string): Promise { export async function postContactEmail(name: string, email: string, message: string): Promise { - await fakeDelay(200) + await fakeDelay(200); if (!name) { throw new Error("Name missing"); @@ -121,19 +118,20 @@ export async function postContactEmail(name: string, email: string, message: str } export async function postVerifyCart(currentCartData: Record): Promise> { - let verifiedItems: Item[] = [] + let verifiedItems: Item[] = []; await getItemsByUUID(Object.keys(currentCartData)) .then((data) => { - verifiedItems = data + verifiedItems = data; }) .catch(() => { - return new Error("Could not collect new cart information") + return new Error("Could not collect new cart information"); }); let newCartData: Record = {}; + Object.entries(currentCartData).forEach(([key, value]) => { - verifiedItems.forEach((verifiedItem) => { + verifiedItems.forEach((verifiedItem: Item) => { if (verifiedItem.uuid === key) { newCartData[key] = { uuid: value.uuid, diff --git a/front/src/pages/PageItem.svelte b/front/src/pages/PageItem.svelte index 89b24c9..01f723b 100644 --- a/front/src/pages/PageItem.svelte +++ b/front/src/pages/PageItem.svelte @@ -9,7 +9,7 @@ export let params; - $: item = getItemByUUID(params.uuid) + $: item = getItemByUUID(params.uuid); $: popularToday = getPopularToday();