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