Rewriting database and API to transform to a ticket shop

This commit is contained in:
2024-09-26 11:04:27 +02:00
parent d36dbced8e
commit da98fc73c0
88 changed files with 1040 additions and 751 deletions

View File

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

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

View File

@@ -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[]
}

View File

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

View 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[]
}

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

View 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[]
}

View File

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

View File

@@ -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[]
}

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

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