Extend database with more tables, rewrite API doc, improve API endpoints

This commit is contained in:
2024-09-23 21:22:45 +02:00
parent 8b4db9ccc8
commit b245e3803a
41 changed files with 1345 additions and 1126 deletions

View File

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