Refactor controllers to return UUID of added entities

This commit is contained in:
faris Aljohari
2024-05-01 10:34:07 +03:00
parent 229909f959
commit d146cce1bb
10 changed files with 21 additions and 15 deletions
+2 -2
View File
@@ -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',
+2 -1
View File
@@ -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);
}