New page for all concerts
This commit is contained in:
@@ -43,7 +43,7 @@ export const sequelize = new Sequelize({
|
||||
})
|
||||
|
||||
export function startDatabase() {
|
||||
let recreateDb = true
|
||||
let recreateDb = false
|
||||
|
||||
// Create database and tables
|
||||
sequelize.sync({ force: recreateDb })
|
||||
|
||||
@@ -8,16 +8,16 @@ import { Concert } from "./concert.model";
|
||||
@Table({ timestamps: false })
|
||||
export class Band extends Model {
|
||||
@Column
|
||||
name: String
|
||||
name: string
|
||||
|
||||
@Column
|
||||
foundingYear: Number
|
||||
foundingYear: number
|
||||
|
||||
@Column
|
||||
descriptionEn: String
|
||||
descriptionEn: string
|
||||
|
||||
@Column
|
||||
descriptionDe: String
|
||||
descriptionDe: string
|
||||
|
||||
@Column({
|
||||
type: DataType.STRING,
|
||||
@@ -28,13 +28,13 @@ export class Band extends Model {
|
||||
this.setDataValue('images', value.join(';'))
|
||||
}
|
||||
})
|
||||
images: Array<String>
|
||||
images: Array<string>
|
||||
|
||||
@Column
|
||||
imageMembers: String
|
||||
imageMembers: string
|
||||
|
||||
@Column
|
||||
logo: String
|
||||
logo: string
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -6,34 +6,37 @@ import { Band } from "./band.model";
|
||||
@Table({ timestamps: false })
|
||||
export class Concert extends Model {
|
||||
@Column
|
||||
date: String
|
||||
date: string
|
||||
|
||||
@Column
|
||||
name: String
|
||||
name: string
|
||||
|
||||
@Column
|
||||
price: Number
|
||||
price: number
|
||||
|
||||
@Column
|
||||
image: String
|
||||
image: string
|
||||
|
||||
@Column
|
||||
inStock: Number
|
||||
inStock: number
|
||||
|
||||
@Column
|
||||
offered: Boolean
|
||||
offered: boolean
|
||||
|
||||
@ForeignKey(() => Band)
|
||||
@Column
|
||||
bandId: Number
|
||||
bandId: number
|
||||
|
||||
@ForeignKey(() => Location)
|
||||
@Column
|
||||
locationId: Number
|
||||
locationId: number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@BelongsTo(() => Band)
|
||||
band: Band
|
||||
|
||||
@BelongsTo(() => Location)
|
||||
location: Location
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { BandGenre } from "./bandGenre.model";
|
||||
@Table({ timestamps: false })
|
||||
export class Genre extends Model {
|
||||
@Column
|
||||
name: String
|
||||
name: string
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -4,14 +4,14 @@ import { Band } from "./band.model";
|
||||
@Table({ timestamps: false })
|
||||
export class Member extends Model {
|
||||
@Column
|
||||
name: String
|
||||
name: string
|
||||
|
||||
@ForeignKey(() => Band)
|
||||
@Column
|
||||
bandId: Number
|
||||
bandId: number
|
||||
|
||||
@Column
|
||||
image: String
|
||||
image: string
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -7,14 +7,14 @@ export class Rating extends Model {
|
||||
|
||||
@ForeignKey(() => Account)
|
||||
@Column
|
||||
accountId: Number
|
||||
accountId: number
|
||||
|
||||
@Column
|
||||
rating: Number
|
||||
rating: number
|
||||
|
||||
@ForeignKey(() => Band)
|
||||
@Column
|
||||
bandId: Number
|
||||
bandId: number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -4,26 +4,26 @@ import { ExerciseGroup } from "./exerciseGroup.model";
|
||||
@Table({ timestamps: false })
|
||||
export class Exercise extends Model {
|
||||
@Column
|
||||
nameDe: String
|
||||
nameDe: string
|
||||
|
||||
@Column
|
||||
nameEn: String
|
||||
nameEn: string
|
||||
|
||||
@Column
|
||||
exerciseNr: Number
|
||||
exerciseNr: number
|
||||
|
||||
@Column
|
||||
descriptionDe: String
|
||||
descriptionDe: string
|
||||
|
||||
@Column
|
||||
descriptionEn: String
|
||||
descriptionEn: string
|
||||
|
||||
@Column
|
||||
solved: Boolean
|
||||
solved: boolean
|
||||
|
||||
@ForeignKey(() => ExerciseGroup)
|
||||
@Column
|
||||
exerciseGroupId: Number
|
||||
exerciseGroupId: number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -4,13 +4,13 @@ import { Exercise } from "./exercise.model";
|
||||
@Table({ timestamps: false })
|
||||
export class ExerciseGroup extends Model {
|
||||
@Column
|
||||
nameDe: String
|
||||
nameDe: string
|
||||
|
||||
@Column
|
||||
nameEn: String
|
||||
nameEn: string
|
||||
|
||||
@Column
|
||||
groupNr: Number
|
||||
groupNr: number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -4,10 +4,10 @@ import { Location } from "./location.model";
|
||||
@Table({ timestamps: false })
|
||||
export class City extends Model {
|
||||
@Column
|
||||
name: String
|
||||
name: string
|
||||
|
||||
@Column
|
||||
country: String
|
||||
country: string
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -9,20 +9,20 @@ export class Location extends Model {
|
||||
urlName: string
|
||||
|
||||
@Column
|
||||
name: String
|
||||
name: string
|
||||
|
||||
@Column
|
||||
address: String
|
||||
address: string
|
||||
|
||||
@ForeignKey(() => City)
|
||||
@Column
|
||||
cityId: Number
|
||||
cityId: number
|
||||
|
||||
@Column
|
||||
imageIndoor: String
|
||||
imageIndoor: string
|
||||
|
||||
@Column
|
||||
imageOutdoor: String
|
||||
imageOutdoor: string
|
||||
|
||||
/**
|
||||
* Layout identifier of the location
|
||||
@@ -31,7 +31,7 @@ export class Location extends Model {
|
||||
* 3 = Stage in the middle of the stay area, seat places all around
|
||||
*/
|
||||
@Column
|
||||
layout: Number
|
||||
layout: number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -9,7 +9,7 @@ export class Seat extends Model {
|
||||
|
||||
@ForeignKey(() => SeatRow)
|
||||
@Column
|
||||
seatRowId: Number
|
||||
seatRowId: number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -5,21 +5,21 @@ import { SeatRow } from "./seatRow.model";
|
||||
@Table({ timestamps: false })
|
||||
export class SeatGroup extends Model {
|
||||
@Column
|
||||
name: String
|
||||
name: string
|
||||
|
||||
@Column
|
||||
surcharge: Number
|
||||
surcharge: number
|
||||
|
||||
@Column
|
||||
capacity: Number
|
||||
capacity: number
|
||||
|
||||
@Default(false)
|
||||
@Column
|
||||
standingArea: Boolean
|
||||
standingArea: boolean
|
||||
|
||||
@ForeignKey(() => Location)
|
||||
@Column
|
||||
locationId: Number
|
||||
locationId: number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
@@ -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: [
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
41
software/backend/scripts/calcScripts.ts
Normal file
41
software/backend/scripts/calcScripts.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Rating } from "../models/acts/rating.model";
|
||||
|
||||
/**
|
||||
* Calculate the average of an Array of ratings
|
||||
*
|
||||
* @param ratings Array of ratings
|
||||
*
|
||||
* @returns Average rating as number
|
||||
*/
|
||||
export function calcOverallRating(ratings: Array<Rating>): number {
|
||||
let sum = 0
|
||||
|
||||
for (let rating of ratings) {
|
||||
sum += rating.dataValues.rating
|
||||
}
|
||||
|
||||
return sum / ratings.length
|
||||
}
|
||||
|
||||
/**
|
||||
* Classifies a bunch of ratings to groups from 1 to 5 stars
|
||||
*
|
||||
* @param ratings Array of RatingModels
|
||||
*
|
||||
* @returns Array of Objects: { value: number[1-5], count: number }
|
||||
*/
|
||||
export function calcRatingValues(ratings: Array<Rating>) {
|
||||
let ratingValues = [
|
||||
{ value: 1, count: 0 },
|
||||
{ value: 2, count: 0 },
|
||||
{ value: 3, count: 0 },
|
||||
{ value: 4, count: 0 },
|
||||
{ value: 5, count: 0 }
|
||||
]
|
||||
|
||||
for (let rating of ratings) {
|
||||
ratingValues[rating.dataValues.rating - 1].count += 1
|
||||
}
|
||||
|
||||
return ratingValues
|
||||
}
|
||||
@@ -29,9 +29,9 @@ const path = require('path')
|
||||
app.use('/static', express.static(path.join(__dirname, 'images')))
|
||||
|
||||
// Add delay for more realistic response times
|
||||
app.use((req, res, next) => {
|
||||
setTimeout(next, Math.floor((Math.random () * 2000) + 100))
|
||||
})
|
||||
// app.use((req, res, next) => {
|
||||
// setTimeout(next, Math.floor((Math.random () * 2000) + 100))
|
||||
// })
|
||||
|
||||
// Routes
|
||||
app.use("/api", api)
|
||||
|
||||
Reference in New Issue
Block a user