added new tag entity

This commit is contained in:
hannathkadher
2025-02-10 11:27:31 +04:00
parent a653616afe
commit 4c566fd6c3
3 changed files with 56 additions and 0 deletions

View 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;
}

View File

@ -0,0 +1 @@
export * from './tag.entity';

View 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);
}
}