From d622fda7a9173fe08f3b5a7a91ba381a95623387 Mon Sep 17 00:00:00 2001 From: Tobias Zoghaib Date: Thu, 28 Nov 2024 13:10:54 +0100 Subject: [PATCH] Finish order admin page with detail dialog and actions --- backend/routes/order.routes.ts | 34 +++++++++-- src/data/api/orderApi.ts | 20 ++++--- src/pages/admin/ordersAdminPage/index.vue | 20 ++++--- .../ordersAdminPage/orderDetailDialog.vue | 60 +++++++++++++++++-- src/stores/order.store.ts | 30 ++++++++-- 5 files changed, 133 insertions(+), 31 deletions(-) diff --git a/backend/routes/order.routes.ts b/backend/routes/order.routes.ts index 21d890c..7f3a086 100644 --- a/backend/routes/order.routes.ts +++ b/backend/routes/order.routes.ts @@ -10,17 +10,15 @@ import { City } from "../models/locations/city.model"; import { Seat } from "../models/locations/seat.model"; import { SeatRow } from "../models/locations/seatRow.model"; import { SeatGroup } from "../models/locations/seatGroup.model"; +import { verifyToken } from "../middlewares/auth.middleware"; import { Account } from "../models/user/account.model"; -import { Exercise } from "backend/models/exercises/exercise.model"; export const order = Router() // Get all orders -order.get("/", (req: Request, res: Response) => { +order.get("/", verifyToken, (req: Request, res: Response) => { Order.findAll({ include: [ - Account, - Address, { model: Ticket, include: [ @@ -35,9 +33,21 @@ order.get("/", (req: Request, res: Response) => { include: [ City ] } ] + }, + { + model: Seat, + include: [ + { + model: SeatRow, + include: [ SeatGroup ] + } + ] } ] - } + }, + Address, + Payment, + Account ] }) .then(orders => { @@ -125,4 +135,18 @@ order.post("/", (req: Request, res: Response) => { .catch(error => { res.status(500).send() }) +}) + +order.patch("/", (req: Request, res: Response) => { + Order.update(req.body, { + where: { + id: req.body.id + } + }) + .then(affectedCount => { + res.status(200).send() + }) + .catch(error => { + res.status(500).send() + }) }) \ No newline at end of file diff --git a/src/data/api/orderApi.ts b/src/data/api/orderApi.ts index b0f2226..505c660 100644 --- a/src/data/api/orderApi.ts +++ b/src/data/api/orderApi.ts @@ -1,5 +1,6 @@ import axios from "axios" import { BasketItemModel } from "../models/ordering/basketItemModel" +import { OrderApiModel } from "../models/apiEndpoints/orderApiModel" const BASE_URL = "http://localhost:3000/orders" @@ -25,13 +26,6 @@ export async function createOrder( } } - console.log({ - accountId: accountId, - tickets: tickets, - paymentId: paymentId, - addressId: addressId - }) - return axios.post(BASE_URL, { accountId: accountId, tickets: tickets, @@ -40,6 +34,14 @@ export async function createOrder( }) } -export async function fetchAllOrders() { - return axios.get(BASE_URL) +export async function fetchAllOrders(token: string) { + return axios.get(BASE_URL, { + headers: { + "Authorization": token + } + }) +} + +export async function patchOrder(order: OrderApiModel) { + return axios.patch(BASE_URL, order) } \ No newline at end of file diff --git a/src/pages/admin/ordersAdminPage/index.vue b/src/pages/admin/ordersAdminPage/index.vue index e3d96de..95484a9 100644 --- a/src/pages/admin/ordersAdminPage/index.vue +++ b/src/pages/admin/ordersAdminPage/index.vue @@ -13,7 +13,7 @@ const headers = [ { title: "Adresse", value: "street" }, { title: "Stadt", value: "city" }, { title: "Versendet", value: "shipped" }, - { title: "", value: "edit", width: 130 } + { title: "Aktionen", value: "edit", width: 130 } ] orderStore.getAllOrders() @@ -26,6 +26,8 @@ orderStore.getAllOrders()