mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:44:55 +00:00
device start using space
This commit is contained in:
@ -8,7 +8,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { AddDeviceDto, UpdateDeviceInRoomDto } from '../dtos/add.device.dto';
|
||||
import { AddDeviceDto, UpdateDeviceInSpaceDto } from '../dtos/add.device.dto';
|
||||
import {
|
||||
DeviceInstructionResponse,
|
||||
GetDeviceDetailsFunctionsInterface,
|
||||
@ -19,7 +19,7 @@ import {
|
||||
updateDeviceFirmwareInterface,
|
||||
} from '../interfaces/get.device.interface';
|
||||
import {
|
||||
GetDeviceByRoomUuidDto,
|
||||
GetDeviceBySpaceUuidDto,
|
||||
GetDeviceLogsDto,
|
||||
} from '../dtos/get.device.dto';
|
||||
import {
|
||||
@ -69,6 +69,7 @@ export class DeviceService {
|
||||
...(withProductDevice && { relations: ['productDevice'] }),
|
||||
});
|
||||
}
|
||||
|
||||
async getDeviceByDeviceTuyaUuid(deviceTuyaUuid: string) {
|
||||
return await this.deviceRepository.findOne({
|
||||
where: {
|
||||
@ -77,6 +78,7 @@ export class DeviceService {
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
}
|
||||
|
||||
async addDeviceUser(addDeviceDto: AddDeviceDto) {
|
||||
try {
|
||||
const device = await this.getDeviceDetailsByDeviceIdTuya(
|
||||
@ -116,12 +118,13 @@ export class DeviceService {
|
||||
);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Failed to add device in room',
|
||||
error.message || 'Failed to add device in space',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getDevicesByUser(
|
||||
userUuid: string,
|
||||
): Promise<GetDeviceDetailsInterface[]> {
|
||||
@ -168,14 +171,15 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async getDevicesByRoomId(
|
||||
getDeviceByRoomUuidDto: GetDeviceByRoomUuidDto,
|
||||
|
||||
async getDevicesBySpaceId(
|
||||
getDeviceBySpaceUuidDto: GetDeviceBySpaceUuidDto,
|
||||
userUuid: string,
|
||||
): Promise<GetDeviceDetailsInterface[]> {
|
||||
try {
|
||||
const devices = await this.deviceRepository.find({
|
||||
where: {
|
||||
spaceDevice: { uuid: getDeviceByRoomUuidDto.roomUuid },
|
||||
spaceDevice: { uuid: getDeviceBySpaceUuidDto.spaceUuid },
|
||||
isActive: true,
|
||||
permission: {
|
||||
userUuid,
|
||||
@ -210,22 +214,22 @@ export class DeviceService {
|
||||
} catch (error) {
|
||||
// Handle the error here
|
||||
throw new HttpException(
|
||||
'Error fetching devices by room',
|
||||
'Error fetching devices by space',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
async updateDeviceInRoom(updateDeviceInRoomDto: UpdateDeviceInRoomDto) {
|
||||
async updateDeviceInSpace(updateDeviceInSpaceDto: UpdateDeviceInSpaceDto) {
|
||||
try {
|
||||
await this.deviceRepository.update(
|
||||
{ uuid: updateDeviceInRoomDto.deviceUuid },
|
||||
{ uuid: updateDeviceInSpaceDto.deviceUuid },
|
||||
{
|
||||
spaceDevice: { uuid: updateDeviceInRoomDto.roomUuid },
|
||||
spaceDevice: { uuid: updateDeviceInSpaceDto.spaceUuid },
|
||||
},
|
||||
);
|
||||
const device = await this.deviceRepository.findOne({
|
||||
where: {
|
||||
uuid: updateDeviceInRoomDto.deviceUuid,
|
||||
uuid: updateDeviceInSpaceDto.deviceUuid,
|
||||
},
|
||||
relations: ['spaceDevice', 'spaceDevice.parent'],
|
||||
});
|
||||
@ -238,15 +242,16 @@ export class DeviceService {
|
||||
|
||||
return {
|
||||
uuid: device.uuid,
|
||||
roomUuid: device.spaceDevice.uuid,
|
||||
spaceUuid: device.spaceDevice.uuid,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'Failed to add device in room',
|
||||
'Failed to add device in space',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async transferDeviceInSpacesTuya(
|
||||
deviceId: string,
|
||||
spaceId: string,
|
||||
@ -294,6 +299,7 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async factoryResetDeviceTuya(
|
||||
deviceUuid: string,
|
||||
): Promise<controlDeviceInterface> {
|
||||
@ -336,6 +342,7 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async batchControlDevices(batchControlDevicesDto: BatchControlDevicesDto) {
|
||||
const { devicesUuid } = batchControlDevicesDto;
|
||||
|
||||
@ -777,12 +784,12 @@ export class DeviceService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async getDevicesByUnitId(unitUuid: string) {
|
||||
async getDevicesBySpaceUuid(SpaceUuid: string) {
|
||||
try {
|
||||
const spaces = await this.spaceRepository.find({
|
||||
where: {
|
||||
parent: {
|
||||
uuid: unitUuid,
|
||||
uuid: SpaceUuid,
|
||||
},
|
||||
devicesSpaceEntity: {
|
||||
isActive: true,
|
||||
@ -813,7 +820,7 @@ export class DeviceService {
|
||||
return devicesData;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'This unit does not have any devices',
|
||||
'This space does not have any devices',
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
@ -874,16 +881,12 @@ export class DeviceService {
|
||||
}
|
||||
}
|
||||
const spaceDevice = device?.spaceDevice;
|
||||
const parentDevice = spaceDevice?.parent;
|
||||
return {
|
||||
room: {
|
||||
space: {
|
||||
uuid: spaceDevice?.uuid,
|
||||
name: spaceDevice?.spaceName,
|
||||
},
|
||||
unit: {
|
||||
uuid: parentDevice?.uuid,
|
||||
name: parentDevice?.spaceName,
|
||||
},
|
||||
|
||||
productUuid: device.productDevice.uuid,
|
||||
productType: device.productDevice.prodType,
|
||||
permissionType: device.permission[0].permissionType.type,
|
||||
|
||||
Reference in New Issue
Block a user