mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
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<GroupDeviceDto> {
|
|
@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<GroupDeviceEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|