From 4c566fd6c3b694ab09ba716efd6d1ebe15997d0d Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 10 Feb 2025 11:27:31 +0400 Subject: [PATCH] added new tag entity --- libs/common/src/modules/tag/dtos/tag.dto.ts | 19 ++++++++++ libs/common/src/modules/tag/entities/index.ts | 1 + .../src/modules/tag/entities/tag.entity.ts | 36 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 libs/common/src/modules/tag/dtos/tag.dto.ts create mode 100644 libs/common/src/modules/tag/entities/index.ts create mode 100644 libs/common/src/modules/tag/entities/tag.entity.ts 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); + } +}