diff --git a/libs/common/src/modules/tag/dtos/tag.dto.ts b/libs/common/src/modules/tag/dtos/tag.dto.ts new file mode 100644 index 0000000..441f339 --- /dev/null +++ b/libs/common/src/modules/tag/dtos/tag.dto.ts @@ -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; +} diff --git a/libs/common/src/modules/tag/entities/index.ts b/libs/common/src/modules/tag/entities/index.ts new file mode 100644 index 0000000..9023bab --- /dev/null +++ b/libs/common/src/modules/tag/entities/index.ts @@ -0,0 +1 @@ +export * from './tag.entity'; \ No newline at end of file diff --git a/libs/common/src/modules/tag/entities/tag.entity.ts b/libs/common/src/modules/tag/entities/tag.entity.ts new file mode 100644 index 0000000..e1dd0fd --- /dev/null +++ b/libs/common/src/modules/tag/entities/tag.entity.ts @@ -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 { + @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) { + super(); + Object.assign(this, partial); + } +}