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

View File

@ -2,7 +2,6 @@ import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Post,
UseGuards,
@ -23,32 +22,21 @@ export class RoleController {
@UseGuards(SuperAdminRoleGuard)
@Get('types')
async fetchRoleTypes() {
try {
const roleTypes = await this.roleService.fetchRoleTypes();
return {
statusCode: HttpStatus.OK,
message: 'Role Types fetched Successfully',
data: roleTypes,
};
} catch (err) {
throw new Error(err);
}
const roleTypes = await this.roleService.fetchRoleTypes();
return {
statusCode: HttpStatus.OK,
message: 'Role Types fetched Successfully',
data: roleTypes,
};
}
@ApiBearerAuth()
@UseGuards(SuperAdminRoleGuard)
@Post()
async addUserRoleType(@Body() addUserRoleDto: AddUserRoleDto) {
try {
await this.roleService.addUserRoleType(addUserRoleDto);
return {
statusCode: HttpStatus.OK,
message: 'User Role Added Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.roleService.addUserRoleType(addUserRoleDto);
return {
statusCode: HttpStatus.OK,
message: 'User Role Added Successfully',
};
}
}