mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 22:24:55 +00:00
added new tag entity
This commit is contained in:
19
libs/common/src/modules/tag/dtos/tag.dto.ts
Normal file
19
libs/common/src/modules/tag/dtos/tag.dto.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { IsNotEmpty, IsUUID, IsString } from 'class-validator';
|
||||
|
||||
export class NewTagDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@IsUUID()
|
||||
@IsNotEmpty()
|
||||
productId: string;
|
||||
|
||||
@IsUUID()
|
||||
@IsNotEmpty()
|
||||
projectId: string;
|
||||
}
|
||||
1
libs/common/src/modules/tag/entities/index.ts
Normal file
1
libs/common/src/modules/tag/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './tag.entity';
|
||||
36
libs/common/src/modules/tag/entities/tag.entity.ts
Normal file
36
libs/common/src/modules/tag/entities/tag.entity.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { Entity, Column, ManyToOne, Unique } from 'typeorm';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { ProjectEntity } from '../../project/entities';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { NewTagDto } from '../dtos/tag.dto';
|
||||
|
||||
@Entity({ name: 'tag' })
|
||||
@Unique(['name', 'project'])
|
||||
export class NewTagEntity extends AbstractEntity<NewTagDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@ManyToOne(() => ProductEntity, (product) => product.tags, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
public product: ProductEntity;
|
||||
|
||||
@ManyToOne(() => ProjectEntity, (project) => project.tags, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
public project: ProjectEntity;
|
||||
|
||||
constructor(partial: Partial<NewTagEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user