Rewriting database and API to transform to a ticket shop
This commit is contained in:
@@ -3,6 +3,7 @@ import { Order } from './order.model';
|
||||
import { Address } from './address.model';
|
||||
import { Payment } from './payment.model';
|
||||
import { AccountRole } from './accountRole.model';
|
||||
import { Rating } from './rating.model';
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Account extends Model {
|
||||
@@ -38,6 +39,9 @@ export class Account extends Model {
|
||||
@HasMany(() => Order)
|
||||
orders: Order[]
|
||||
|
||||
@HasMany(() => Rating)
|
||||
ratings: Rating[]
|
||||
|
||||
@BelongsTo(() => AccountRole)
|
||||
accountRole: AccountRole
|
||||
}
|
||||
49
software/backend/models/band.model.ts
Normal file
49
software/backend/models/band.model.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { BelongsTo, Column, DataType, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
|
||||
import { Member } from "./member.model";
|
||||
import { Genre } from "./genre.model";
|
||||
import { Rating } from "./rating.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Band extends Model {
|
||||
@Column
|
||||
name: String
|
||||
|
||||
@Column
|
||||
foundingYear: Number
|
||||
|
||||
@Column
|
||||
descriptionEn: String
|
||||
|
||||
@Column
|
||||
descriptionDe: String
|
||||
|
||||
@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
|
||||
logo: String
|
||||
|
||||
@ForeignKey(() => Genre)
|
||||
@Column
|
||||
genreId: Number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@HasMany(() => Member)
|
||||
members: Member[]
|
||||
|
||||
@HasMany(() => Rating)
|
||||
ratings: Rating[]
|
||||
|
||||
@BelongsTo(() => Genre)
|
||||
genre: Genre
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
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,15 +0,0 @@
|
||||
import { Table, Column, Model, BelongsTo, ForeignKey, HasMany, Unique } from 'sequelize-typescript';
|
||||
import { Product } from './product.model';
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Category extends Model {
|
||||
@Unique
|
||||
@Column
|
||||
name: string
|
||||
|
||||
@Column
|
||||
icon: string
|
||||
|
||||
@HasMany(() => Product)
|
||||
product: Product
|
||||
}
|
||||
14
software/backend/models/genre.model.ts
Normal file
14
software/backend/models/genre.model.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Column, HasMany, Model, Table } from "sequelize-typescript";
|
||||
import { Band } from "./band.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Genre extends Model {
|
||||
@Column
|
||||
name: String
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@HasMany(() => Band)
|
||||
bands: Band[]
|
||||
}
|
||||
13
software/backend/models/location.model.ts
Normal file
13
software/backend/models/location.model.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Column, Model, Table } from "sequelize-typescript";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Location extends Model {
|
||||
@Column
|
||||
name: String
|
||||
|
||||
@Column
|
||||
address: String
|
||||
|
||||
@Column
|
||||
image: String
|
||||
}
|
||||
21
software/backend/models/member.model.ts
Normal file
21
software/backend/models/member.model.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript";
|
||||
import { Band } from "./band.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Member extends Model {
|
||||
@Column
|
||||
name: String
|
||||
|
||||
@ForeignKey(() => Band)
|
||||
@Column
|
||||
bandId: Number
|
||||
|
||||
@Column
|
||||
image: String
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@BelongsTo(() => Band)
|
||||
bands: Band[]
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Model, BelongsTo, Column, ForeignKey, HasMany, HasOne, Table } from "sequelize-typescript";
|
||||
import { Product } from "./product.model";
|
||||
import { Show } from "./show.model";
|
||||
import { Order } from "./order.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
@@ -15,7 +15,7 @@ export class OrderItem extends Model {
|
||||
orderPrice: number
|
||||
|
||||
@Column
|
||||
@ForeignKey(() => Product)
|
||||
@ForeignKey(() => Show)
|
||||
productId: number
|
||||
|
||||
|
||||
@@ -23,6 +23,6 @@ export class OrderItem extends Model {
|
||||
@BelongsTo(() => Order)
|
||||
order: Order
|
||||
|
||||
@BelongsTo(() => Product)
|
||||
product: Product
|
||||
@BelongsTo(() => Show)
|
||||
product: Show
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
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({ timestamps: false })
|
||||
export class Product extends Model {
|
||||
@Column
|
||||
@ForeignKey(() => Category)
|
||||
categoryId: number
|
||||
|
||||
@ForeignKey(() => Brand)
|
||||
@Column
|
||||
brandId: number
|
||||
|
||||
@Column
|
||||
name: string
|
||||
|
||||
@Column
|
||||
description: string
|
||||
|
||||
@Column
|
||||
price: number
|
||||
|
||||
@Column
|
||||
discount: number
|
||||
|
||||
@Column
|
||||
rating: number
|
||||
|
||||
@Column
|
||||
inStock: number
|
||||
|
||||
@Column
|
||||
offered: boolean
|
||||
|
||||
@Column({
|
||||
type: DataType.STRING,
|
||||
get(): Array<string> {
|
||||
return this.getDataValue('specs').split(';')
|
||||
},
|
||||
set(value: Array<string>) {
|
||||
this.setDataValue('specs', value.join(';'))
|
||||
}
|
||||
})
|
||||
specs: Array<string>
|
||||
|
||||
@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)
|
||||
orders: OrderItem[]
|
||||
}
|
||||
27
software/backend/models/rating.model.ts
Normal file
27
software/backend/models/rating.model.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript";
|
||||
import { Account } from "./account.model";
|
||||
import { Band } from "./band.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Rating extends Model {
|
||||
|
||||
@ForeignKey(() => Account)
|
||||
@Column
|
||||
accountId: Number
|
||||
|
||||
@Column
|
||||
rating: Number
|
||||
|
||||
@ForeignKey(() => Band)
|
||||
@Column
|
||||
bandId: Number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@BelongsTo(() => Account)
|
||||
account: Account
|
||||
|
||||
@BelongsTo(() => Band)
|
||||
band: Band
|
||||
}
|
||||
37
software/backend/models/show.model.ts
Normal file
37
software/backend/models/show.model.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { BelongsTo, Column, ForeignKey, Model, Table } from "sequelize-typescript";
|
||||
import { Band } from "./band.model";
|
||||
import { Location } from "./location.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Show extends Model {
|
||||
@Column
|
||||
name: String
|
||||
|
||||
@ForeignKey(() => Band)
|
||||
bandId: Number
|
||||
|
||||
@Column
|
||||
date: String
|
||||
|
||||
@Column
|
||||
price: Number
|
||||
|
||||
@Column
|
||||
inStock: Number
|
||||
|
||||
@Column
|
||||
offered: Boolean
|
||||
|
||||
@ForeignKey(() => Location)
|
||||
@Column
|
||||
locationId: Number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@BelongsTo(() => Band)
|
||||
band: Band
|
||||
|
||||
@BelongsTo(() => Location)
|
||||
location: Location
|
||||
}
|
||||
Reference in New Issue
Block a user