Display free tickets in standing areas

This commit is contained in:
2024-10-23 13:36:21 +02:00
parent 1f0933e2a9
commit 3faa89a749
9 changed files with 81 additions and 3 deletions

View File

@@ -38,6 +38,7 @@ concert.get("/", (req: Request, res: Response) => {
})
// Get all available data about a band by it's ID
concert.get("/concert/:id", (req: Request, res: Response) => {
Concert.findByPk(req.params.id, {
include: [
@@ -79,14 +80,22 @@ concert.get("/concert/:id", (req: Request, res: Response) => {
}
})
.then(concert => {
concert.dataValues["capacity"] = 0
// Go through every seat group
for (let seatGroup of concert.dataValues.location.dataValues.seatGroups) {
seatGroup.dataValues["occupied"] = 0
// Go through every seat row
for (let seatRow of seatGroup.dataValues.seatRows) {
for (let seat of seatRow.dataValues.seats) {
seat.dataValues["state"] = 0
concert.dataValues["inStock"] += 1
// Go through every seat
for (let ticket of seat.dataValues.tickets) {
// Check if the seat is occupied through a ticket
// If yes, reduce number of available seats
if (ticket.dataValues.concertId == req.params.id) {
seat.dataValues["state"] = 1
seatGroup.dataValues["occupied"] += 1
@@ -109,19 +118,35 @@ concert.get("/search", (req: Request, res: Response) => {
Concert.findAll({
where: {
[Op.or]: [
// Search by name of concert
{
name: {
[Op.substring]: req.query.value
}
},
// Search by name of band
{
"$band.name$": {
[Op.substring]: req.query.value
}
},
// Search by name of city of location
{
"$location.city.name$": {
[Op.substring]: req.query.value
}
}
]
},
include: [ Band, Location ]
include: [
Band,
{
model: Location,
include: [ City ]
}
]
})
.then(concerts => {
res.status(200).json(concerts)

View File

@@ -4,6 +4,9 @@ import { Request, Response, Router } from "express";
export const exercises = Router()
/**
* Get all Exercises grouped in ExerciseGroups
*/
exercises.get("/", (req: Request, res: Response) => {
ExerciseGroup.findAll(
{
@@ -22,6 +25,13 @@ exercises.get("/", (req: Request, res: Response) => {
})
})
/**
* Update state of an Exercise
*
* @param groupNr Number of exercise group (not ID)
* @param exerciseNr Number of exercise (not ID)
* @param state New state boolean
*/
exercises.post("/:groupNr/:exerciseNr/:state", (req: Request, res: Response) => {
ExerciseGroup.findOne({
where: { groupNr: req.params.groupNr }

View File

@@ -5,6 +5,9 @@ import { Request, Response, Router } from "express";
export const genre = Router()
/**
* Get all available Genres
*/
genre.get("/", (req: Request, res: Response) => {
Genre.findAll()
.then(genres => {

View File

@@ -10,6 +10,12 @@ import { Op } from "sequelize";
export const location = Router()
/**
* Get all available Locations
*
* @query sort Sort results ascending (asc) or descending (desc)
* @query count Limit number of results
*/
location.get("/", (req: Request, res: Response) => {
let sort = req.query.sort
let count = req.query.count
@@ -52,6 +58,12 @@ location.get("/", (req: Request, res: Response) => {
})
})
/**
* Get all data about a specific location
*
* @param urlName UrlName of the band (e.g. Red Hot Chili Peppers => red-hot-chili-peppers)
*/
location.get("/location/:urlName", (req: Request, res: Response) => {
Location.findOne({
where: { urlName: req.params.urlName },
@@ -89,16 +101,23 @@ location.get("/location/:urlName", (req: Request, res: Response) => {
})
// Location search
/**
* Search for Locations
*
* @query value Search term to look for
*/
location.get("/search", (req: Request, res: Response) => {
Location.findAll({
where: {
[Op.or]: [
// Search by name of location
{
name: {
[Op.substring]: req.query.value
},
},
// Search by name of city
{
"$city.name$": {
[Op.substring]: req.query.value