finished delete switch scene device

This commit is contained in:
faris Aljohari
2024-11-23 20:50:34 -06:00
parent 67ed5cdca1
commit 7b3c929aa6
5 changed files with 95 additions and 5 deletions

View File

@ -1,8 +1,9 @@
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
import { SceneDto, SceneIconDto } from '../dtos';
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
import { SceneIconType } from '@app/common/constants/secne-icon-type.enum';
import { SceneDeviceEntity } from '../../scene-device/entities';
import { SpaceEntity } from '../../space/entities';
// Define SceneIconEntity before SceneEntity
@Entity({ name: 'scene-icon' })
@ -45,16 +46,19 @@ export class SceneEntity extends AbstractEntity<SceneDto> {
nullable: false,
})
sceneTuyaUuid: string;
@Column({
nullable: false,
})
spaceUuid: string;
@Column({
nullable: false,
})
showInHomePage: boolean;
@ManyToOne(() => SpaceEntity, (space) => space.scenes, {
nullable: false,
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'space_uuid' })
space: SpaceEntity;
@ManyToOne(() => SceneIconEntity, (icon) => icon.scenesIconEntity, {
nullable: false,
})

View File

@ -14,6 +14,7 @@ import { CommunityEntity } from '../../community/entities';
import { SubspaceEntity } from './subspace.entity';
import { SpaceLinkEntity } from './space-link.entity';
import { SpaceProductEntity } from './space-product.entity';
import { SceneEntity } from '../../scene/entities';
@Entity({ name: 'space' })
@Unique(['invitationCode'])
@ -94,6 +95,9 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
@OneToMany(() => SpaceProductEntity, (spaceProduct) => spaceProduct.space)
spaceProducts: SpaceProductEntity[];
@OneToMany(() => SceneEntity, (scene) => scene.space)
scenes: SceneEntity[];
constructor(partial: Partial<SpaceEntity>) {
super();
Object.assign(this, partial);