Refactor group controller and service for better code organization

This commit is contained in:
faris Aljohari
2024-04-22 10:05:54 +03:00
parent 7abfe29746
commit fc7907d204
3 changed files with 77 additions and 31 deletions
+15 -12
View File
@@ -26,8 +26,8 @@ import { CheckProductUuidForAllDevicesGuard } from 'src/guards/device.product.gu
export class GroupController {
constructor(private readonly groupService: GroupService) {}
// @ApiBearerAuth()
// @UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('space/:spaceUuid')
async getGroupsBySpaceUuid(@Param('spaceUuid') spaceUuid: string) {
try {
@@ -39,8 +39,8 @@ export class GroupController {
);
}
}
// @ApiBearerAuth()
// @UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':groupUuid')
async getGroupsByGroupId(@Param('groupUuid') groupUuid: string) {
try {
@@ -52,8 +52,8 @@ export class GroupController {
);
}
}
// @ApiBearerAuth()
@UseGuards(CheckProductUuidForAllDevicesGuard)
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckProductUuidForAllDevicesGuard)
@Post()
async addGroup(@Body() addGroupDto: AddGroupDto) {
try {
@@ -72,13 +72,16 @@ export class GroupController {
async controlGroup(@Body() controlGroupDto: ControlGroupDto) {
try {
return await this.groupService.controlGroup(controlGroupDto);
} catch (err) {
throw new Error(err);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
// @ApiBearerAuth()
// @UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Put('rename/:groupUuid')
async renameGroupByUuid(
@Param('groupUuid') groupUuid: string,
@@ -97,8 +100,8 @@ export class GroupController {
}
}
// @ApiBearerAuth()
// @UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Delete(':groupUuid')
async deleteGroup(@Param('groupUuid') groupUuid: string) {
try {