From 9383a2fb09ffb60cfe63683106945bd688affa59 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 1 Jun 2022 21:13:43 +0200 Subject: feat: Initial commit after clean slate --- src/wwwroot/scripts/api/account-api.ts | 28 +++++++++++ src/wwwroot/scripts/api/account-api.types.ts | 5 ++ src/wwwroot/scripts/api/categories-api.ts | 33 +++++++++++++ src/wwwroot/scripts/api/categories-api.types.ts | 17 +++++++ src/wwwroot/scripts/api/db-base.ts | 3 ++ src/wwwroot/scripts/api/documents-api.ts | 24 ++++++++++ src/wwwroot/scripts/api/order-api.ts | 64 +++++++++++++++++++++++++ src/wwwroot/scripts/api/order-api.types.ts | 39 +++++++++++++++ src/wwwroot/scripts/api/products-api.ts | 59 +++++++++++++++++++++++ src/wwwroot/scripts/api/products-api.types.ts | 35 ++++++++++++++ src/wwwroot/scripts/api/settings-api.ts | 17 +++++++ src/wwwroot/scripts/api/settings-api.types.ts | 3 ++ 12 files changed, 327 insertions(+) create mode 100644 src/wwwroot/scripts/api/account-api.ts create mode 100644 src/wwwroot/scripts/api/account-api.types.ts create mode 100644 src/wwwroot/scripts/api/categories-api.ts create mode 100644 src/wwwroot/scripts/api/categories-api.types.ts create mode 100644 src/wwwroot/scripts/api/db-base.ts create mode 100644 src/wwwroot/scripts/api/documents-api.ts create mode 100644 src/wwwroot/scripts/api/order-api.ts create mode 100644 src/wwwroot/scripts/api/order-api.types.ts create mode 100644 src/wwwroot/scripts/api/products-api.ts create mode 100644 src/wwwroot/scripts/api/products-api.types.ts create mode 100644 src/wwwroot/scripts/api/settings-api.ts create mode 100644 src/wwwroot/scripts/api/settings-api.types.ts (limited to 'src/wwwroot/scripts/api') diff --git a/src/wwwroot/scripts/api/account-api.ts b/src/wwwroot/scripts/api/account-api.ts new file mode 100644 index 0000000..0d8604b --- /dev/null +++ b/src/wwwroot/scripts/api/account-api.ts @@ -0,0 +1,28 @@ +import {LoginPayload} from "./account-api.types" + +export function login(payload: LoginPayload, xsrf: string): Promise { + return fetch("/api/account/login", { + method: "post", + body: JSON.stringify(payload), + headers: { + "Content-Type": "application/json;charset=utf-8", + "XSRF-TOKEN": xsrf + } + }); +} + +export function logout(): Promise { + return fetch("/api/account/logout"); +} + +export function updatePassword(newPassword: string): Promise { + return fetch("/api/account/update-password", { + method: "post", + body: JSON.stringify({ + newPassword + }), + headers: { + "Content-Type": "application/json;charset=utf-8" + } + }); +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/account-api.types.ts b/src/wwwroot/scripts/api/account-api.types.ts new file mode 100644 index 0000000..3c02441 --- /dev/null +++ b/src/wwwroot/scripts/api/account-api.types.ts @@ -0,0 +1,5 @@ +export interface LoginPayload { + username: string, + password: string, + persist: boolean +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/categories-api.ts b/src/wwwroot/scripts/api/categories-api.ts new file mode 100644 index 0000000..1ca1d97 --- /dev/null +++ b/src/wwwroot/scripts/api/categories-api.ts @@ -0,0 +1,33 @@ +export function getCategories(withProducts: boolean = false): Promise { + return fetch(withProducts ? "/api/categories/with-products" : "/api/categories"); +} + +export function getCategory(categoryId: string): Promise { + return fetch("/api/categories/" + categoryId); +} + +export function createCategory(name: string, disabled: boolean): Promise { + return fetch("/api/categories/create?" + new URLSearchParams({ + name + })); +} + +export function updateCategory(categoryId: string, newName: string): Promise { + return fetch("/api/categories/" + categoryId + "/update?" + new URLSearchParams({ + newName + })); +} + +export function deleteCategory(categoryId: string): Promise { + return fetch("/api/categories/" + categoryId + "/delete", { + method: "delete" + }); +} + +export function enableCategory(categoryId: string): Promise { + return fetch("/api/categories/" + categoryId + "/enable"); +} + +export function disableCategory(categoryId: string): Promise { + return fetch("/api/categories/" + categoryId + "/disable"); +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/categories-api.types.ts b/src/wwwroot/scripts/api/categories-api.types.ts new file mode 100644 index 0000000..7040cea --- /dev/null +++ b/src/wwwroot/scripts/api/categories-api.types.ts @@ -0,0 +1,17 @@ +import {Base} from "./db-base"; +import {Product} from "./products-api.types"; + +export interface Category extends Base { + name: string, + slug: string, + visibilityState: CategoryVisibility, + disabled: boolean, + deleted: boolean, + products: Array +} + +export enum CategoryVisibility { + Default = 0, + Disabled = 1, + Deleted = 2 +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/db-base.ts b/src/wwwroot/scripts/api/db-base.ts new file mode 100644 index 0000000..a6593a1 --- /dev/null +++ b/src/wwwroot/scripts/api/db-base.ts @@ -0,0 +1,3 @@ +export interface Base { + id: string, +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/documents-api.ts b/src/wwwroot/scripts/api/documents-api.ts new file mode 100644 index 0000000..f458f6c --- /dev/null +++ b/src/wwwroot/scripts/api/documents-api.ts @@ -0,0 +1,24 @@ +export function uploadDocumentImages(files: Array): Promise { + if (files.length <= 0) throw new Error("files.length was " + files.length); + const data = new FormData(); + for (const file of files) + data.append("files", file); + + return fetch("/api/documents/upload-images", { + method: "post", + body: data + }); +} + +export function getDocument(documentType: string) { + return fetch("/api/documents/" + documentType); +} + +export function setDocument(documentType: string, content: string) { + const fd = new FormData(); + fd.append("content", content); + return fetch("/api/documents/" + documentType, { + method: "post", + body: fd, + }); +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/order-api.ts b/src/wwwroot/scripts/api/order-api.ts new file mode 100644 index 0000000..eaacffe --- /dev/null +++ b/src/wwwroot/scripts/api/order-api.ts @@ -0,0 +1,64 @@ +import {SubmitOrderPayload, ValidateOrderPayload} from "./order-api.types"; + +export function validateOrderProducts(payload: ValidateOrderPayload): Promise { + return fetch("/api/orders/validate-products", { + headers: { + "Content-Type": "application/json;charset=utf-8" + }, + body: JSON.stringify(payload), + method: "post", + credentials: "include" + }); +} + +export function validateOrder(payload: ValidateOrderPayload): Promise { + return fetch("/api/orders/validate", { + headers: { + "Content-Type": "application/json;charset=utf-8" + }, + body: JSON.stringify(payload), + method: "post", + credentials: "include" + }); +} + +export function getOrderDetails(id): Promise { + return fetch("/api/orders/" + id + "/details", { + credentials: "include" + }); +} + +export function captureVippsOrder(id: String): Promise { + return fetch("/api/orders/" + id + "/capture") +} + +export function cancelOrder(id: String): Promise { + return fetch("/api/orders/" + id + "/cancel") +} + +export function refundOrder(id: String): Promise { + return fetch("/api/orders/" + id + "/refund") +} + +export function submitOrder(payload: SubmitOrderPayload): Promise { + return fetch("/api/orders/submit", { + headers: { + "Content-Type": "application/json;charset=utf-8" + }, + body: JSON.stringify(payload), + method: "post", + credentials: "include" + }); +} + +export function getOrders(filter?: string): Promise { + return fetch("/api/orders?filter=" + filter, { + credentials: "include" + }); +} + +export function getOrder(id): Promise { + return fetch("/api/orders/" + id, { + credentials: "include" + }); +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/order-api.types.ts b/src/wwwroot/scripts/api/order-api.types.ts new file mode 100644 index 0000000..8f4ca25 --- /dev/null +++ b/src/wwwroot/scripts/api/order-api.types.ts @@ -0,0 +1,39 @@ +import {Base} from "./db-base"; + +export interface ValidateOrderPayload { + products: Array +} + +export interface Order extends Base { + comment: string, + paymentType: OrderPaymentType, + status: OrderStatus, + ContactInfo: ContactInformation, + ProductIds: Array +} + +export interface SubmitOrderPayload extends Order { +} + +export interface ContactInformation { + name: string, + phoneNumber: string, + emailaddress: string +} + +export interface ProductValidationDto { + id: string, + count: number +} + +export enum OrderPaymentType { + Vipps = 0, + InvoiceByEmail = 1 +} + +export enum OrderStatus { + InProgress = 0, + Completed = 3, + Canceled = 1, + Failed = 2 +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/products-api.ts b/src/wwwroot/scripts/api/products-api.ts new file mode 100644 index 0000000..6069830 --- /dev/null +++ b/src/wwwroot/scripts/api/products-api.ts @@ -0,0 +1,59 @@ +import {CreateProductPayload, Product} from "./products-api.types"; + +export function createProduct(payload: CreateProductPayload): Promise { + return fetch("/api/products/create", { + headers: { + "Content-Type": "application/json;charset=utf-8" + }, + body: JSON.stringify(payload), + method: "post", + credentials: "include" + }); +} + +export function getProduct(id: string): Promise { + return fetch("/api/products/" + id, { + method: "get", + credentials: "include" + }); +} + +export function getProducts(): Promise { + return fetch("/api/products", { + method: "get", + credentials: "include" + }); +} + +export function uploadProductImages(files: Array): Promise { + if (files.length <= 0) throw new Error("files.length was " + files.length); + const data = new FormData(); + for (const file of files) + data.append("files", file); + + return fetch("/api/products/upload-images", { + method: "post", + body: data + }); +} + +export function deleteProduct(id: string): Promise { + return fetch("/api/products/" + id + "/delete", { + method: "delete", + credentials: "include" + }); +} + +export function updateProduct(data: Product): Promise { + if (!data.id) { + throw new Error("data.id was undefined"); + } + return fetch("/api/products/" + data.id + "/update", { + method: "post", + headers: { + "Content-Type": "application/json;charset=utf-8" + }, + body: JSON.stringify(data), + credentials: "include" + }); +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/products-api.types.ts b/src/wwwroot/scripts/api/products-api.types.ts new file mode 100644 index 0000000..f4fdd5e --- /dev/null +++ b/src/wwwroot/scripts/api/products-api.types.ts @@ -0,0 +1,35 @@ +import {Base} from "./db-base"; +import {Category} from "./categories-api.types"; + +export interface Product extends Base { + name: string, + description: string, + price: number, + priceSuffix: PriceSuffix, + visibilityState: ProductVisibility, + category: Category, + images: Array, + slug: string, + disabled: boolean, + deleted: boolean +} + +export interface CreateProductPayload extends Product { +} + +export interface Image { + order: number, + fileName: string +} + +export enum PriceSuffix { + Money = 0, + Kilos = 1, + Per = 2 +} + +export enum ProductVisibility { + Default = 0, + Disabled = 1, + Deleted = 2 +} \ No newline at end of file diff --git a/src/wwwroot/scripts/api/settings-api.ts b/src/wwwroot/scripts/api/settings-api.ts new file mode 100644 index 0000000..7f7e482 --- /dev/null +++ b/src/wwwroot/scripts/api/settings-api.ts @@ -0,0 +1,17 @@ +export function setOrderEmailList(payload: string[]): Promise { + return fetch("/api/settings/order-emails", { + headers: { + "Content-Type": "application/json;charset=utf-8" + }, + body: JSON.stringify(payload), + method: "post", + credentials: "include" + }); +} + +export function getOrderEmailList(): Promise { + return fetch("/api/settings/order-emails", { + method: "get", + credentials: "include" + }); +} diff --git a/src/wwwroot/scripts/api/settings-api.types.ts b/src/wwwroot/scripts/api/settings-api.types.ts new file mode 100644 index 0000000..fe9864a --- /dev/null +++ b/src/wwwroot/scripts/api/settings-api.types.ts @@ -0,0 +1,3 @@ +export interface SettingsApiTypes { + +} \ No newline at end of file -- cgit v1.3