diff --git a/.gitignore b/.gitignore index f411625..0c42199 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,5 @@ coverage build *.sqlite out/ -database.svg \ No newline at end of file +database.svg +*.bkp \ No newline at end of file diff --git a/misc/database.drawio b/misc/database.drawio index 1ec7e0e..b0def35 100644 --- a/misc/database.drawio +++ b/misc/database.drawio @@ -1,61 +1,61 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + @@ -70,7 +70,7 @@ - + @@ -89,10 +89,10 @@ - + - + @@ -101,276 +101,335 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - + - - + + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - + - - - + + + + + + + + - + + + + + + + + + - + - + - + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/misc/images/database.png b/misc/images/database.png index 5db43ea..685edf4 100644 Binary files a/misc/images/database.png and b/misc/images/database.png differ diff --git a/software/backend/data/accounts.json b/software/backend/data/accounts.json index 54030e0..094d628 100644 --- a/software/backend/data/accounts.json +++ b/software/backend/data/accounts.json @@ -9,6 +9,7 @@ "lastName": "Hagemeister", "addresses": [ { + "id": 0, "accountId": 0, "street": "Laportestraße", "houseNumber": 22, @@ -18,6 +19,7 @@ ], "payments": [ { + "id": 0, "accountId": 0, "bankName": "Deutsche Bank", "iban": "DE92500105175721645777" @@ -34,6 +36,7 @@ "lastName": "Stoiber", "addresses": [ { + "id": 1, "accountId": 1, "street": "Gustav-Adolf-Straße", "houseNumber": 30, @@ -43,6 +46,7 @@ ], "payments": [ { + "id": 1, "accountId": 1, "bankName": "DZ Bank", "iban": "DE12500105179557939114" @@ -59,6 +63,7 @@ "lastName": "Oeter", "addresses": [ { + "id": 2, "accountId": 2, "street": "Eckermannstraße", "houseNumber": 1, @@ -66,6 +71,7 @@ "city": "Hannover" }, { + "id": 3, "accountId": 2, "street": "Gehrdener Straße", "houseNumber": 14, @@ -75,6 +81,7 @@ ], "payments": [ { + "id": 2, "accountId": 2, "bankName": "Commerzbank", "iban": "DE31500105175417833272" @@ -91,6 +98,7 @@ "lastName": "Durand", "addresses": [ { + "id": 4, "accountId": 3, "street": "Schlägerstraße", "houseNumber": 36, @@ -98,6 +106,7 @@ "city": "Hannover" }, { + "id": 5, "accountId": 3, "street": "Else-Ury-Weg", "houseNumber": 20, @@ -107,6 +116,7 @@ ], "payments": [ { + "id": 3, "accountId": 3, "bankName": "ING", "iban": "DE41500105172184936679" @@ -123,6 +133,7 @@ "lastName": "Furtwängler", "addresses": [ { + "id": 6, "accountId": 4, "street": "Steinmetzstraße", "houseNumber": 12, @@ -132,6 +143,7 @@ ], "payments": [ { + "id": 4, "accountId": 4, "bankName": "Sparkasse Hannover", "iban": "DE85500105172283979774" @@ -148,6 +160,7 @@ "lastName": "Herbst", "addresses": [ { + "id": 7, "accountId": 5, "street": "Allerweg", "houseNumber": 33, @@ -157,6 +170,7 @@ ], "payments": [ { + "id": 5, "accountId": 5, "bankName": "Postbank", "iban": "DE45500105178862417577" @@ -173,6 +187,7 @@ "lastName": "Seibert", "addresses": [ { + "id": 8, "accountId": 6, "street": "Marktstraße", "houseNumber": 26, @@ -180,6 +195,7 @@ "city": "Laatzen" }, { + "id": 9, "accountId": 6, "street": "Kleiner Hillen", "houseNumber": 24, @@ -189,6 +205,7 @@ ], "payments": [ { + "id": 6, "accountId": 6, "bankName": "Sparkasse Hannover", "iban": "DE51500105177526222196" diff --git a/software/backend/data/orders.json b/software/backend/data/orders.json index 350e04b..35b2766 100644 --- a/software/backend/data/orders.json +++ b/software/backend/data/orders.json @@ -3,17 +3,23 @@ { "id": 0, "accountId": 0, - "shippingProgress": 4 + "shippingProgress": 4, + "addressId": 0, + "paymentId": 0 }, { "id": 1, "accountId": 3, - "shippingProgress": 5 + "shippingProgress": 5, + "addressId": 4, + "paymentId": 3 }, { "id": 2, "accountId": 3, - "shippingProgress": 2 + "shippingProgress": 2, + "addressId": 5, + "paymentId": 3 } ] } \ No newline at end of file diff --git a/software/backend/models/address.model.ts b/software/backend/models/address.model.ts index e466541..52241e4 100644 --- a/software/backend/models/address.model.ts +++ b/software/backend/models/address.model.ts @@ -1,5 +1,6 @@ -import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript"; +import { BelongsTo, Column, ForeignKey, HasMany, Model, Table } from "sequelize-typescript"; import { Account } from "./account.model"; +import { Order } from "./order.model"; @Table({ timestamps: false }) export class Address extends Model { @@ -24,4 +25,7 @@ export class Address extends Model { @BelongsTo(() => Account) account: Account + + @HasMany(() => Order) + orders: Order[] } \ No newline at end of file diff --git a/software/backend/models/order.model.ts b/software/backend/models/order.model.ts index bdf762c..a0c29b1 100644 --- a/software/backend/models/order.model.ts +++ b/software/backend/models/order.model.ts @@ -1,6 +1,8 @@ import { Table, Column, Model, BelongsTo, ForeignKey, HasMany, BelongsToMany, Default } from 'sequelize-typescript'; import { Account } from './account.model'; import { OrderItem } from './orderItem.model'; +import { Address } from './address.model'; +import { Payment } from './payment.model'; @Table({ updatedAt: false, @@ -18,11 +20,26 @@ export class Order extends Model { @Column shippingProgress: number + @ForeignKey(() => Address) + @Column + addressId: number + + @ForeignKey(() => Payment) + @Column + paymentId: number + // Relations + @BelongsTo(() => Account) account: Account + @BelongsTo(() => Address) + address: Address + + @BelongsTo(() => Payment) + payment: Payment + @HasMany(() => OrderItem) orderItems: OrderItem[] } diff --git a/software/backend/models/payment.model.ts b/software/backend/models/payment.model.ts index 476992e..45e565a 100644 --- a/software/backend/models/payment.model.ts +++ b/software/backend/models/payment.model.ts @@ -1,5 +1,6 @@ -import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript"; +import { BelongsTo, Column, ForeignKey, HasMany, Model, Table } from "sequelize-typescript"; import { Account } from "./account.model"; +import { Order } from "./order.model"; @Table({ timestamps: false }) export class Payment extends Model { @@ -15,6 +16,10 @@ export class Payment extends Model { // Relations + @BelongsTo(() => Account) account: Account + + @HasMany(() => Order) + orders: Order[] } \ No newline at end of file diff --git a/software/backend/routes/order.routes.ts b/software/backend/routes/order.routes.ts index 852379a..0c92100 100644 --- a/software/backend/routes/order.routes.ts +++ b/software/backend/routes/order.routes.ts @@ -4,7 +4,8 @@ import { Product } from "../models/product.model"; import { OrderItem } from "../models/orderItem.model"; import { Brand } from "../models/brand.model"; import { Category } from "../models/category.model"; -import { Sequelize } from "sequelize-typescript"; +import { Payment } from "../models/payment.model"; +import { Address } from "../models/address.model"; export const order = Router() @@ -27,7 +28,9 @@ order.get("/:id", (req: Request, res: Response) => { } }, ] - } + }, + Payment, + Address ] }) .then(orders => { @@ -49,7 +52,10 @@ order.post("/", (req: Request, res: Response) => { Product.decrement( "inStock", - { where: { id: orderItem.productId } } + { + by: orderItem.quantity, + where: { id: orderItem.productId } + } ) } diff --git a/software/src/components/confirmDialog.vue b/software/src/components/confirmDialog.vue index a5f028f..5cc7707 100644 --- a/software/src/components/confirmDialog.vue +++ b/software/src/components/confirmDialog.vue @@ -32,13 +32,15 @@ function confirmPressed() {