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