New page for all concerts

This commit is contained in:
2024-10-12 19:40:12 +02:00
parent f8bdb54c33
commit 6c33de3d87
56 changed files with 531 additions and 405 deletions

View File

@@ -7,44 +7,41 @@ import { Concert } from "../models/acts/concert.model";
import { Location } from "../models/locations/location.model";
import { City } from "../models/locations/city.model";
import { Op } from "sequelize";
import { calcOverallRating, calcRatingValues } from "../scripts/calcScripts";
export const band = Router()
// Get all bands
band.get("/", (req: Request, res: Response) => {
Band.findAll({
include: [
{
model: Member,
attributes: {
exclude: [ "id", "bandId" ]
}
},
include: [
{
model: Rating,
attributes: {
exclude: [ "id", "bandId" ]
}
},
{
model: Concert,
include: [
{
model: Location,
include: [ City ],
attributes: {
exclude: [ "id" ]
}
}
],
model: Genre,
attributes: {
exclude: [ "id", "tourId", "locationId" ]
exclude: [ "id" ]
}
},
Genre
Concert
]
})
.then(bands => {
for (let band of bands) {
band.dataValues["nrOfConcerts"] = band.dataValues.concerts.length
band.dataValues["rating"] = calcOverallRating(band.dataValues.ratings)
// Delete unnecessary Arrays
delete band.dataValues.ratings
delete band.dataValues.concerts
for (let genre of band.dataValues.genres) {
delete genre.dataValues.BandGenre
}
}
res.status(200).json(bands)
})
})
@@ -90,6 +87,16 @@ band.get("/band/:name", (req: Request, res: Response) => {
}
})
.then(band => {
band.dataValues["rating"] = calcOverallRating(band.dataValues.ratings)
band.dataValues["ratingValues"] = calcRatingValues(band.dataValues.ratings)
// Delete unnecessary Arrays
delete band.dataValues.ratings
for (let genre of band.dataValues.genres) {
delete genre.dataValues.BandGenre
}
res.status(200).json(band)
})
})

View File

@@ -1,26 +1,11 @@
import { Location } from "../models/locations/location.model";
import { City } from "../models/locations/city.model";
import { Request, Response, Router } from "express";
import { Concert } from "../models/acts/concert.model";
export const city = Router()
city.get("/", (req: Request, res: Response) => {
City.findAll({
include: [
{
model: Location,
include: [ Concert ]
}
]
})
City.findAll()
.then(cities => {
// for (let city of cities) {
// for (let location of city.dataValues.locations) {
// location.dataValues.nrOfConcerts = location.dataValues.concerts.length
// delete location.dataValues.concerts
// }
// }
res.status(200).json(cities)
})
})

View File

@@ -7,10 +7,23 @@ import { SeatRow } from "../models/locations/seatRow.model";
import { Seat } from "../models/locations/seat.model";
import { Ticket } from "../models/ordering/ticket.model";
import { Band } from "../models/acts/band.model";
import { Op } from "sequelize";
export const concert = Router()
concert.get("/", (req: Request, res: Response) => {
Concert.findAll({
include: [ Band, Location ],
order: [
[ 'date', 'ASC' ]
]
})
.then(concerts => {
res.status(200).json(concerts)
})
})
concert.get("/concert/:id", (req: Request, res: Response) => {
Concert.findByPk(req.params.id, {
include: [

View File

@@ -20,15 +20,6 @@ location.get("/", (req: Request, res: Response) => {
{
model: Concert,
include: [ Band ],
},
{
model: SeatGroup,
include: [
{
model: SeatRow,
include: [ Seat ]
}
]
}
],
attributes: {
@@ -46,6 +37,12 @@ location.get("/", (req: Request, res: Response) => {
})
}
for (let location of locations) {
location.dataValues["nrOfConcerts"] = location.dataValues.concerts.length
delete location.dataValues.concerts
}
// Limit number of items
if (count != undefined) {
locations.splice(Number(count))
}
@@ -86,7 +83,6 @@ location.get("/location/:urlName", (req: Request, res: Response) => {
}
}
res.status(200).json(location)
})
})