Implement ordering process

This commit is contained in:
2024-09-24 15:40:16 +02:00
parent 22d3e8d177
commit 03ff8b402f
19 changed files with 274 additions and 160 deletions

View File

@@ -0,0 +1,12 @@
import axios from "axios"
const BASE_URL = "http://localhost:3000/api"
export function getServerState() {
return axios.get(BASE_URL)
}
export function resetDatabase() {
return axios.get(BASE_URL + "/resetdatabase")
}

View File

@@ -1,6 +1,7 @@
import axios from "axios"
import { OrderModel } from "../models/orderModel"
import { BasketItemModel } from "../models/basketItemModel"
import { calcPrice } from "@/scripts/productScripts"
const BASE_URL = "http://localhost:3000/orders"
@@ -9,8 +10,18 @@ export async function getUserOrders(userId: number) {
}
export async function addOrder(accountId: number, basketItems: Array<BasketItemModel>) {
let orderItems = []
for (let basketItem of basketItems) {
orderItems.push({
productId: basketItem.product.id,
quantity: basketItem.quantity,
orderPrice: calcPrice(basketItem.product.price, basketItem.product.discount)
})
}
return axios.post(BASE_URL, {
"accountId": accountId,
"orderItem": basketItems
accountId: accountId,
orderItems: orderItems
})
}