diff --git a/src/posts/posts.service.ts b/src/posts/posts.service.ts index 05ffc4c..4d787b3 100644 --- a/src/posts/posts.service.ts +++ b/src/posts/posts.service.ts @@ -39,7 +39,7 @@ export class PostsService { }); } - + async getAllPosts(offset?: number, limit?: number, startId = 0) { diff --git a/src/productCategories/productCategory.entity.ts b/src/productCategories/productCategory.entity.ts new file mode 100644 index 0000000..1c41f4a --- /dev/null +++ b/src/productCategories/productCategory.entity.ts @@ -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; \ No newline at end of file diff --git a/src/products/product.entity.ts b/src/products/product.entity.ts new file mode 100644 index 0000000..9a6587e --- /dev/null +++ b/src/products/product.entity.ts @@ -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; \ No newline at end of file diff --git a/src/products/types/bookProperties.interface.ts b/src/products/types/bookProperties.interface.ts new file mode 100644 index 0000000..b3dae4e --- /dev/null +++ b/src/products/types/bookProperties.interface.ts @@ -0,0 +1,4 @@ +export interface BookProperties { + authors: string[]; + publicationYear: string; +} \ No newline at end of file diff --git a/src/products/types/carProperties.interface.ts b/src/products/types/carProperties.interface.ts new file mode 100644 index 0000000..a1c4c28 --- /dev/null +++ b/src/products/types/carProperties.interface.ts @@ -0,0 +1,7 @@ +export interface CarProperties { + brand: string; + engine: { + fuel: string; + numberOfCylinders: number; + } +} \ No newline at end of file