Files
backend/libs/common/src/modules/space-model/entities/space-model.entity.ts
2024-12-25 10:52:48 +04:00

67 lines
1.5 KiB
TypeScript

import {
Entity,
Column,
OneToMany,
ManyToOne,
JoinColumn,
Unique,
} from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SpaceModelDto } from '../dtos';
import { SubspaceModelEntity } from './subspace-model';
import { ProjectEntity } from '../../project/entities';
import { SpaceEntity } from '../../space/entities';
import { TagModel } from './tag-model.entity';
@Entity({ name: 'space-model' })
@Unique(['modelName', 'project'])
export class SpaceModelEntity extends AbstractEntity<SpaceModelDto> {
@Column({
type: 'uuid',
default: () => 'gen_random_uuid()',
nullable: false,
})
public uuid: string;
@Column({
nullable: false,
})
public modelName: string;
@Column({
nullable: false,
default: false,
})
public disabled: boolean;
@ManyToOne(() => ProjectEntity, (project) => project.spaceModels, {
nullable: false,
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'project_uuid' })
public project: ProjectEntity;
@OneToMany(
() => SubspaceModelEntity,
(subspaceModel) => subspaceModel.spaceModel,
{
cascade: true,
nullable: true,
},
)
public subspaceModels: SubspaceModelEntity[];
@OneToMany(() => SpaceEntity, (space) => space.spaceModel, {
cascade: true,
})
public spaces: SpaceEntity[];
@OneToMany(() => TagModel, (tag) => tag.spaceModel)
tags: TagModel[];
constructor(partial: Partial<SpaceModelEntity>) {
super();
Object.assign(this, partial);
}
}