Extend database with more tables, rewrite API doc, improve API endpoints
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { Table, Column, Model, HasMany, Unique } from 'sequelize-typescript';
|
||||
import { Table, Column, Model, HasMany, Unique, BelongsTo, ForeignKey } from 'sequelize-typescript';
|
||||
import { Order } from './order.model';
|
||||
import { Address } from './address.model';
|
||||
import { Payment } from './payment.model';
|
||||
import { AccountRole } from './accountRole.model';
|
||||
|
||||
@Table
|
||||
@Table({ timestamps: false })
|
||||
export class Account extends Model {
|
||||
@Unique
|
||||
@Column
|
||||
@@ -16,25 +19,21 @@ export class Account extends Model {
|
||||
@Column
|
||||
lastName: string = ""
|
||||
|
||||
@ForeignKey(() => AccountRole)
|
||||
@Column
|
||||
street: string = ""
|
||||
accountRoleId: number
|
||||
|
||||
@Column
|
||||
houseNumber: number = 0
|
||||
|
||||
@Column
|
||||
postalCode: number = 0
|
||||
|
||||
@Column
|
||||
city: string
|
||||
|
||||
@Column
|
||||
bankName: string
|
||||
|
||||
@Column
|
||||
iban: string
|
||||
|
||||
// Relations
|
||||
@HasMany(() => Address)
|
||||
addresses: Address[]
|
||||
|
||||
@HasMany(() => Payment)
|
||||
payments: Payment[]
|
||||
|
||||
@HasMany(() => Order)
|
||||
orders: Order[]
|
||||
|
||||
@BelongsTo(() => AccountRole)
|
||||
accountRole: AccountRole
|
||||
}
|
||||
19
software/backend/models/accountRole.model.ts
Normal file
19
software/backend/models/accountRole.model.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Column, HasMany, Model, Table } from "sequelize-typescript";
|
||||
import { Account } from "./account.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class AccountRole extends Model {
|
||||
@Column
|
||||
name: string
|
||||
|
||||
@Column
|
||||
privilegeBuy: boolean
|
||||
|
||||
@Column
|
||||
privilegeAdminPanel: boolean
|
||||
|
||||
|
||||
// Relations
|
||||
@HasMany(() => Account)
|
||||
accounts: Account[]
|
||||
}
|
||||
27
software/backend/models/address.model.ts
Normal file
27
software/backend/models/address.model.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript";
|
||||
import { Account } from "./account.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Address extends Model {
|
||||
@ForeignKey(() => Account)
|
||||
@Column
|
||||
accountId: number
|
||||
|
||||
@Column
|
||||
street: string
|
||||
|
||||
@Column
|
||||
houseNumber: number
|
||||
|
||||
@Column
|
||||
postalCode: number
|
||||
|
||||
@Column
|
||||
city: string
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@BelongsTo(() => Account)
|
||||
account: Account
|
||||
}
|
||||
14
software/backend/models/brand.model.ts
Normal file
14
software/backend/models/brand.model.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Column, HasMany, Model, Table } from "sequelize-typescript";
|
||||
import { Product } from "./product.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Brand extends Model {
|
||||
@Column
|
||||
name: string
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@HasMany(() => Product)
|
||||
products: Product[]
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Table, Column, Model, BelongsTo, ForeignKey, HasMany, Unique } from 'sequelize-typescript';
|
||||
import { Product } from './product.model';
|
||||
|
||||
@Table
|
||||
@Table({ timestamps: false })
|
||||
export class Category extends Model {
|
||||
@Unique
|
||||
@Column
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
import { Table, Column, Model, BelongsTo, ForeignKey, HasMany, BelongsToMany } from 'sequelize-typescript';
|
||||
import { Table, Column, Model, BelongsTo, ForeignKey, HasMany, BelongsToMany, Default } from 'sequelize-typescript';
|
||||
import { Account } from './account.model';
|
||||
import { OrderItem } from './orderItem.model';
|
||||
|
||||
@Table
|
||||
@Table({
|
||||
updatedAt: false,
|
||||
createdAt: 'orderedAt'
|
||||
})
|
||||
export class Order extends Model {
|
||||
@Column
|
||||
@ForeignKey(() => Account)
|
||||
accountId: number
|
||||
|
||||
@Column
|
||||
totalPrice: number
|
||||
orderedAt: Date
|
||||
|
||||
@Default(1)
|
||||
@Column
|
||||
shippingProgress: number = 1
|
||||
shippingProgress: number
|
||||
|
||||
|
||||
// Relations
|
||||
@@ -20,5 +24,5 @@ export class Order extends Model {
|
||||
account: Account
|
||||
|
||||
@HasMany(() => OrderItem)
|
||||
orderItem: OrderItem[]
|
||||
orderItems: OrderItem[]
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Model, BelongsTo, Column, ForeignKey, HasMany, HasOne, Table } from "se
|
||||
import { Product } from "./product.model";
|
||||
import { Order } from "./order.model";
|
||||
|
||||
@Table
|
||||
@Table({ timestamps: false })
|
||||
export class OrderItem extends Model {
|
||||
@Column
|
||||
@ForeignKey(() => Order)
|
||||
@@ -10,6 +10,9 @@ export class OrderItem extends Model {
|
||||
|
||||
@Column
|
||||
quantity: number
|
||||
|
||||
@Column
|
||||
orderPrice: number
|
||||
|
||||
@Column
|
||||
@ForeignKey(() => Product)
|
||||
|
||||
20
software/backend/models/payment.model.ts
Normal file
20
software/backend/models/payment.model.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript";
|
||||
import { Account } from "./account.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Payment extends Model {
|
||||
@ForeignKey(() => Account)
|
||||
@Column
|
||||
accountId: number
|
||||
|
||||
@Column
|
||||
bankName: string
|
||||
|
||||
@Column
|
||||
iban: string
|
||||
|
||||
|
||||
// Relations
|
||||
@BelongsTo(() => Account)
|
||||
account: Account
|
||||
}
|
||||
@@ -1,18 +1,23 @@
|
||||
import { Table, Column, Model, ForeignKey, BelongsTo, BelongsToMany, HasMany, DataType } from 'sequelize-typescript';
|
||||
import { Category } from './category.model';
|
||||
import { OrderItem } from './orderItem.model';
|
||||
import { Brand } from './brand.model';
|
||||
|
||||
@Table
|
||||
@Table({ timestamps: false })
|
||||
export class Product extends Model {
|
||||
@Column
|
||||
brand: string
|
||||
@ForeignKey(() => Category)
|
||||
categoryId: number
|
||||
|
||||
@ForeignKey(() => Brand)
|
||||
@Column
|
||||
brandId: number
|
||||
|
||||
@Column
|
||||
name: string
|
||||
|
||||
@Column
|
||||
@ForeignKey(() => Category)
|
||||
categoryId: number
|
||||
description: string
|
||||
|
||||
@Column
|
||||
price: number
|
||||
@@ -23,19 +28,8 @@ export class Product extends Model {
|
||||
@Column
|
||||
rating: number
|
||||
|
||||
@Column({
|
||||
type: DataType.STRING,
|
||||
get(): Array<string> {
|
||||
return this.getDataValue('images').split(';')
|
||||
},
|
||||
set(value: Array<string>) {
|
||||
this.setDataValue('images', value.join(';'))
|
||||
}
|
||||
})
|
||||
images: Array<string>
|
||||
|
||||
@Column
|
||||
description: string
|
||||
inStock: number
|
||||
|
||||
@Column({
|
||||
type: DataType.STRING,
|
||||
@@ -48,13 +42,26 @@ export class Product extends Model {
|
||||
})
|
||||
specs: Array<string>
|
||||
|
||||
@Column
|
||||
storedItems: number
|
||||
|
||||
@Column({
|
||||
type: DataType.STRING,
|
||||
get(): Array<string> {
|
||||
return this.getDataValue('images').split(';')
|
||||
},
|
||||
set(value: Array<string>) {
|
||||
this.setDataValue('images', value.join(';'))
|
||||
}
|
||||
})
|
||||
images: Array<string>
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@BelongsTo(() => Category)
|
||||
category: Category
|
||||
|
||||
@BelongsTo(() => Brand)
|
||||
brand: Brand
|
||||
|
||||
@HasMany(() => OrderItem)
|
||||
order: OrderItem
|
||||
orders: OrderItem[]
|
||||
}
|
||||
Reference in New Issue
Block a user