Connect Orders database table with Payments and Addresses, visualize it in the frontend
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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[]
|
||||
}
|
||||
@@ -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[]
|
||||
}
|
||||
|
||||
@@ -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[]
|
||||
}
|
||||
@@ -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 }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user