Implement ordering process
This commit is contained in:
12
software/src/data/api/mainApi.ts
Normal file
12
software/src/data/api/mainApi.ts
Normal 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")
|
||||
}
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user