Display free tickets in standing areas
This commit is contained in:
@@ -33,6 +33,9 @@ export class Location extends Model {
|
|||||||
@Column
|
@Column
|
||||||
layout: number
|
layout: number
|
||||||
|
|
||||||
|
@Column
|
||||||
|
capacity: number
|
||||||
|
|
||||||
|
|
||||||
// Relations
|
// Relations
|
||||||
|
|
||||||
|
|||||||
@@ -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.get("/concert/:id", (req: Request, res: Response) => {
|
||||||
Concert.findByPk(req.params.id, {
|
Concert.findByPk(req.params.id, {
|
||||||
include: [
|
include: [
|
||||||
@@ -79,14 +80,22 @@ concert.get("/concert/:id", (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(concert => {
|
.then(concert => {
|
||||||
|
concert.dataValues["capacity"] = 0
|
||||||
|
|
||||||
|
// Go through every seat group
|
||||||
for (let seatGroup of concert.dataValues.location.dataValues.seatGroups) {
|
for (let seatGroup of concert.dataValues.location.dataValues.seatGroups) {
|
||||||
seatGroup.dataValues["occupied"] = 0
|
seatGroup.dataValues["occupied"] = 0
|
||||||
|
|
||||||
|
// Go through every seat row
|
||||||
for (let seatRow of seatGroup.dataValues.seatRows) {
|
for (let seatRow of seatGroup.dataValues.seatRows) {
|
||||||
for (let seat of seatRow.dataValues.seats) {
|
for (let seat of seatRow.dataValues.seats) {
|
||||||
seat.dataValues["state"] = 0
|
seat.dataValues["state"] = 0
|
||||||
|
concert.dataValues["inStock"] += 1
|
||||||
|
|
||||||
|
// Go through every seat
|
||||||
for (let ticket of seat.dataValues.tickets) {
|
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) {
|
if (ticket.dataValues.concertId == req.params.id) {
|
||||||
seat.dataValues["state"] = 1
|
seat.dataValues["state"] = 1
|
||||||
seatGroup.dataValues["occupied"] += 1
|
seatGroup.dataValues["occupied"] += 1
|
||||||
@@ -109,19 +118,35 @@ concert.get("/search", (req: Request, res: Response) => {
|
|||||||
Concert.findAll({
|
Concert.findAll({
|
||||||
where: {
|
where: {
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
|
// Search by name of concert
|
||||||
{
|
{
|
||||||
name: {
|
name: {
|
||||||
[Op.substring]: req.query.value
|
[Op.substring]: req.query.value
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Search by name of band
|
||||||
{
|
{
|
||||||
"$band.name$": {
|
"$band.name$": {
|
||||||
[Op.substring]: req.query.value
|
[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 => {
|
.then(concerts => {
|
||||||
res.status(200).json(concerts)
|
res.status(200).json(concerts)
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import { Request, Response, Router } from "express";
|
|||||||
|
|
||||||
export const exercises = Router()
|
export const exercises = Router()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all Exercises grouped in ExerciseGroups
|
||||||
|
*/
|
||||||
exercises.get("/", (req: Request, res: Response) => {
|
exercises.get("/", (req: Request, res: Response) => {
|
||||||
ExerciseGroup.findAll(
|
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) => {
|
exercises.post("/:groupNr/:exerciseNr/:state", (req: Request, res: Response) => {
|
||||||
ExerciseGroup.findOne({
|
ExerciseGroup.findOne({
|
||||||
where: { groupNr: req.params.groupNr }
|
where: { groupNr: req.params.groupNr }
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import { Request, Response, Router } from "express";
|
|||||||
|
|
||||||
export const genre = Router()
|
export const genre = Router()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all available Genres
|
||||||
|
*/
|
||||||
genre.get("/", (req: Request, res: Response) => {
|
genre.get("/", (req: Request, res: Response) => {
|
||||||
Genre.findAll()
|
Genre.findAll()
|
||||||
.then(genres => {
|
.then(genres => {
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ import { Op } from "sequelize";
|
|||||||
|
|
||||||
export const location = Router()
|
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) => {
|
location.get("/", (req: Request, res: Response) => {
|
||||||
let sort = req.query.sort
|
let sort = req.query.sort
|
||||||
let count = req.query.count
|
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.get("/location/:urlName", (req: Request, res: Response) => {
|
||||||
Location.findOne({
|
Location.findOne({
|
||||||
where: { urlName: req.params.urlName },
|
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.get("/search", (req: Request, res: Response) => {
|
||||||
Location.findAll({
|
Location.findAll({
|
||||||
where: {
|
where: {
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
|
// Search by name of location
|
||||||
{
|
{
|
||||||
name: {
|
name: {
|
||||||
[Op.substring]: req.query.value
|
[Op.substring]: req.query.value
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Search by name of city
|
||||||
{
|
{
|
||||||
"$city.name$": {
|
"$city.name$": {
|
||||||
[Op.substring]: req.query.value
|
[Op.substring]: req.query.value
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ export async function prepopulateDatabase() {
|
|||||||
|
|
||||||
await Location.create(location)
|
await Location.create(location)
|
||||||
.then(async locationDataset => {
|
.then(async locationDataset => {
|
||||||
|
let capacity = 0
|
||||||
|
|
||||||
for (let seatGroup of location.seatGroups)
|
for (let seatGroup of location.seatGroups)
|
||||||
{
|
{
|
||||||
seatGroup["locationId"] = locationDataset.id
|
seatGroup["locationId"] = locationDataset.id
|
||||||
@@ -131,6 +133,8 @@ export async function prepopulateDatabase() {
|
|||||||
seatNr: i + 1,
|
seatNr: i + 1,
|
||||||
seatRowId: seatRowRes.id
|
seatRowId: seatRowRes.id
|
||||||
})
|
})
|
||||||
|
|
||||||
|
capacity++
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -147,12 +151,24 @@ export async function prepopulateDatabase() {
|
|||||||
seatNr: col,
|
seatNr: col,
|
||||||
seatRowId: seatRowRes.id
|
seatRowId: seatRowRes.id
|
||||||
})
|
})
|
||||||
|
|
||||||
|
capacity++
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update capacity of location
|
||||||
|
await Location.update(
|
||||||
|
{ capacity: capacity },
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: locationDataset.dataValues.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ function handleSeatClick() {
|
|||||||
|
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col class="text-center text-h6">
|
<v-col class="text-center text-h6">
|
||||||
{{ seatGroup.capacity }} {{ $t('standingPlaces') }}
|
{{ seatGroup.capacity - seatGroup.occupied }} {{ $t('standingPlaces') }}
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-sheet>
|
</v-sheet>
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ export class LocationModel {
|
|||||||
address: string = ""
|
address: string = ""
|
||||||
imageIndoor: string = ""
|
imageIndoor: string = ""
|
||||||
imageOutdoor: string = ""
|
imageOutdoor: string = ""
|
||||||
|
capacity: number = 0
|
||||||
layout: number = 1
|
layout: number = 1
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,6 @@ export class SeatGroupModel {
|
|||||||
surcharge: number = 0
|
surcharge: number = 0
|
||||||
standingArea: boolean = false
|
standingArea: boolean = false
|
||||||
capacity: number = 0
|
capacity: number = 0
|
||||||
|
occupied: number = 0
|
||||||
seatRows: Array<SeatRowModel>
|
seatRows: Array<SeatRowModel>
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user