mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +00:00
Merge pull request #28 from SyncrowIOT/fixes-some-issues-spaces-and-devices
Fixes some issues spaces and devices
This commit is contained in:
@ -32,8 +32,8 @@ export class BuildingController {
|
||||
@Post()
|
||||
async addBuilding(@Body() addBuildingDto: AddBuildingDto) {
|
||||
try {
|
||||
await this.buildingService.addBuilding(addBuildingDto);
|
||||
return { message: 'Building added successfully' };
|
||||
const building = await this.buildingService.addBuilding(addBuildingDto);
|
||||
return { message: 'Building added successfully', uuid: building.uuid };
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
||||
@ -38,11 +38,12 @@ export class BuildingService {
|
||||
if (!spaceType) {
|
||||
throw new BadRequestException('Invalid building UUID');
|
||||
}
|
||||
await this.spaceRepository.save({
|
||||
const building = await this.spaceRepository.save({
|
||||
spaceName: addBuildingDto.buildingName,
|
||||
parent: { uuid: addBuildingDto.communityUuid },
|
||||
spaceType: { uuid: spaceType.uuid },
|
||||
});
|
||||
return building;
|
||||
} catch (err) {
|
||||
if (err instanceof BadRequestException) {
|
||||
throw err; // Re-throw BadRequestException
|
||||
|
||||
@ -34,8 +34,9 @@ export class CommunityController {
|
||||
@Post()
|
||||
async addCommunity(@Body() addCommunityDto: AddCommunityDto) {
|
||||
try {
|
||||
const community =
|
||||
await this.communityService.addCommunity(addCommunityDto);
|
||||
return { message: 'Community added successfully' };
|
||||
return { message: 'Community added successfully', uuid: community.uuid };
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
||||
@ -34,10 +34,11 @@ export class CommunityService {
|
||||
},
|
||||
});
|
||||
|
||||
await this.spaceRepository.save({
|
||||
const community = await this.spaceRepository.save({
|
||||
spaceName: addCommunityDto.communityName,
|
||||
spaceType: { uuid: spaceType.uuid },
|
||||
});
|
||||
return community;
|
||||
} catch (err) {
|
||||
throw new HttpException(err.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { ProductRepository } from './../../../libs/common/src/modules/product/repositories/product.repository';
|
||||
import {
|
||||
Injectable,
|
||||
HttpException,
|
||||
@ -33,6 +34,7 @@ export class DeviceService {
|
||||
private readonly configService: ConfigService,
|
||||
private readonly deviceRepository: DeviceRepository,
|
||||
private readonly groupDeviceRepository: GroupDeviceRepository,
|
||||
private readonly productRepository: ProductRepository,
|
||||
) {
|
||||
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
||||
const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
|
||||
@ -247,18 +249,17 @@ export class DeviceService {
|
||||
|
||||
// Convert keys to camel case
|
||||
const camelCaseResponse = convertKeysToCamelCase(response);
|
||||
const deviceDetails = await this.deviceRepository.findOne({
|
||||
const product = await this.productRepository.findOne({
|
||||
where: {
|
||||
deviceTuyaUuid: deviceId,
|
||||
prodId: camelCaseResponse.result.productId,
|
||||
},
|
||||
relations: ['productDevice'],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { productName, productId, ...rest } = camelCaseResponse.result;
|
||||
return {
|
||||
...rest,
|
||||
productUuid: deviceDetails.productDevice.uuid,
|
||||
productUuid: product.uuid,
|
||||
} as GetDeviceDetailsInterface;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
|
||||
@ -32,8 +32,8 @@ export class FloorController {
|
||||
@Post()
|
||||
async addFloor(@Body() addFloorDto: AddFloorDto) {
|
||||
try {
|
||||
await this.floorService.addFloor(addFloorDto);
|
||||
return { message: 'Floor added successfully' };
|
||||
const floor = await this.floorService.addFloor(addFloorDto);
|
||||
return { message: 'Floor added successfully', uuid: floor.uuid };
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
||||
@ -35,11 +35,12 @@ export class FloorService {
|
||||
},
|
||||
});
|
||||
|
||||
await this.spaceRepository.save({
|
||||
const floor = await this.spaceRepository.save({
|
||||
spaceName: addFloorDto.floorName,
|
||||
parent: { uuid: addFloorDto.buildingUuid },
|
||||
spaceType: { uuid: spaceType.uuid },
|
||||
});
|
||||
return floor;
|
||||
} catch (err) {
|
||||
throw new HttpException(err.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ -30,8 +30,8 @@ export class RoomController {
|
||||
@Post()
|
||||
async addRoom(@Body() addRoomDto: AddRoomDto) {
|
||||
try {
|
||||
await this.roomService.addRoom(addRoomDto);
|
||||
return { message: 'Room added successfully' };
|
||||
const room = await this.roomService.addRoom(addRoomDto);
|
||||
return { message: 'Room added successfully', uuid: room.uuid };
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
||||
@ -32,11 +32,12 @@ export class RoomService {
|
||||
},
|
||||
});
|
||||
|
||||
await this.spaceRepository.save({
|
||||
const room = await this.spaceRepository.save({
|
||||
spaceName: addRoomDto.roomName,
|
||||
parent: { uuid: addRoomDto.unitUuid },
|
||||
spaceType: { uuid: spaceType.uuid },
|
||||
});
|
||||
return room;
|
||||
} catch (err) {
|
||||
throw new HttpException(err.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ -32,8 +32,8 @@ export class UnitController {
|
||||
@Post()
|
||||
async addUnit(@Body() addUnitDto: AddUnitDto) {
|
||||
try {
|
||||
await this.unitService.addUnit(addUnitDto);
|
||||
return { message: 'Unit added successfully' };
|
||||
const unit = await this.unitService.addUnit(addUnitDto);
|
||||
return { message: 'Unit added successfully', uuid: unit.uuid };
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
|
||||
@ -35,11 +35,12 @@ export class UnitService {
|
||||
},
|
||||
});
|
||||
|
||||
await this.spaceRepository.save({
|
||||
const unit = await this.spaceRepository.save({
|
||||
spaceName: addUnitDto.unitName,
|
||||
parent: { uuid: addUnitDto.floorUuid },
|
||||
spaceType: { uuid: spaceType.uuid },
|
||||
});
|
||||
return unit;
|
||||
} catch (err) {
|
||||
throw new HttpException(err.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user