Files
backend/libs/common/src/modules/space-model/entities/space-model.entity.ts
2025-02-10 20:36:29 +04:00

67 lines
1.7 KiB
TypeScript

import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SpaceModelDto } from '../dtos';
import { SubspaceModelEntity } from './subspace-model';
import { ProjectEntity } from '../../project/entities';
import { TagModel } from './tag-model.entity';
import { SpaceModelProductAllocationEntity } from './space-model-product-allocation.entity';
import { SpaceEntity } from '../../space/entities/space.entity';
@Entity({ name: 'space-model' })
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[];
@OneToMany(
() => SpaceModelProductAllocationEntity,
(allocation) => allocation.spaceModel,
{ cascade: true },
)
public productAllocations: SpaceModelProductAllocationEntity[];
constructor(partial: Partial<SpaceModelEntity>) {
super();
Object.assign(this, partial);
}
}