SeatSelection page

This commit is contained in:
2024-10-04 20:15:16 +02:00
parent 519fa210e9
commit a676ce3d86
22 changed files with 316 additions and 76 deletions

View File

@@ -9,7 +9,8 @@
"tickets": [
{
"concertId": 0,
"orderPrice": 184
"orderPrice": 184,
"seatId": 43
}
]
},

View File

@@ -1,5 +1,6 @@
import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript";
import { BelongsTo, Column, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
import { SeatRow } from "./seatRow.model";
import { Ticket } from "../ordering/ticket.model";
@Table({ timestamps: false })
export class Seat extends Model {
@@ -15,4 +16,7 @@ export class Seat extends Model {
@BelongsTo(() => SeatRow)
seatRow: SeatRow
@HasMany(() => Ticket)
tickets: Ticket[]
}

View File

@@ -92,12 +92,12 @@ band.get("/:name", (req: Request, res: Response) => {
}
],
attributes: {
exclude: [ "id", "tourId", "locationId" ]
exclude: [ "tourId", "locationId" ]
}
}
],
attributes: {
exclude: [ "id", "bandId" ]
exclude: [ "bandId" ]
}
},
Genre

View File

@@ -3,6 +3,10 @@ import { Concert } from "../models/acts/concert.model";
import { Request, Response, Router } from "express";
import { Event } from "../models/acts/event.model";
import { City } from "../models/locations/city.model";
import { SeatGroup } from "../models/locations/seatGroup.model";
import { SeatRow } from "../models/locations/seatRow.model";
import { Seat } from "../models/locations/seat.model";
import { Ticket } from "../models/ordering/ticket.model";
export const concert = Router()
@@ -12,7 +16,29 @@ concert.get("/:id", (req: Request, res: Response) => {
Event,
{
model: Location,
include: [ City ],
include: [
{
model: City
},
{
model: SeatGroup,
include: [
{
model: SeatRow,
include: [
{
model: Seat,
include: [
{
model: Ticket
}
]
}
]
}
]
}
],
attributes: {
exclude: [ "cityId" ]
}
@@ -22,7 +48,27 @@ concert.get("/:id", (req: Request, res: Response) => {
exclude: [ "locationId", "tourId" ]
}
})
.then(shows => {
res.status(200).json(shows)
.then(concert => {
for (let seatGroup of concert.dataValues.location.dataValues.seatGroups) {
seatGroup.dataValues["occupied"] = 0
for (let seatRow of seatGroup.dataValues.seatRows) {
for (let seat of seatRow.dataValues.seats) {
seat.dataValues["state"] = 0
for (let ticket of seat.dataValues.tickets) {
if (ticket.dataValues.concertId == req.params.id) {
seat.dataValues["state"] = 1
seatGroup.dataValues["occupied"] += 1
break
}
}
delete seat.dataValues.tickets
}
}
}
res.status(200).json(concert)
})
})
})

View File

@@ -42,6 +42,7 @@ app.use("/genres", genre)
app.use("/orders", order)
app.use("/accounts", account)
app.use("/cities", city)
app.use("/concerts", concert)
// Start server