aboutsummaryrefslogtreecommitdiffstats
path: root/src/wwwroot/scripts/api
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-06-01 21:13:43 +0200
committerivarlovlie <git@ivarlovlie.no>2022-06-01 21:13:43 +0200
commit9383a2fb09ffb60cfe63683106945bd688affa59 (patch)
tree65b3f4b48841583e355887db5de5a16e7005fc87 /src/wwwroot/scripts/api
downloadvinjesvingenhandel.no-9383a2fb09ffb60cfe63683106945bd688affa59.tar.xz
vinjesvingenhandel.no-9383a2fb09ffb60cfe63683106945bd688affa59.zip
feat: Initial commit after clean slate
Diffstat (limited to 'src/wwwroot/scripts/api')
-rw-r--r--src/wwwroot/scripts/api/account-api.ts28
-rw-r--r--src/wwwroot/scripts/api/account-api.types.ts5
-rw-r--r--src/wwwroot/scripts/api/categories-api.ts33
-rw-r--r--src/wwwroot/scripts/api/categories-api.types.ts17
-rw-r--r--src/wwwroot/scripts/api/db-base.ts3
-rw-r--r--src/wwwroot/scripts/api/documents-api.ts24
-rw-r--r--src/wwwroot/scripts/api/order-api.ts64
-rw-r--r--src/wwwroot/scripts/api/order-api.types.ts39
-rw-r--r--src/wwwroot/scripts/api/products-api.ts59
-rw-r--r--src/wwwroot/scripts/api/products-api.types.ts35
-rw-r--r--src/wwwroot/scripts/api/settings-api.ts17
-rw-r--r--src/wwwroot/scripts/api/settings-api.types.ts3
12 files changed, 327 insertions, 0 deletions
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<Response> {
+ 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<Response> {
+ return fetch("/api/account/logout");
+}
+
+export function updatePassword(newPassword: string): Promise<Response> {
+ 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<Response> {
+ return fetch(withProducts ? "/api/categories/with-products" : "/api/categories");
+}
+
+export function getCategory(categoryId: string): Promise<Response> {
+ return fetch("/api/categories/" + categoryId);
+}
+
+export function createCategory(name: string, disabled: boolean): Promise<Response> {
+ return fetch("/api/categories/create?" + new URLSearchParams({
+ name
+ }));
+}
+
+export function updateCategory(categoryId: string, newName: string): Promise<Response> {
+ return fetch("/api/categories/" + categoryId + "/update?" + new URLSearchParams({
+ newName
+ }));
+}
+
+export function deleteCategory(categoryId: string): Promise<Response> {
+ return fetch("/api/categories/" + categoryId + "/delete", {
+ method: "delete"
+ });
+}
+
+export function enableCategory(categoryId: string): Promise<Response> {
+ return fetch("/api/categories/" + categoryId + "/enable");
+}
+
+export function disableCategory(categoryId: string): Promise<Response> {
+ 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<Product>
+}
+
+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<File>): Promise<Response> {
+ 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<Response> {
+ 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<Response> {
+ 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<Response> {
+ return fetch("/api/orders/" + id + "/details", {
+ credentials: "include"
+ });
+}
+
+export function captureVippsOrder(id: String): Promise<Response> {
+ return fetch("/api/orders/" + id + "/capture")
+}
+
+export function cancelOrder(id: String): Promise<Response> {
+ return fetch("/api/orders/" + id + "/cancel")
+}
+
+export function refundOrder(id: String): Promise<Response> {
+ return fetch("/api/orders/" + id + "/refund")
+}
+
+export function submitOrder(payload: SubmitOrderPayload): Promise<Response> {
+ 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<Response> {
+ return fetch("/api/orders?filter=" + filter, {
+ credentials: "include"
+ });
+}
+
+export function getOrder(id): Promise<Response> {
+ 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<ProductValidationDto>
+}
+
+export interface Order extends Base {
+ comment: string,
+ paymentType: OrderPaymentType,
+ status: OrderStatus,
+ ContactInfo: ContactInformation,
+ ProductIds: Array<string>
+}
+
+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<Response> {
+ 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<Response> {
+ return fetch("/api/products/" + id, {
+ method: "get",
+ credentials: "include"
+ });
+}
+
+export function getProducts(): Promise<Response> {
+ return fetch("/api/products", {
+ method: "get",
+ credentials: "include"
+ });
+}
+
+export function uploadProductImages(files: Array<File>): Promise<Response> {
+ 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<Response> {
+ return fetch("/api/products/" + id + "/delete", {
+ method: "delete",
+ credentials: "include"
+ });
+}
+
+export function updateProduct(data: Product): Promise<Response> {
+ 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<Image>,
+ 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<Response> {
+ 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<Response> {
+ 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