mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-28 00:34:55 +00:00
changed entity and type structure
This commit is contained in:
@ -1,11 +1,21 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { DeviceEntity } from './entities';
|
||||
import {
|
||||
DeviceEntity,
|
||||
DeviceNotificationEntity,
|
||||
DeviceUserPermissionEntity,
|
||||
} from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [TypeOrmModule.forFeature([DeviceEntity])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
DeviceEntity,
|
||||
DeviceNotificationEntity,
|
||||
DeviceUserPermissionEntity,
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class DeviceRepositoryModule {}
|
||||
|
||||
@ -21,3 +21,35 @@ export class DeviceDto {
|
||||
@IsNotEmpty()
|
||||
productUuid: string;
|
||||
}
|
||||
|
||||
export class DeviceUserPermissionDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public permissionTypeUuid: string;
|
||||
}
|
||||
|
||||
export class DeviceNotificationDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public deviceUuid: string;
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique, Index } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { DeviceDto } from '../dtos/device.dto';
|
||||
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { ProductEntity } from '../../product/entities';
|
||||
import { DeviceUserPermissionEntity } from '../../device-user-permission/entities';
|
||||
import { DeviceNotificationEntity } from '../../device-notification/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
import { DeviceNotificationDto } from '../dtos';
|
||||
import { PermissionTypeEntity } from '../../permission/entities';
|
||||
|
||||
@Entity({ name: 'device' })
|
||||
@Unique(['deviceTuyaUuid'])
|
||||
@ -60,3 +60,68 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'device-notification' })
|
||||
@Unique(['userUuid', 'deviceUuid'])
|
||||
export class DeviceNotificationEntity extends AbstractEntity<DeviceNotificationDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public userUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
deviceUuid: string;
|
||||
|
||||
@ManyToOne(() => DeviceEntity, (device) => device.permission, {
|
||||
nullable: false,
|
||||
})
|
||||
device: DeviceEntity;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
constructor(partial: Partial<DeviceNotificationEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'device-user-permission' })
|
||||
@Unique(['userUuid', 'deviceUuid'])
|
||||
export class DeviceUserPermissionEntity extends AbstractEntity<DeviceUserPermissionDto> {
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public userUuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
deviceUuid: string;
|
||||
|
||||
@ManyToOne(() => DeviceEntity, (device) => device.permission, {
|
||||
nullable: false,
|
||||
})
|
||||
device: DeviceEntity;
|
||||
|
||||
@ManyToOne(
|
||||
() => PermissionTypeEntity,
|
||||
(permissionType) => permissionType.permission,
|
||||
{
|
||||
nullable: false,
|
||||
},
|
||||
)
|
||||
permissionType: PermissionTypeEntity;
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
constructor(partial: Partial<DeviceUserPermissionEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DeviceEntity } from '../entities';
|
||||
import {
|
||||
DeviceEntity,
|
||||
DeviceNotificationEntity,
|
||||
DeviceUserPermissionEntity,
|
||||
} from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceRepository extends Repository<DeviceEntity> {
|
||||
@ -8,3 +12,15 @@ export class DeviceRepository extends Repository<DeviceEntity> {
|
||||
super(DeviceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class DeviceNotificationRepository extends Repository<DeviceNotificationEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(DeviceNotificationEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class DeviceUserPermissionRepository extends Repository<DeviceUserPermissionEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(DeviceUserPermissionEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user