Remove EventTable in database, redesign frontend URL paths
This commit is contained in:
@@ -10,7 +10,6 @@ import { Genre } from '../models/acts/genre.model'
|
||||
import { Band } from '../models/acts/band.model'
|
||||
import { Location } from '../models/locations/location.model'
|
||||
import { Concert } from '../models/acts/concert.model'
|
||||
import { Event } from '../models/acts/event.model'
|
||||
import { City } from '../models/locations/city.model'
|
||||
import { BandGenre } from '../models/acts/bandGenre.model'
|
||||
import { SeatGroup } from '../models/locations/seatGroup.model'
|
||||
@@ -22,11 +21,9 @@ import { ExerciseGroup } from '../models/exercises/exerciseGroup.model'
|
||||
import accounts from "./../data/accounts.json"
|
||||
import orders from "./../data/orders.json"
|
||||
import accountRoles from "./../data/accountRoles.json"
|
||||
import bands from "./../data/bands.json"
|
||||
import genres from "./../data/genres.json"
|
||||
import events from "./../data/events.json"
|
||||
import citiesLocations from "./../data/cities-locations.json"
|
||||
import exercises from "./../data/exercises.json"
|
||||
import bands from "./../data/bands-concerts.json"
|
||||
|
||||
|
||||
/**
|
||||
@@ -40,7 +37,6 @@ export function deleteAllTables() {
|
||||
Member.destroy({ truncate: true })
|
||||
Genre.destroy({ truncate: true })
|
||||
Band.destroy({ truncate: true })
|
||||
Event.destroy({ truncate: true })
|
||||
|
||||
City.destroy({ truncate: true })
|
||||
Location.destroy({ truncate: true })
|
||||
@@ -80,7 +76,7 @@ export async function prepopulateDatabase() {
|
||||
deleteAllTables()
|
||||
|
||||
AccountRole.bulkCreate(accountRoles.data)
|
||||
Genre.bulkCreate(genres.data)
|
||||
//Genre.bulkCreate(genres.data)
|
||||
|
||||
for (let city of citiesLocations.data)
|
||||
{
|
||||
@@ -97,41 +93,42 @@ export async function prepopulateDatabase() {
|
||||
{
|
||||
seatGroup["locationId"] = locationDataset.id
|
||||
|
||||
await SeatGroup.create(seatGroup)
|
||||
.then(async seatGroupRes => {
|
||||
if (seatGroup.standingArea) {
|
||||
// In an area without seats, create one row with all "seats"
|
||||
await SeatRow.create({
|
||||
row: 0,
|
||||
seatGroupId: seatGroupRes.id
|
||||
})
|
||||
.then(async seatRowRes => {
|
||||
for (let i = 0; i < seatGroup.capacity; i++) {
|
||||
await Seat.create({
|
||||
seatNr: i + 1,
|
||||
seatRowId: seatRowRes.id
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
else
|
||||
{
|
||||
for (let row = 0; row < seatGroup.rows; row++) {
|
||||
await SeatRow.create({
|
||||
row: row + 1,
|
||||
seatGroupId: seatGroupRes.id
|
||||
})
|
||||
.then(async seatRowRes => {
|
||||
for (let col = 0; col < seatGroup.capacity / seatGroup.rows; col++) {
|
||||
await Seat.create({
|
||||
seatNr: col,
|
||||
seatRowId: seatRowRes.id
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
// todo activate
|
||||
// await SeatGroup.create(seatGroup)
|
||||
// .then(async seatGroupRes => {
|
||||
// if (seatGroup.standingArea) {
|
||||
// // In an area without seats, create one row with all "seats"
|
||||
// await SeatRow.create({
|
||||
// row: 0,
|
||||
// seatGroupId: seatGroupRes.id
|
||||
// })
|
||||
// .then(async seatRowRes => {
|
||||
// for (let i = 0; i < seatGroup.capacity; i++) {
|
||||
// await Seat.create({
|
||||
// seatNr: i + 1,
|
||||
// seatRowId: seatRowRes.id
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// for (let row = 0; row < seatGroup.rows; row++) {
|
||||
// await SeatRow.create({
|
||||
// row: row + 1,
|
||||
// seatGroupId: seatGroupRes.id
|
||||
// })
|
||||
// .then(async seatRowRes => {
|
||||
// for (let col = 0; col < seatGroup.capacity / seatGroup.rows; col++) {
|
||||
// await Seat.create({
|
||||
// seatNr: col,
|
||||
// seatRowId: seatRowRes.id
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -142,74 +139,129 @@ export async function prepopulateDatabase() {
|
||||
// Account & Sub tables
|
||||
for (let account of accounts.data) {
|
||||
await Account.create(account)
|
||||
.then(dataset => {
|
||||
Address.bulkCreate(account.addresses)
|
||||
Payment.bulkCreate(account.payments)
|
||||
.then(async dataset => {
|
||||
for (let address of account.addresses) {
|
||||
await Address.create({
|
||||
accountId: dataset.dataValues.id,
|
||||
street: address.street,
|
||||
houseNumber: address.houseNumber,
|
||||
postalCode: address.postalCode,
|
||||
city: address.city
|
||||
})
|
||||
}
|
||||
|
||||
for (let payment of account.payments) {
|
||||
await Payment.create({
|
||||
accountId: dataset.dataValues.id,
|
||||
bankName: payment.bankName,
|
||||
iban: payment.iban
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
for(let band of bands.data) {
|
||||
for(let band of bands.bands) {
|
||||
// Create a band dataset
|
||||
await Band.create(band)
|
||||
.then(async dataset => {
|
||||
// Create the m:n associations for the genres
|
||||
for (let genreId of band.genreId) {
|
||||
await BandGenre.create({
|
||||
genreId: Number(genreId),
|
||||
for (let genre of band.genres) {
|
||||
await Genre.findOrCreate({
|
||||
where: {
|
||||
name: genre
|
||||
},
|
||||
defaults: {
|
||||
name: genre
|
||||
}
|
||||
})
|
||||
.then(async genreDataset => {
|
||||
await BandGenre.create({
|
||||
genreId: genreDataset[0].dataValues.id,
|
||||
bandId: dataset.dataValues.id
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for (let rating of band.ratings) {
|
||||
await Account.findOne({
|
||||
where: {
|
||||
username: rating.username
|
||||
}
|
||||
})
|
||||
.then(async account => {
|
||||
await Rating.create({
|
||||
accountId: account.dataValues.id,
|
||||
rating: rating.rating,
|
||||
bandId: dataset.dataValues.id
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for (let member of band.members) {
|
||||
await Member.create({
|
||||
name: member.name,
|
||||
image: member.image,
|
||||
bandId: dataset.dataValues.id
|
||||
})
|
||||
}
|
||||
|
||||
Rating.bulkCreate(band.ratings)
|
||||
Member.bulkCreate(band.members)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
for (let event of events.data) {
|
||||
await Event.create(event)
|
||||
.then(async dataset => {
|
||||
for (let concert of event.concerts) {
|
||||
concert["eventId"] = dataset.id
|
||||
|
||||
await Concert.create(concert)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for (let order of orders.data) {
|
||||
await Order.create(order)
|
||||
.then(async dataset => {
|
||||
for (let ticket of order.tickets) {
|
||||
ticket["orderId"] = dataset.id
|
||||
|
||||
SeatGroup.findOne({
|
||||
where: {
|
||||
name: ticket.seatGroup
|
||||
}
|
||||
})
|
||||
.then(seatGroup => {
|
||||
SeatRow.findOne({
|
||||
where: {
|
||||
seatGroupId: seatGroup.id,
|
||||
row: ticket.seatRow
|
||||
}
|
||||
})
|
||||
.then(seatRow => {
|
||||
Seat.findOne({
|
||||
where: {
|
||||
seatRowId: seatRow.id,
|
||||
seatNr: ticket.seat
|
||||
}
|
||||
})
|
||||
.then(async seat => {
|
||||
ticket["seatId"] = seat.id
|
||||
await Ticket.create(ticket)
|
||||
})
|
||||
})
|
||||
for (let concertGroup of band.concertGroups) {
|
||||
for (let concert of concertGroup.concerts) {
|
||||
await Location.findOne({
|
||||
where: {
|
||||
name: concert.location
|
||||
}
|
||||
})
|
||||
.then(async location => {
|
||||
await Concert.create({
|
||||
date: concert.date,
|
||||
name: concertGroup.name,
|
||||
price: concert.price,
|
||||
image: concertGroup.name,
|
||||
inStock: concert.inStock,
|
||||
offered: true,
|
||||
bandId: dataset.dataValues.id,
|
||||
locationId: location.dataValues.id
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// for (let order of orders.data) {
|
||||
// await Order.create(order)
|
||||
// .then(async dataset => {
|
||||
// for (let ticket of order.tickets) {
|
||||
// ticket["orderId"] = dataset.id
|
||||
|
||||
// SeatGroup.findOne({
|
||||
// where: {
|
||||
// name: ticket.seatGroup
|
||||
// }
|
||||
// })
|
||||
// .then(seatGroup => {
|
||||
// SeatRow.findOne({
|
||||
// where: {
|
||||
// seatGroupId: seatGroup.id,
|
||||
// row: ticket.seatRow
|
||||
// }
|
||||
// })
|
||||
// .then(seatRow => {
|
||||
// Seat.findOne({
|
||||
// where: {
|
||||
// seatRowId: seatRow.id,
|
||||
// seatNr: ticket.seat
|
||||
// }
|
||||
// })
|
||||
// .then(async seat => {
|
||||
// ticket["seatId"] = seat.id
|
||||
// await Ticket.create(ticket)
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user