This commit is contained in:
Phuoc Nguyen
2025-05-23 13:59:21 +07:00
parent 4c51aad94e
commit a6cd959531
5 changed files with 54 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
import { Column, Entity, PrimaryGeneratedColumn, OneToMany } from 'typeorm';
import Product from '../products/product.entity';
@Entity()
class ProductCategory {
@PrimaryGeneratedColumn()
public id: number;
@Column()
public name: string;
@OneToMany(
() => Product,
(product: Product) => product.category,
)
public products: Product[];
}
export default ProductCategory;

View File

@@ -0,0 +1,23 @@
import { Column, Entity, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
import ProductCategory from '../productCategories/productCategory.entity';
import { CarProperties } from './types/carProperties.interface';
import { BookProperties } from './types/bookProperties.interface';
@Entity()
class Product {
@PrimaryGeneratedColumn()
public id: number;
@Column()
public name: string;
@ManyToOne(() => ProductCategory, (category: ProductCategory) => category.products)
public category: ProductCategory;
@Column({
type: 'jsonb'
})
public properties: CarProperties | BookProperties;
}
export default Product;

View File

@@ -0,0 +1,4 @@
export interface BookProperties {
authors: string[];
publicationYear: string;
}

View File

@@ -0,0 +1,7 @@
export interface CarProperties {
brand: string;
engine: {
fuel: string;
numberOfCylinders: number;
}
}