mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +00:00
Add Role Module with Role Controller, Service, and DTOs
This commit is contained in:
58
src/role/controllers/role.controller.ts
Normal file
58
src/role/controllers/role.controller.ts
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user