diff --git a/front/src/lib/cart.ts b/front/src/lib/cart.ts index 6377d9e..5820c44 100644 --- a/front/src/lib/cart.ts +++ b/front/src/lib/cart.ts @@ -25,18 +25,14 @@ function createCartStore() { async function addToCart(uuid: string, amount: number) { if (get(cart)[uuid] !== undefined) { cart.update((cart: Record) => { - cart[uuid].amount += amount; + cart[uuid].amount += amount; // skipcq: JS-0320 return cart; }); } else { await getItemByUUID(uuid).then((data: Item) => { cart.update((cart: Record) => Object.assign({}, cart, { - [uuid]: { - uuid: uuid, - amount: amount, - data: data, - }, + [uuid]: {uuid, amount, data}, }) ); }); @@ -44,7 +40,7 @@ function createCartStore() { cart.update((cart: Record) => { if (cart[uuid].amount <= 0) { - delete cart[uuid]; + delete cart[uuid]; // skipcq: JS-0320 } return cart; }); @@ -59,7 +55,7 @@ function createCartStore() { } function getTotalLength(): number { - let totalCartSize: number = 0; + let totalCartSize = 0; Object.values(get(cart)).forEach((item: CartItem) => { totalCartSize += item.amount; }); diff --git a/front/src/lib/test-api.ts b/front/src/lib/test-api.ts index 0804d24..be87189 100644 --- a/front/src/lib/test-api.ts +++ b/front/src/lib/test-api.ts @@ -1,11 +1,9 @@ import { type CartItem, type Item } from "./types"; import TestData from "./test-data"; -let cache: Record = {}; +const cache = {}; -// @ts-ignore -async function fakeDelay(timeout: number = 1000) { - // @ts-ignore +async function fakeDelay(timeout = 1000) { await new Promise((resolve: TimerHandler) => setTimeout(resolve, timeout)); } @@ -58,7 +56,7 @@ export async function getMenuItems(): Promise< export async function getItemsByUUID(items: string[]): Promise { await fakeDelay(200); - let data: Item[] = []; + const data: Item[] = []; TestData.forEach((itemInDatabase: Item) => { items.forEach((itemInRequest) => { @@ -68,7 +66,7 @@ export async function getItemsByUUID(items: string[]): Promise { }); }); - if (data.length < 0) { + if (data.length === 0) { throw new Error("Resource could not be found"); } @@ -76,15 +74,14 @@ export async function getItemsByUUID(items: string[]): Promise { } export async function getItemByUUID(uuid: string): Promise { - let data: Item[]; + const data: Item[] = []; await getItemsByUUID([uuid]) .then((result) => { - if (result.length != 1) { + if (result.length !== 1) { throw new Error("Resource could not be found"); - } else { - data = result; } + data.push(...result); }) .catch((error) => { throw error; @@ -118,17 +115,17 @@ export async function postContactEmail( export async function postVerifyCart( currentCartData: Record ): Promise> { - let verifiedItems: Item[] = []; + const verifiedItems: Item[] = []; await getItemsByUUID(Object.keys(currentCartData)) .then((data) => { - verifiedItems = data; + verifiedItems.push(...data); }) .catch(() => { return new Error("Could not collect new cart information"); }); - let newCartData: Record = {}; + const newCartData: Record = {}; Object.entries(currentCartData).forEach(([key, value]) => { verifiedItems.forEach((verifiedItem: Item) => { diff --git a/front/src/lib/utils.js b/front/src/lib/utils.js index 7ff3337..d5ece3e 100644 --- a/front/src/lib/utils.js +++ b/front/src/lib/utils.js @@ -1,6 +1,6 @@ export function expandOnTyping(element) { element.oninput = (event) => { event.target.style.height = ""; - event.target.style.height = event.target.scrollHeight + 2 + "px"; + event.target.style.height = `${event.target.scrollHeight + 2}px`; }; }