Add Role Module with Role Controller, Service, and DTOs

This commit is contained in:
faris Aljohari
2024-05-06 23:49:09 +03:00
parent 1dcb0a3052
commit a093fd3f72
8 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,58 @@
import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Put,
UseGuards,
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { RoleService } from '../services/role.service';
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
import { UserRoleEditDto } from '../dtos';
@ApiTags('Role Module')
@Controller({
version: '1',
path: 'role',
})
export class RoleController {
constructor(private readonly roleService: RoleService) {}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@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);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Put('edit/user/:userUuid')
async editUserRoleType(
@Param('userUuid') userUuid: string,
@Body() userRoleEditDto: UserRoleEditDto,
) {
try {
await this.roleService.editUserRoleType(userUuid, userRoleEditDto);
return {
statusCode: HttpStatus.OK,
message: 'User Role Updated Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}