diff --git a/src/modules/product/controllers/product.controller.ts b/src/modules/product/controllers/product.controller.ts index 701ca4f..7baf00f 100644 --- a/src/modules/product/controllers/product.controller.ts +++ b/src/modules/product/controllers/product.controller.ts @@ -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' }) diff --git a/src/modules/product/dto/create-attribute.dto.ts b/src/modules/product/dto/create-attribute.dto.ts index 79b199d..10935fe 100644 --- a/src/modules/product/dto/create-attribute.dto.ts +++ b/src/modules/product/dto/create-attribute.dto.ts @@ -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() diff --git a/src/modules/product/entities/attribute-value.entity.ts b/src/modules/product/entities/attribute-value.entity.ts index ac3ad14..1f2dddc 100644 --- a/src/modules/product/entities/attribute-value.entity.ts +++ b/src/modules/product/entities/attribute-value.entity.ts @@ -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() diff --git a/src/modules/product/entities/attribute.entity.ts b/src/modules/product/entities/attribute.entity.ts index daacd08..47930ab 100644 --- a/src/modules/product/entities/attribute.entity.ts +++ b/src/modules/product/entities/attribute.entity.ts @@ -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 }) diff --git a/src/modules/product/entities/category.entity.ts b/src/modules/product/entities/category.entity.ts index 2197769..7cb6a25 100644 --- a/src/modules/product/entities/category.entity.ts +++ b/src/modules/product/entities/category.entity.ts @@ -13,7 +13,7 @@ export class Category extends BaseEntity { children?: Category[] @PrimaryKey({ type: 'bigint', autoincrement: true }) - id: number + id: bigint @Property() title: string; diff --git a/src/modules/product/entities/product.entity.ts b/src/modules/product/entities/product.entity.ts index d4bc84b..a7c392c 100644 --- a/src/modules/product/entities/product.entity.ts +++ b/src/modules/product/entities/product.entity.ts @@ -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(this) + @PrimaryKey({ type: 'bigint', autoincrement: true }) + id: bigint + @Property() title: string; diff --git a/src/modules/product/providers/attribute.service.ts b/src/modules/product/providers/attribute.service.ts index 5efcf31..856328f 100644 --- a/src/modules/product/providers/attribute.service.ts +++ b/src/modules/product/providers/attribute.service.ts @@ -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 } diff --git a/src/modules/product/providers/product.service.ts b/src/modules/product/providers/product.service.ts index e375418..7d45c6a 100644 --- a/src/modules/product/providers/product.service.ts +++ b/src/modules/product/providers/product.service.ts @@ -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 } diff --git a/src/seeders/DatabaseSeeder.ts b/src/seeders/DatabaseSeeder.ts index d921c67..a636028 100644 --- a/src/seeders/DatabaseSeeder.ts +++ b/src/seeders/DatabaseSeeder.ts @@ -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'; diff --git a/src/seeders/foods.seeder.ts b/src/seeders/product.seeder.ts similarity index 100% rename from src/seeders/foods.seeder.ts rename to src/seeders/product.seeder.ts