mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 03:34:55 +00:00
disabling space
This commit is contained in:
@ -41,7 +41,7 @@ import {
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
||||
import { In } from 'typeorm';
|
||||
import { In, QueryRunner } from 'typeorm';
|
||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { DeviceStatusFirebaseService } from '@app/common/firebase/devices-status/services/devices-status.service';
|
||||
@ -59,6 +59,7 @@ import { DeviceSceneParamDto } from '../dtos/device.param.dto';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { DeleteSceneFromSceneDeviceDto } from '../dtos/delete.device.dto';
|
||||
import { DeviceEntity } from '@app/common/modules/device/entities';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceService {
|
||||
@ -83,6 +84,7 @@ export class DeviceService {
|
||||
secretKey,
|
||||
});
|
||||
}
|
||||
|
||||
async getDeviceByDeviceUuid(
|
||||
deviceUuid: string,
|
||||
withProductDevice: boolean = true,
|
||||
@ -98,6 +100,29 @@ export class DeviceService {
|
||||
relations,
|
||||
});
|
||||
}
|
||||
async deleteDevice(
|
||||
devices: DeviceEntity[],
|
||||
orphanSpace: SpaceEntity,
|
||||
queryRunner: QueryRunner,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const deviceIds = devices.map((device) => device.uuid);
|
||||
|
||||
if (deviceIds.length > 0) {
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.update(DeviceEntity)
|
||||
.set({ spaceDevice: orphanSpace })
|
||||
.whereInIds(deviceIds)
|
||||
.execute();
|
||||
}
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
`Failed to update devices to orphan space: ${error.message}`,
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async getDeviceByDeviceTuyaUuid(deviceTuyaUuid: string) {
|
||||
return await this.deviceRepository.findOne({
|
||||
|
||||
Reference in New Issue
Block a user