More skelton loader, add optional parameters to /locations and /events
@@ -5,7 +5,7 @@
|
||||
"name": "Unlimited Love",
|
||||
"bandId": 0,
|
||||
"offered": true,
|
||||
"image": "unlimited-love-tour.jpg",
|
||||
"image": "events/unlimited-love-tour.jpg",
|
||||
"concerts": [
|
||||
{
|
||||
"id": 0,
|
||||
@@ -49,7 +49,7 @@
|
||||
"name": "The Bends",
|
||||
"bandId": 1,
|
||||
"offered": true,
|
||||
"image": "the-bends-tour.jpg",
|
||||
"image": "events/the-bends-tour.jpg",
|
||||
"concerts": [
|
||||
{
|
||||
"id": 5,
|
||||
@@ -79,7 +79,7 @@
|
||||
"name": "European Tour",
|
||||
"bandId": 2,
|
||||
"offered": true,
|
||||
"image": "european-tour-arctic-monkeys.jpg",
|
||||
"image": "events/european-tour-arctic-monkeys.jpg",
|
||||
"concerts": [
|
||||
{
|
||||
"id": 8,
|
||||
@@ -102,7 +102,7 @@
|
||||
"name": "Music of the Spheres",
|
||||
"bandId": 3,
|
||||
"offered": true,
|
||||
"image": "music-of-the-spheres.png",
|
||||
"image": "events/music-of-the-spheres.png",
|
||||
"concerts": [
|
||||
{
|
||||
"id": 10,
|
||||
@@ -132,7 +132,7 @@
|
||||
"name": "But Here We Are Tour",
|
||||
"bandId": 4,
|
||||
"offered": true,
|
||||
"image": "but-here-we-are.jpg",
|
||||
"image": "events/but-here-we-are.jpg",
|
||||
"concerts": [
|
||||
{
|
||||
"id": 13,
|
||||
@@ -148,7 +148,7 @@
|
||||
"name": "Crisis of Faith",
|
||||
"bandId": 5,
|
||||
"offered": true,
|
||||
"image": "crisis-of-faith-tour.jpg",
|
||||
"image": "events/crisis-of-faith-tour.jpg",
|
||||
"concerts": [
|
||||
{
|
||||
"id": 14,
|
||||
@@ -171,7 +171,7 @@
|
||||
"name": "Back to the Water Below",
|
||||
"bandId": 6,
|
||||
"offered": true,
|
||||
"image": "back-to-the-water-below.jpg",
|
||||
"image": "events/back-to-the-water-below.jpg",
|
||||
"concerts": [
|
||||
{
|
||||
"id": 16,
|
||||
@@ -194,7 +194,7 @@
|
||||
"name": "Will of the People Tour",
|
||||
"bandId": 7,
|
||||
"offered": true,
|
||||
"image": "will-of-the-people-tour.jpg",
|
||||
"image": "events/will-of-the-people-tour.jpg",
|
||||
"concerts": [
|
||||
{
|
||||
"id": 18,
|
||||
|
||||
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 336 KiB After Width: | Height: | Size: 336 KiB |
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 208 KiB |
|
Before Width: | Height: | Size: 150 KiB After Width: | Height: | Size: 150 KiB |
|
Before Width: | Height: | Size: 492 KiB After Width: | Height: | Size: 492 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 113 KiB After Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 250 KiB After Width: | Height: | Size: 250 KiB |
@@ -11,6 +11,8 @@ export const events = Router()
|
||||
events.get("/", async (req: Request, res: Response) => {
|
||||
let cityName = req.query.city
|
||||
let genreName = req.query.genre
|
||||
let sort = req.query.sort
|
||||
let count = req.query.count
|
||||
let cityFilter = {}
|
||||
let genreFilter = {}
|
||||
|
||||
@@ -44,14 +46,16 @@ events.get("/", async (req: Request, res: Response) => {
|
||||
include: [
|
||||
{
|
||||
model: Location,
|
||||
required: true,
|
||||
include: [
|
||||
cityFilter
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
model: Band,
|
||||
required: true,
|
||||
include: [
|
||||
genreFilter
|
||||
]
|
||||
@@ -59,21 +63,21 @@ events.get("/", async (req: Request, res: Response) => {
|
||||
]
|
||||
})
|
||||
.then(events => {
|
||||
let resultArray = []
|
||||
|
||||
// Remove datasets which not fulfill the optional parameter
|
||||
for (let event of events) {
|
||||
if (event.dataValues.band != null) {
|
||||
for (let concert of event.dataValues.concerts) {
|
||||
if (concert.dataValues.location != null) {
|
||||
resultArray.push(event)
|
||||
break
|
||||
}
|
||||
if (sort != undefined) {
|
||||
events.sort((event1, event2) => {
|
||||
if (sort == "desc") {
|
||||
return event2.dataValues.concerts.length - event1.dataValues.concerts.length
|
||||
} else if (sort == "asc") {
|
||||
return event1.dataValues.concerts.length - event2.dataValues.concerts.length
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
res.status(200).json(resultArray)
|
||||
if (count != undefined) {
|
||||
events.splice(Number(count))
|
||||
}
|
||||
|
||||
res.status(200).json(events)
|
||||
})
|
||||
|
||||
})
|
||||
@@ -12,6 +12,9 @@ import { Op } from "sequelize";
|
||||
export const location = Router()
|
||||
|
||||
location.get("/", (req: Request, res: Response) => {
|
||||
let sort = req.query.sort
|
||||
let count = req.query.count
|
||||
|
||||
Location.findAll({
|
||||
include: [
|
||||
City,
|
||||
@@ -49,13 +52,25 @@ location.get("/", (req: Request, res: Response) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (sort != undefined) {
|
||||
locations.sort((location1, location2) => {
|
||||
if (sort == "desc") {
|
||||
return location2.dataValues.concerts.length - location1.dataValues.concerts.length
|
||||
} else if (sort == "asc") {
|
||||
return location1.dataValues.concerts.length - location2.dataValues.concerts.length
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (count != undefined) {
|
||||
locations.splice(Number(count))
|
||||
}
|
||||
|
||||
res.status(200).json(locations)
|
||||
})
|
||||
})
|
||||
|
||||
location.get("/:name", (req: Request, res: Response) => {
|
||||
console.log(req.params.name)
|
||||
|
||||
Location.findOne({
|
||||
where: { name: { [Op.like]: req.params.name } },
|
||||
include: [
|
||||
|
||||