import { Column, Entity, ManyToOne, Unique } from 'typeorm'; import { GroupDeviceDto } from '../dtos'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { DeviceEntity } from '../../device/entities'; import { GroupEntity } from '../../group/entities'; @Entity({ name: 'group-device' }) @Unique(['device', 'group']) export class GroupDeviceEntity extends AbstractEntity { @Column({ type: 'uuid', default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value nullable: false, }) public uuid: string; @Column({ type: 'string', nullable: false, }) deviceUuid: string; @Column({ type: 'string', nullable: false, }) groupUuid: string; @ManyToOne(() => DeviceEntity, (device) => device.userGroupDevices, { nullable: false, }) device: DeviceEntity; @ManyToOne(() => GroupEntity, (group) => group.groupDevices, { nullable: false, }) group: GroupEntity; @Column({ nullable: true, default: true, }) public isActive: boolean; constructor(partial: Partial) { super(); Object.assign(this, partial); } }