Files
backend/libs/common/src/modules/space/entities/subspace/subspace.entity.ts
ZaydSkaff 8503ee728d Refactor/space management (#404)
* refactor: reducing used queries on get communities (#385)

* refactor: fix create space logic (#394)

* Remove unique constraint on subspace and product in SubspaceProductAllocationEntity; update product relation to nullable in NewTagEntity

* refactor: fix create space logic

* device model updated to include the fixes and final columns

* updated space models to include suggested fixes, update final logic and column names

* task: removing old references of the old tag-product relation

* task: remove old use of tags

* task: remove old tag & tag model usage

* refactor: delete space

* task: remove unused functions

* fix lint rule
2025-06-11 13:15:21 +03:00

57 lines
1.5 KiB
TypeScript

import { AbstractEntity } from '@app/common/modules/abstract/entities/abstract.entity';
import { DeviceEntity } from '@app/common/modules/device/entities';
import { SubspaceModelEntity } from '@app/common/modules/space-model';
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
import { SubspaceDto } from '../../dtos';
import { SpaceEntity } from '../space.entity';
import { SubspaceProductAllocationEntity } from './subspace-product-allocation.entity';
@Entity({ name: 'subspace' })
export class SubspaceEntity extends AbstractEntity<SubspaceDto> {
@Column({
type: 'uuid',
default: () => 'gen_random_uuid()',
nullable: false,
})
public uuid: string;
@Column({
nullable: false,
})
public subspaceName: string;
@ManyToOne(() => SpaceEntity, (space) => space.subspaces, {
nullable: false,
})
@JoinColumn({ name: 'space_uuid' })
space: SpaceEntity;
@Column({
nullable: false,
default: false,
})
public disabled: boolean;
@OneToMany(() => DeviceEntity, (device) => device.subspace, {
nullable: true,
})
devices: DeviceEntity[];
@ManyToOne(() => SubspaceModelEntity, (model) => model.subspace, {
nullable: true,
})
subSpaceModel?: SubspaceModelEntity;
@OneToMany(
() => SubspaceProductAllocationEntity,
(allocation) => allocation.subspace,
{ cascade: true },
)
public productAllocations: SubspaceProductAllocationEntity[];
constructor(partial: Partial<SubspaceEntity>) {
super();
Object.assign(this, partial);
}
}