added exception filter and removed controller error handling

This commit is contained in:
unknown
2024-10-06 11:04:25 +03:00
26 changed files with 780 additions and 1345 deletions
+8 -30
View File
@@ -1,13 +1,5 @@
import { GroupService } from '../services/group.service';
import {
Controller,
Get,
UseGuards,
Param,
HttpException,
HttpStatus,
Req,
} from '@nestjs/common';
import { Controller, Get, UseGuards, Param, Req } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
import { UnitPermissionGuard } from 'src/guards/unit.permission.guard';
@@ -24,14 +16,7 @@ export class GroupController {
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
@Get(':unitUuid')
async getGroupsBySpaceUuid(@Param('unitUuid') unitUuid: string) {
try {
return await this.groupService.getGroupsByUnitUuid(unitUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.groupService.getGroupsByUnitUuid(unitUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
@@ -41,19 +26,12 @@ export class GroupController {
@Param('groupName') groupName: string,
@Req() req: any,
) {
try {
const userUuid = req.user.uuid;
const userUuid = req.user.uuid;
return await this.groupService.getUnitDevicesByGroupName(
unitUuid,
groupName,
userUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.groupService.getUnitDevicesByGroupName(
unitUuid,
groupName,
userUuid,
);
}
}