Simplified json import

This commit is contained in:
2024-10-12 16:22:14 +02:00
parent 203f8428a7
commit f8bdb54c33
7 changed files with 136 additions and 111 deletions

View File

@@ -1,6 +1,6 @@
<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.7.17 Chrome/128.0.6613.36 Electron/32.0.1 Safari/537.36" version="24.7.17">
<diagram name="Page-1" id="WevClHWmhzPAQ7FDN5po">
<mxGraphModel dx="4871" dy="2547" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<mxGraphModel dx="3437" dy="1720" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
@@ -270,9 +270,6 @@
<mxCell id="EQeajuEG8KHzwlrw_xps-89" value="&lt;blockquote style=&quot;margin: 0px 0px 0px 8px; border: none; padding: 0px;&quot;&gt;&lt;i&gt;orderId:&amp;nbsp;&lt;/i&gt;&lt;i style=&quot;background-color: initial;&quot;&gt;Number&lt;/i&gt;&lt;/blockquote&gt;" style="rounded=0;whiteSpace=wrap;html=1;align=left;" parent="1" vertex="1">
<mxGeometry x="-837.42" y="130" width="160" height="30" as="geometry" />
</mxCell>
<mxCell id="EQeajuEG8KHzwlrw_xps-91" value="&lt;blockquote style=&quot;margin: 0px 0px 0px 8px; border: none; padding: 0px;&quot;&gt;shippingProgress: Number&lt;/blockquote&gt;" style="rounded=0;whiteSpace=wrap;html=1;align=left;" parent="1" vertex="1">
<mxGeometry x="-1078.1399999999999" y="190" width="160" height="30" as="geometry" />
</mxCell>
<mxCell id="EQeajuEG8KHzwlrw_xps-92" value="" style="sketch=0;pointerEvents=1;shadow=0;dashed=0;html=1;strokeColor=none;labelPosition=center;verticalLabelPosition=bottom;verticalAlign=top;outlineConnect=0;align=center;shape=mxgraph.office.security.key_permissions;fillColor=#2072B8;" parent="1" vertex="1">
<mxGeometry x="-1640.1999999999998" y="105" width="9.43" height="20" as="geometry" />
</mxCell>
@@ -451,10 +448,10 @@
</mxGeometry>
</mxCell>
<mxCell id="EQeajuEG8KHzwlrw_xps-139" value="&lt;blockquote style=&quot;margin: 0px 0px 0px 8px; border: none; padding: 0px;&quot;&gt;paymentId: Number&lt;/blockquote&gt;" style="rounded=0;whiteSpace=wrap;html=1;align=left;" parent="1" vertex="1">
<mxGeometry x="-1078.1399999999999" y="220" width="160" height="30" as="geometry" />
<mxGeometry x="-1078.1399999999999" y="190" width="160" height="30" as="geometry" />
</mxCell>
<mxCell id="EQeajuEG8KHzwlrw_xps-140" value="&lt;blockquote style=&quot;margin: 0px 0px 0px 8px; border: none; padding: 0px;&quot;&gt;addressId: Number&lt;/blockquote&gt;" style="rounded=0;whiteSpace=wrap;html=1;align=left;" parent="1" vertex="1">
<mxGeometry x="-1078.1399999999999" y="250" width="160" height="30" as="geometry" />
<mxGeometry x="-1078.1399999999999" y="220" width="160" height="30" as="geometry" />
</mxCell>
<mxCell id="EQeajuEG8KHzwlrw_xps-141" value="" style="endArrow=open;endSize=12;startArrow=diamondThin;startSize=14;startFill=0;edgeStyle=orthogonalEdgeStyle;entryX=1;entryY=0.5;entryDx=0;entryDy=0;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="EQeajuEG8KHzwlrw_xps-139" target="EQeajuEG8KHzwlrw_xps-117" edge="1">
<mxGeometry x="389.35999999999996" y="350" as="geometry">
@@ -532,7 +529,7 @@
<mxGeometry x="-938.0500000000001" y="225" width="9.43" height="20" as="geometry" />
</mxCell>
<mxCell id="EQeajuEG8KHzwlrw_xps-155" value="" style="sketch=0;pointerEvents=1;shadow=0;dashed=0;html=1;strokeColor=none;labelPosition=center;verticalLabelPosition=bottom;verticalAlign=top;outlineConnect=0;align=center;shape=mxgraph.office.security.key_permissions;fillColor=#CCCCCC;" parent="1" vertex="1">
<mxGeometry x="-938.0500000000001" y="255" width="9.43" height="20" as="geometry" />
<mxGeometry x="-938.0500000000001" y="195" width="9.43" height="20" as="geometry" />
</mxCell>
<mxCell id="EQeajuEG8KHzwlrw_xps-156" value="&lt;blockquote style=&quot;margin: 0px 0px 0px 8px; border: none; padding: 0px;&quot;&gt;logo: String&lt;/blockquote&gt;" style="rounded=0;whiteSpace=wrap;html=1;align=left;" parent="1" vertex="1">
<mxGeometry x="-358.14" y="250" width="160" height="30" as="geometry" />

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
})
})
})
})
}
})
}
}