crud product

This commit is contained in:
2026-01-13 18:19:51 +03:30
parent 984b889587
commit 6522acff5f
27 changed files with 333 additions and 1080 deletions
@@ -1,6 +1,6 @@
import { Entity, Property, ManyToOne } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Attribute } from './attribute.entity';
// import { Attribute } from './attribute.entity';
@Entity({ tableName: 'attribute_values' })
export class AttributeValue extends BaseEntity {
@@ -10,13 +10,13 @@ export class AttributeValue extends BaseEntity {
@Property()
value: string;
@ManyToOne(() => Attribute)
attribute: Attribute;
// @ManyToOne(() => Attribute)
// attribute: Attribute;
@Property({ type: 'bigint' })
attributeId: bigint;
@Property({ type: 'int', nullable: true })
sortOrder?: number;
order?: number;
}
@@ -4,6 +4,9 @@ import { AttributeType } from '../interface/product.interface';
@Entity({ tableName: 'attributes' })
export class Attribute extends BaseEntity {
@Property({ type: 'bigint' })
productId: string
@Property({ primary: true })
id: bigint;
@@ -0,0 +1,30 @@
import { Entity, Index, Property, Collection, OneToMany, ManyToOne } from '@mikro-orm/core';
import { Product } from './product.entity';
import { BaseEntity } from '../../../common/entities/base.entity';
@Entity({ tableName: 'categories' })
@Index({ properties: ['isActive'] })
export class Category extends BaseEntity {
@ManyToOne(() => Category)
parent?: Category | null
@Property({ primary: true })
id: bigint
@Property()
title!: string;
@OneToMany(() => Product, product => product.category)
Products = new Collection<Product>(this);
@Property({ default: true })
isActive: boolean = true;
@Property({ nullable: true })
avatarUrl?: string;
@Property({ type: 'int', nullable: true })
order?: number;
}
+19 -2
View File
@@ -1,15 +1,29 @@
import { Entity, Property } from '@mikro-orm/core';
import { Collection, Entity, ManyToOne, OneToMany, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Category } from './category.entity';
import { Attribute } from './attribute.entity';
@Entity({ tableName: 'products' })
export class product extends BaseEntity {
export class Product extends BaseEntity {
@Property({ primary: true })
id: bigint
@ManyToOne(() => Category)
category: Category
@OneToMany(() => Attribute, (attr) => attr.productId)
attributes = new Collection<Attribute>(this)
@Property()
title: string;
@Property({ type: 'json' })
desc: string[]
@Property()
prepareTime: number;
@Property({ type: 'text', nullable: true })
linkUrl?: string;
@@ -19,4 +33,7 @@ export class product extends BaseEntity {
@Property({ type: 'json', nullable: true })
images?: string[];
@Property({ type: 'int' })
order?: number | null
}