mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 11:07:55 +00:00
Refactor controllers to return UUID of added entities
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
|
||||
|
||||
Reference in New Issue
Block a user