mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +00:00
Merge pull request #34 from SyncrowIOT/fixed-device-room-service
Fixed device room service
This commit is contained in:
@ -34,7 +34,12 @@ export class BuildingController {
|
||||
async addBuilding(@Body() addBuildingDto: AddBuildingDto) {
|
||||
try {
|
||||
const building = await this.buildingService.addBuilding(addBuildingDto);
|
||||
return { message: 'Building added successfully', uuid: building.uuid };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Building added successfully',
|
||||
data: building,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
@ -100,7 +105,11 @@ export class BuildingController {
|
||||
async addUserBuilding(@Body() addUserBuildingDto: AddUserBuildingDto) {
|
||||
try {
|
||||
await this.buildingService.addUserBuilding(addUserBuildingDto);
|
||||
return { message: 'user building added successfully' };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user building added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
@ -37,7 +37,12 @@ export class CommunityController {
|
||||
try {
|
||||
const community =
|
||||
await this.communityService.addCommunity(addCommunityDto);
|
||||
return { message: 'Community added successfully', uuid: community.uuid };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Community added successfully',
|
||||
data: community,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
@ -102,7 +107,11 @@ export class CommunityController {
|
||||
async addUserCommunity(@Body() addUserCommunityDto: AddUserCommunityDto) {
|
||||
try {
|
||||
await this.communityService.addUserCommunity(addUserCommunityDto);
|
||||
return { message: 'user community added successfully' };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user community added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
@ -61,7 +61,15 @@ export class DeviceController {
|
||||
@Post('room')
|
||||
async addDeviceInRoom(@Body() addDeviceInRoomDto: AddDeviceInRoomDto) {
|
||||
try {
|
||||
return await this.deviceService.addDeviceInRoom(addDeviceInRoomDto);
|
||||
const device =
|
||||
await this.deviceService.addDeviceInRoom(addDeviceInRoomDto);
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'device added in room successfully',
|
||||
data: device,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
@ -27,6 +27,7 @@ import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
import { GroupDeviceRepository } from '@app/common/modules/group-device/repositories';
|
||||
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
||||
import { In } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceService {
|
||||
@ -57,7 +58,7 @@ export class DeviceService {
|
||||
permission: {
|
||||
userUuid,
|
||||
permissionType: {
|
||||
type: PermissionType.READ || PermissionType.CONTROLLABLE,
|
||||
type: In([PermissionType.READ, PermissionType.CONTROLLABLE]),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -81,6 +82,7 @@ export class DeviceService {
|
||||
} as GetDeviceDetailsInterface;
|
||||
}),
|
||||
);
|
||||
|
||||
return devicesData;
|
||||
} catch (error) {
|
||||
// Handle the error here
|
||||
@ -147,12 +149,11 @@ export class DeviceService {
|
||||
throw new Error('Product UUID is missing for the device.');
|
||||
}
|
||||
|
||||
await this.deviceRepository.save({
|
||||
return await this.deviceRepository.save({
|
||||
deviceTuyaUuid: addDeviceInRoomDto.deviceTuyaUuid,
|
||||
spaceDevice: { uuid: addDeviceInRoomDto.roomUuid },
|
||||
productDevice: { uuid: device.productUuid },
|
||||
});
|
||||
return { message: 'device added in room successfully' };
|
||||
} catch (error) {
|
||||
if (error.code === '23505') {
|
||||
throw new HttpException(
|
||||
|
@ -34,7 +34,12 @@ export class FloorController {
|
||||
async addFloor(@Body() addFloorDto: AddFloorDto) {
|
||||
try {
|
||||
const floor = await this.floorService.addFloor(addFloorDto);
|
||||
return { message: 'Floor added successfully', uuid: floor.uuid };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Floor added successfully',
|
||||
data: floor,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
@ -99,7 +104,11 @@ export class FloorController {
|
||||
async addUserFloor(@Body() addUserFloorDto: AddUserFloorDto) {
|
||||
try {
|
||||
await this.floorService.addUserFloor(addUserFloorDto);
|
||||
return { message: 'user floor added successfully' };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user floor added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
@ -32,7 +32,12 @@ export class RoomController {
|
||||
async addRoom(@Body() addRoomDto: AddRoomDto) {
|
||||
try {
|
||||
const room = await this.roomService.addRoom(addRoomDto);
|
||||
return { message: 'Room added successfully', uuid: room.uuid };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Room added successfully',
|
||||
data: room,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
@ -76,7 +81,11 @@ export class RoomController {
|
||||
async addUserRoom(@Body() addUserRoomDto: AddUserRoomDto) {
|
||||
try {
|
||||
await this.roomService.addUserRoom(addUserRoomDto);
|
||||
return { message: 'user room added successfully' };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user room added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
@ -34,7 +34,12 @@ export class UnitController {
|
||||
async addUnit(@Body() addUnitDto: AddUnitDto) {
|
||||
try {
|
||||
const unit = await this.unitService.addUnit(addUnitDto);
|
||||
return { message: 'Unit added successfully', uuid: unit.uuid };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Unit added successfully',
|
||||
data: unit,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
@ -95,7 +100,11 @@ export class UnitController {
|
||||
async addUserUnit(@Body() addUserUnitDto: AddUserUnitDto) {
|
||||
try {
|
||||
await this.unitService.addUserUnit(addUserUnitDto);
|
||||
return { message: 'user unit added successfully' };
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user unit added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
Reference in New Issue
Block a user