22: json
This commit is contained in:
19
src/productCategories/productCategory.entity.ts
Normal file
19
src/productCategories/productCategory.entity.ts
Normal 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;
|
||||
23
src/products/product.entity.ts
Normal file
23
src/products/product.entity.ts
Normal 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;
|
||||
4
src/products/types/bookProperties.interface.ts
Normal file
4
src/products/types/bookProperties.interface.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface BookProperties {
|
||||
authors: string[];
|
||||
publicationYear: string;
|
||||
}
|
||||
7
src/products/types/carProperties.interface.ts
Normal file
7
src/products/types/carProperties.interface.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface CarProperties {
|
||||
brand: string;
|
||||
engine: {
|
||||
fuel: string;
|
||||
numberOfCylinders: number;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user