From 5f0b357d883a936c1bc7456041de3f5a9ff2457d Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Mon, 5 Dec 2022 18:22:08 +0100 Subject: [PATCH] Updated ts types, sync w/ backend --- src/lib/cartStore.ts | 7 ++++--- src/lib/interfaces/ApiResponse.ts | 18 +++++++++++++--- src/lib/interfaces/IOrder.ts | 12 ++--------- src/lib/websocketCart.ts | 1 + src/routes/checkout/DeliverySection.svelte | 13 ++++++++---- src/routes/checkout/OrderSection.svelte | 14 ++++++------- src/routes/login/+page.svelte | 4 ++-- src/routes/orders/[id]/CustomerDetails.svelte | 8 +++---- src/routes/orders/[id]/OrderSummary.svelte | 2 +- src/routes/receipt/[[id]]/+page.svelte | 21 +++++++++---------- src/routes/sitemap.xml/+server.ts | 4 +--- 11 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/lib/cartStore.ts b/src/lib/cartStore.ts index 000037c..ef93556 100644 --- a/src/lib/cartStore.ts +++ b/src/lib/cartStore.ts @@ -1,14 +1,15 @@ -import { writable, get, derived } from 'svelte/store'; +import { writable, derived } from 'svelte/store'; import type { Writable, Readable } from 'svelte/store'; +import type ICart from './interfaces/ICart'; -export const cart: Writable = writable([]); +export const cart: Writable = writable([]); export const isOpen: Writable = writable(false); export const count: Readable = derived(cart, ($cart) => $cart.length || 0); export const subTotal: Readable = derived(cart, ($cart) => { let total = 0; - $cart.forEach((cartItem) => (total += cartItem.price * cartItem.quantity)); + $cart.forEach((cartItem: ICart) => (total += cartItem.price * cartItem.quantity)); return total; }); diff --git a/src/lib/interfaces/ApiResponse.ts b/src/lib/interfaces/ApiResponse.ts index e32e071..4dc221b 100644 --- a/src/lib/interfaces/ApiResponse.ts +++ b/src/lib/interfaces/ApiResponse.ts @@ -1,27 +1,39 @@ import type { IProduct } from './IProduct'; import type { IOrder, IOrderSummary } from './IOrder'; +import type ICustomer from './ICustomer'; +import type ICart from './ICart'; export interface IProductResponse { success: boolean; products: Array; } -export interface IOrderResponse { +export interface IOrderDTO { success: boolean; order: IOrder; } +export interface IOrderCreateDTO { + customer: ICustomer; + cart: ICart[]; +} + export interface IOrderSummaryResponse { success: boolean; order: IOrderSummary; } -export interface IProductResponse { +export interface IProductDTO { success: boolean; product: IProduct; } -export interface IProductsResponse { +export interface IProductsDTO { success: boolean; products: Array; } + +export interface ICartDTO { + cart: ICart[]; + success: boolean; +} diff --git a/src/lib/interfaces/IOrder.ts b/src/lib/interfaces/IOrder.ts index 60383cb..f30afb3 100644 --- a/src/lib/interfaces/IOrder.ts +++ b/src/lib/interfaces/IOrder.ts @@ -1,5 +1,6 @@ // import type IProduct from './IProduct'; // import type BadgeType from './BadgeType'; +import type ICustomer from './ICustomer'; export interface IStripePayment { amount: number; @@ -26,17 +27,8 @@ export interface IOrder { created?: Date; } -export interface ICustomer { - city: string; - customer_no: string; - email: string; - firstname: string; - lastname: string; - streetaddress: string; - zipcode: number; -} - export interface ILineItem { + sku_id: number; image: string; name: string; price: number; diff --git a/src/lib/websocketCart.ts b/src/lib/websocketCart.ts index b4b49ff..bede984 100644 --- a/src/lib/websocketCart.ts +++ b/src/lib/websocketCart.ts @@ -1,5 +1,6 @@ import { dev } from '$app/environment'; import { cart as cartStore } from './cartStore'; +import type { ICartDTO } from './interfaces/ApiResponse'; const WS_HOST = '127.0.0.1'; const WS_PORT = 30010; diff --git a/src/routes/checkout/DeliverySection.svelte b/src/routes/checkout/DeliverySection.svelte index 73ffcef..73822eb 100644 --- a/src/routes/checkout/DeliverySection.svelte +++ b/src/routes/checkout/DeliverySection.svelte @@ -11,11 +11,16 @@
- - + + - - + +
diff --git a/src/routes/checkout/OrderSection.svelte b/src/routes/checkout/OrderSection.svelte index 7ddff40..2ef2e13 100644 --- a/src/routes/checkout/OrderSection.svelte +++ b/src/routes/checkout/OrderSection.svelte @@ -21,23 +21,23 @@ {#if $cart.length} - {#each $cart as order} + {#each $cart as cartItem}
- {order.name} - Størrelse: {order.size} + {cartItem.name} + Størrelse: {cartItem.size}
- Nok {order.quantity * order.price} + Nok {cartItem.quantity * cartItem.price} {/each} {:else} diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index 8e96e53..2012ebb 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -6,9 +6,9 @@ let password: string; let displayMessage: string | null; - function postLogin(event: any) { + function postLogin(event: SubmitEvent) { displayMessage = null; - const formData = new FormData(event.target); + const formData = new FormData(event.target as HTMLFormElement); const data = {}; formData.forEach((value, key) => (data[key] = value)); diff --git a/src/routes/orders/[id]/CustomerDetails.svelte b/src/routes/orders/[id]/CustomerDetails.svelte index f265a27..c07cdb7 100644 --- a/src/routes/orders/[id]/CustomerDetails.svelte +++ b/src/routes/orders/[id]/CustomerDetails.svelte @@ -1,5 +1,5 @@
@@ -31,14 +30,14 @@ A payment to PLANETPOSEN, AS will appear on your statement with order number: {id}.

-

Order receipt has been email to: {email}

+

En ordrebekreftelse er sent til: {email}

- {#each products as product} + {#each order?.lineItems as lineItem}

- {product.name} x{product.quantity} - {product.currency} {product.price * product.quantity} + {lineItem.name} x{lineItem.quantity} + NOK {lineItem.price * lineItem.quantity}

{/each}

@@ -48,7 +47,7 @@

Total - NOK {subTotal(products)} + NOK {subTotal(order?.lineItems)}

diff --git a/src/routes/sitemap.xml/+server.ts b/src/routes/sitemap.xml/+server.ts index 4ad1381..71957d1 100644 --- a/src/routes/sitemap.xml/+server.ts +++ b/src/routes/sitemap.xml/+server.ts @@ -1,6 +1,4 @@ -import { dev } from '$app/environment'; -import { env } from '$env/dynamic/private'; -import type { IProductResponse } from '$lib/interfaces/ApiResponse'; +import type { IProductsDTO } from '$lib/interfaces/ApiResponse'; const domain = 'planet.schleppe.cloud'; const pages: Array = [