mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 09:57:28 +00:00
68 lines
1.5 KiB
TypeScript
68 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 { SpaceProductModelEntity } from './space-product-model.entity';
|
|
import { ProjectEntity } from '../../project/entities';
|
|
import { SpaceEntity } from '../../space/entities';
|
|
|
|
@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(
|
|
() => SpaceProductModelEntity,
|
|
(productModel) => productModel.spaceModel,
|
|
{
|
|
nullable: true,
|
|
},
|
|
)
|
|
public spaceProductModels: SpaceProductModelEntity[];
|
|
|
|
@OneToMany(() => SpaceEntity, (space) => space.spaceModel, {
|
|
cascade: true,
|
|
})
|
|
public spaces: SpaceEntity[];
|
|
}
|