Simplified json import

This commit is contained in:
2024-10-12 16:22:14 +02:00
parent 60e217db03
commit 3204e4a658
7 changed files with 136 additions and 111 deletions

View File

@@ -8,8 +8,6 @@
"lastName": "Hagemeister",
"addresses": [
{
"id": 0,
"accountId": 0,
"street": "Laportestraße",
"houseNumber": 22,
"postalCode": 30449,
@@ -18,8 +16,6 @@
],
"payments": [
{
"id": 0,
"accountId": 0,
"bankName": "Deutsche Bank",
"iban": "DE92500105175721645777"
}
@@ -34,8 +30,6 @@
"lastName": "Stoiber",
"addresses": [
{
"id": 1,
"accountId": 1,
"street": "Gustav-Adolf-Straße",
"houseNumber": 30,
"postalCode": 30167,
@@ -44,8 +38,6 @@
],
"payments": [
{
"id": 1,
"accountId": 1,
"bankName": "DZ Bank",
"iban": "DE12500105179557939114"
}

View File

@@ -1,5 +1,5 @@
{
"data": [
"cities": [
{
"name": "Hannover",
"country": "Germany",

View File

@@ -1,5 +1,5 @@
{
"data": [
"groups": [
{
"nameDe": "Den Shop kennenlernen",
"nameEn": "Getting to know the shop",

View File

@@ -1,13 +1,11 @@
{
"data": [
"orders": [
{
"username": "hagemeister93",
"shippingProgress": 4,
"addressId": 0,
"paymentId": 0,
"tickets": [
{
"concertId": 0,
"date": "2024-10-18",
"concertGroupName": "Unlimited Love",
"orderPrice": 184,
"seatGroup": "A",
"seatRow": 0,
@@ -17,19 +15,18 @@
},
{
"username": "duranduran",
"shippingProgress": 5,
"addressId": 4,
"paymentId": 3,
"tickets": [
{
"concertId": 0,
"date": "2024-10-18",
"concertGroupName": "Unlimited Love",
"orderPrice": 184,
"seatGroup": "A",
"seatRow": 0,
"seat": 2
},
{
"concertId": 0,
"date": "2024-10-18",
"concertGroupName": "Unlimited Love",
"orderPrice": 184,
"seatGroup": "A",
"seatRow": 0,
@@ -39,12 +36,10 @@
},
{
"username": "duranduran",
"shippingProgress": 2,
"addressId": 5,
"paymentId": 3,
"tickets": [
{
"concertId": 0,
"date": "2024-10-18",
"concertGroupName": "Unlimited Love",
"orderPrice": 184,
"seatGroup": "A",
"seatRow": 0,

View File

@@ -16,10 +16,6 @@ export class Order extends Model {
@Column
orderedAt: Date
@Default(1)
@Column
shippingProgress: number
@ForeignKey(() => Address)
@Column
addressId: number

View File

@@ -23,7 +23,8 @@ import orders from "./../data/orders.json"
import accountRoles from "./../data/accountRoles.json"
import citiesLocations from "./../data/cities-locations.json"
import exercises from "./../data/exercises.json"
import bands from "./../data/bands-concerts.json"
import bandsConcerts from "./../data/bands-concerts.json"
import { Op } from 'sequelize'
/**
@@ -57,7 +58,7 @@ export function deleteExerciseProgressTables() {
}
export async function prepopulateExerciseDatabase() {
for (let exerciseGroup of exercises.data) {
for (let exerciseGroup of exercises.groups) {
ExerciseGroup.create(exerciseGroup)
.then(async dataset => {
for (let exercise of exerciseGroup.exercises) {
@@ -75,10 +76,11 @@ export async function prepopulateExerciseDatabase() {
export async function prepopulateDatabase() {
deleteAllTables()
AccountRole.bulkCreate(accountRoles.data)
//Genre.bulkCreate(genres.data)
for (let city of citiesLocations.data)
////////// Locations and Seat Tables //////////
for (let city of citiesLocations.cities)
{
await City.create(city)
.then(async cityDataset => {
@@ -93,42 +95,41 @@ export async function prepopulateDatabase() {
{
seatGroup["locationId"] = locationDataset.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
// })
// }
// })
// }
// }
// })
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
})
}
})
}
}
})
}
})
}
@@ -136,7 +137,11 @@ export async function prepopulateDatabase() {
}
// Account & Sub tables
////////// Account Tables //////////
AccountRole.bulkCreate(accountRoles.data)
for (let account of accounts.data) {
await Account.create(account)
.then(async dataset => {
@@ -161,7 +166,10 @@ export async function prepopulateDatabase() {
}
for(let band of bands.bands) {
////////// Band and Concert Tables //////////
for(let band of bandsConcerts.bands) {
// Create a band dataset
await Band.create(band)
.then(async dataset => {
@@ -230,38 +238,75 @@ export async function prepopulateDatabase() {
})
}
// 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)
// })
// })
// })
// }
// })
// }
////////// Order and Ticket Tables //////////
for (let order of orders.orders) {
let account = await Account.findOne({
where: {
username: order.username
}
})
let payment = await Payment.findOne({
where: {
accountId: account.dataValues.id
}
})
let address = await Address.findOne({
where: {
accountId: account.dataValues.id
}
})
await Order.create({
accountId: account.dataValues.id,
paymentId: payment.dataValues.id,
addressId: address.dataValues.id
})
.then(async dataset => {
for (let ticket of order.tickets) {
let concert = await Concert.findOne({
where: {
[Op.and] : [
{ name: ticket.concertGroupName },
{ date: ticket.date }
]
}
})
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 => {
await Ticket.create({
orderId: dataset.dataValues.id,
concertId: concert.dataValues.id,
orderPrice: ticket.orderPrice,
seatId: seat.dataValues.id
})
})
})
})
}
})
}
}