mirror of
https://github.com/Fluffy-Bean/TastyBites.git
synced 2025-06-19 08:30:36 +00:00
Effort to transition to TypeScript
Remove commit warnings
This commit is contained in:
parent
4f0ecd33e4
commit
1486c1b70a
18 changed files with 93 additions and 87 deletions
|
@ -1,4 +1,4 @@
|
|||
import Items from '%/lib/test-data.js';
|
||||
import TestData from '%/lib/test-data.ts';
|
||||
|
||||
export async function getPopularToday() {
|
||||
const res = await fetch("/api/items")
|
||||
|
@ -15,7 +15,7 @@ export function getMenuItems() {
|
|||
return [
|
||||
{
|
||||
name: "Main Menu",
|
||||
items: Items,
|
||||
items: TestData,
|
||||
},
|
||||
{
|
||||
name: "Breakfast",
|
||||
|
@ -23,7 +23,7 @@ export function getMenuItems() {
|
|||
},
|
||||
{
|
||||
name: "Seasonal",
|
||||
items: Items,
|
||||
items: TestData,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import Items from '%/lib/test-data.js';
|
||||
import type { Item } from './types';
|
||||
import TestData from './test-data';
|
||||
|
||||
|
||||
let cache = {
|
||||
|
@ -7,8 +8,10 @@ let cache = {
|
|||
};
|
||||
|
||||
|
||||
// @ts-ignore
|
||||
async function fakeDelay(timeout: number = 1000) {
|
||||
await new Promise(resolve => setTimeout(resolve, timeout));
|
||||
// @ts-ignore
|
||||
await new Promise((resolve: TimerHandler) => setTimeout(resolve, timeout));
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,7 +34,7 @@ export async function getPopularToday() {
|
|||
return cache.popular_today;
|
||||
}
|
||||
|
||||
const data = Items;
|
||||
const data = TestData;
|
||||
cache.popular_today = data;
|
||||
await fakeDelay(200)
|
||||
return data;
|
||||
|
@ -42,7 +45,7 @@ export async function getMenuItems() {
|
|||
const data = [
|
||||
{
|
||||
name: "Main Menu",
|
||||
items: Items,
|
||||
items: TestData,
|
||||
},
|
||||
{
|
||||
name: "Breakfast",
|
||||
|
@ -50,7 +53,7 @@ export async function getMenuItems() {
|
|||
},
|
||||
{
|
||||
name: "Seasonal",
|
||||
items: Items,
|
||||
items: TestData,
|
||||
},
|
||||
];
|
||||
await fakeDelay(20)
|
||||
|
@ -61,7 +64,7 @@ export async function getMenuItems() {
|
|||
export async function getItemsByUUID(items: string[]) {
|
||||
let data = [];
|
||||
|
||||
Items.forEach((itemInDatabase) => {
|
||||
TestData.forEach((itemInDatabase: Item) => {
|
||||
items.forEach((itemInRequest) => {
|
||||
if (itemInDatabase.uuid === itemInRequest) {
|
||||
data.push(itemInDatabase);
|
||||
|
@ -94,10 +97,10 @@ export async function postContactEmail(name: string, email: string, message: str
|
|||
await fakeDelay(200)
|
||||
|
||||
if (!name) {
|
||||
throw new Error("Namey missing");
|
||||
throw new Error("Name missing");
|
||||
}
|
||||
if (!email) {
|
||||
throw new Error("Emaily missing");
|
||||
throw new Error("Email missing");
|
||||
}
|
||||
if (!message) {
|
||||
throw new Error("Message missing");
|
||||
|
|
|
@ -1,80 +1,72 @@
|
|||
// "vegan", "fish", "nut", "spicy", "gluten"
|
||||
import type { Item } from './types';
|
||||
import { Labels } from "./types";
|
||||
|
||||
const Items = [
|
||||
// soap: {
|
||||
const TestData: Item[] = [
|
||||
{
|
||||
uuid: "soap",
|
||||
name: "Bar of Soap",
|
||||
price: 69.99,
|
||||
labels: ["vegan", "spicy"],
|
||||
labels: [Labels.vegan, Labels.spicy],
|
||||
detail: "Example",
|
||||
},
|
||||
// sock: {
|
||||
{
|
||||
uuid: "sock",
|
||||
name: "Sock",
|
||||
price: 21,
|
||||
labels: ["vegan", "fish", "nut", "spicy"],
|
||||
labels: [Labels.vegan, Labels.fish, Labels.nut, Labels.spicy],
|
||||
detail: "Example",
|
||||
},
|
||||
// brick: {
|
||||
{
|
||||
uuid: "brick",
|
||||
name: "Brick",
|
||||
price: 0,
|
||||
labels: ["spicy"],
|
||||
labels: [Labels.spicy],
|
||||
detail: "Example",
|
||||
},
|
||||
// toast: {
|
||||
{
|
||||
uuid: "toast",
|
||||
name: "Toast",
|
||||
price: 4382749832743,
|
||||
labels: ["gluten"],
|
||||
labels: [Labels.gluten],
|
||||
detail: "Example",
|
||||
},
|
||||
// water: {
|
||||
{
|
||||
uuid: "water",
|
||||
name: "water",
|
||||
price: 1,
|
||||
labels: ["fish"],
|
||||
labels: [Labels.fish],
|
||||
detail: "Example",
|
||||
},
|
||||
// mouldy_bread: {
|
||||
{
|
||||
uuid: "mouldy_bread",
|
||||
name: "half eaten mouldy bread",
|
||||
price: -99,
|
||||
labels: ["nut"],
|
||||
labels: [Labels.nut],
|
||||
detail: "Example",
|
||||
},
|
||||
// gwagwa: {
|
||||
// {
|
||||
// uuid: "gwagwa",
|
||||
// name: "GwaGwa",
|
||||
// price: "Priceless",
|
||||
// labels: ["nut"],
|
||||
// image: "/dab.jpg",
|
||||
// },
|
||||
// hogmelon: {
|
||||
{
|
||||
uuid: "gwagwa",
|
||||
name: "GwaGwa",
|
||||
price: 69,
|
||||
labels: [Labels.nut],
|
||||
image: "/dab.jpg",
|
||||
},
|
||||
{
|
||||
uuid: "hogmelon",
|
||||
name: "Hogermellon",
|
||||
price: "1111",
|
||||
labels: ["fish"],
|
||||
price: 1111,
|
||||
labels: [Labels.fish],
|
||||
image: "/wathog.jpg",
|
||||
detail: "Example",
|
||||
},
|
||||
// bluhog: {
|
||||
{
|
||||
uuid: "bluhog",
|
||||
name: "Blue HOGGGGG",
|
||||
price: "ARUGH",
|
||||
labels: ["nut", "gluten", "spicy"],
|
||||
price: 0,
|
||||
labels: [Labels.nut, Labels.gluten, Labels.spicy],
|
||||
image: "/sonichog.jpg",
|
||||
detail: "Example",
|
||||
},
|
||||
];
|
||||
|
||||
export default Items;
|
||||
export default TestData;
|
16
front/src/lib/types.ts
Normal file
16
front/src/lib/types.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
export interface Item {
|
||||
uuid: string,
|
||||
name: string,
|
||||
price: number,
|
||||
detail?: string,
|
||||
labels: Labels[],
|
||||
image?: string,
|
||||
}
|
||||
|
||||
export enum Labels {
|
||||
vegan = "VEGAN",
|
||||
fish = "FISH",
|
||||
nut = "NUT",
|
||||
spicy = "SPICY",
|
||||
gluten = "GLUTEN",
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue