attribute

This commit is contained in:
2026-01-16 19:11:57 +03:30
parent 17b4b30a3f
commit d9bc1fa0b2
10 changed files with 30 additions and 25 deletions
@@ -48,7 +48,7 @@ export class productController {
/* ---------------------------------- Admin ---------------------------------- */
@Post('admin/product')
@UseGuards(AdminAuthGuard)
// @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.MANAGE_productS)
@ApiOperation({ summary: 'Create a new product' })
@@ -58,7 +58,7 @@ export class productController {
}
@Get('admin/products')
@UseGuards(AdminAuthGuard)
// @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.MANAGE_productS)
@ApiOperation({ summary: 'Get a paginated list of products' })
@@ -75,7 +75,7 @@ export class productController {
}
@Get('admin/products/:id')
@UseGuards(AdminAuthGuard)
// @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.MANAGE_productS)
@ApiOperation({ summary: 'Get a product by id' })
@@ -85,7 +85,7 @@ export class productController {
}
@Patch('admin/products/:id')
@UseGuards(AdminAuthGuard)
// @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.MANAGE_productS)
@ApiOperation({ summary: 'Update a product' })
@@ -96,7 +96,7 @@ export class productController {
}
@Delete('admin/products/:id')
@UseGuards(AdminAuthGuard)
// @UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.MANAGE_productS)
@ApiOperation({ summary: 'Delete (soft) a product' })
@@ -1,4 +1,4 @@
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum } from 'class-validator';
import { IsString, IsOptional, IsBoolean, IsInt, Min, IsEnum, IsNotEmpty } from 'class-validator';
import { ApiPropertyOptional, ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { AttributeType } from '../interface/product.interface';
@@ -19,8 +19,9 @@ export class CreateAttributeDto {
@ApiPropertyOptional({ example: true })
isRequired: boolean;
@IsEnum(() => AttributeType)
@ApiProperty()
@IsNotEmpty()
@IsEnum(AttributeType)
@ApiProperty({ enum: AttributeType, example: AttributeType.SELECT })
type: AttributeType;
@IsOptional()
@@ -1,10 +1,10 @@
import { Entity, Property, ManyToOne } from '@mikro-orm/core';
import { Entity, Property, ManyToOne, PrimaryKey } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
// import { Attribute } from './attribute.entity';
@Entity({ tableName: 'attribute_values' })
export class AttributeValue extends BaseEntity {
@Property({ primary: true })
@PrimaryKey({ autoincrement: true, type: 'bigint' })
id: bigint;
@Property()
@@ -1,26 +1,26 @@
import { Entity, Enum, ManyToOne, OneToMany, Property } from '@mikro-orm/core';
import { Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { AttributeType } from '../interface/product.interface';
import { Product } from './product.entity';
@Entity({ tableName: 'attributes' })
export class Attribute extends BaseEntity {
@ManyToOne(()=>Product)
@ManyToOne(() => Product)
product: Product
@ManyToOne(() => Attribute, { nullable: true })
parent?: Attribute | null
@OneToMany(() => Attribute, (c) => c.parent)
children?: Attribute[]
@Property({ primary: true })
id: bigint;
@PrimaryKey({ type: 'bigint', autoincrement: true })
id: number;
@Property()
name: string;
@Enum()
@Enum(() => AttributeType)
type: AttributeType;
@Property({ type: 'boolean', default: false })
@@ -13,7 +13,7 @@ export class Category extends BaseEntity {
children?: Category[]
@PrimaryKey({ type: 'bigint', autoincrement: true })
id: number
id: bigint
@Property()
title: string;
@@ -6,15 +6,15 @@ import { Attribute } from './attribute.entity';
@Entity({ tableName: 'products' })
export class Product extends BaseEntity {
@PrimaryKey({ type: 'bigint', columnType: 'char(26)', autoincrement: true })
id: bigint
@ManyToOne(() => Category)
category: Category
@OneToMany(() => Attribute, (attr) => attr.product)
attributes = new Collection<Attribute>(this)
@PrimaryKey({ type: 'bigint', autoincrement: true })
id: bigint
@Property()
title: string;
@@ -40,11 +40,11 @@ export class AttributeService {
parent
};
const category = this.attributeRepository.create(data)
const attribute = this.attributeRepository.create(data)
await this.em.persistAndFlush(category)
await this.em.persistAndFlush(attribute)
return category
return attribute
}
@@ -34,7 +34,11 @@ export class ProductService {
category,
};
return this.productRepository.create(data)
const product = this.productRepository.create(data)
this.em.persistAndFlush(product)
return product
}
+1 -1
View File
@@ -2,7 +2,7 @@ import type { EntityManager } from '@mikro-orm/core';
import { Seeder } from '@mikro-orm/seeder';
import { PermissionsSeeder } from './permissions.seeder';
import { RolesSeeder } from './roles.seeder';
import { ProductsSeeder } from './foods.seeder';
import { ProductsSeeder } from './product.seeder';
import { AdminsSeeder } from './admins.seeder';
import { UsersSeeder } from './users.seeder';