Merge branch 'master' into dev
This commit is contained in:
@@ -1,16 +1,9 @@
|
||||
import { IsString, IsOptional, IsBoolean } from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsString } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class CreateGroupDto {
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'Social Media' })
|
||||
name!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Type(() => Boolean)
|
||||
@ApiPropertyOptional({ example: true })
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
import { IsString, IsOptional, IsBoolean } from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsString } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class CreateIconDto {
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'Facebook Icon' })
|
||||
name!: string;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'https://example.com/icons/facebook.svg' })
|
||||
url!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Type(() => Boolean)
|
||||
@ApiPropertyOptional({ example: true })
|
||||
isActive?: boolean;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'group-id-here' })
|
||||
groupId!: string;
|
||||
|
||||
@@ -3,14 +3,10 @@ import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Icon } from './icon.entity';
|
||||
|
||||
@Entity({ tableName: 'icon_groups' })
|
||||
@Index({ properties: ['isActive'] })
|
||||
export class Group extends BaseEntity {
|
||||
@Property()
|
||||
name!: string;
|
||||
|
||||
@Property({ default: true })
|
||||
isActive: boolean = true;
|
||||
|
||||
@OneToMany(() => Icon, icon => icon.group)
|
||||
icons = new Collection<Icon>(this);
|
||||
}
|
||||
|
||||
@@ -3,18 +3,11 @@ import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Group } from './group.entity';
|
||||
|
||||
@Entity({ tableName: 'icons' })
|
||||
@Index({ properties: ['isActive'] })
|
||||
@Index({ properties: ['group', 'isActive'] })
|
||||
@Index({ properties: ['group'] })
|
||||
export class Icon extends BaseEntity {
|
||||
@Property()
|
||||
name!: string;
|
||||
|
||||
@Property()
|
||||
url!: string;
|
||||
|
||||
@Property({ default: true })
|
||||
isActive: boolean = true;
|
||||
|
||||
@ManyToOne(() => Group)
|
||||
group!: Group;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ export class GroupService {
|
||||
async create(dto: CreateGroupDto): Promise<Group> {
|
||||
const data: RequiredEntityData<Group> = {
|
||||
name: dto.name,
|
||||
isActive: dto.isActive ?? true,
|
||||
};
|
||||
|
||||
const group = this.groupRepository.create(data);
|
||||
|
||||
@@ -22,9 +22,7 @@ export class IconService {
|
||||
}
|
||||
|
||||
const data: RequiredEntityData<Icon> = {
|
||||
name: dto.name,
|
||||
url: dto.url,
|
||||
isActive: dto.isActive ?? true,
|
||||
group: group,
|
||||
};
|
||||
|
||||
@@ -60,9 +58,7 @@ export class IconService {
|
||||
}
|
||||
|
||||
this.em.assign(icon, {
|
||||
name: dto.name,
|
||||
url: dto.url,
|
||||
isActive: dto.isActive,
|
||||
});
|
||||
|
||||
await this.em.persistAndFlush(icon);
|
||||
|
||||
Reference in New Issue
Block a user