70 lines
2.7 KiB
TypeScript
70 lines
2.7 KiB
TypeScript
import { Controller, Get, Post, Body, Param, Patch, Delete, Query, UseGuards } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBody, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { RolesService } from './providers/roles.service';
|
|
import { PermissionsService } from './providers/permissions.service';
|
|
import { CreateRoleDto } from './dto/create-role.dto';
|
|
import { UpdateRoleDto } from './dto/update-role.dto';
|
|
import { FindRolesDto } from './dto/find-roles.dto';
|
|
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
|
import { Permissions } from '../auth/decorators/permissions.decorator';
|
|
import { RestId } from 'src/common/decorators';
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiTags('admin/roles')
|
|
@Controller('admin/roles')
|
|
export class RolesController {
|
|
constructor(
|
|
private readonly roleService: RolesService,
|
|
private readonly permissionService: PermissionsService,
|
|
) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get all roles with pagination and filters' })
|
|
@ApiResponse({ status: 200, description: 'Roles retrieved successfully' })
|
|
findAll(@Query() dto: FindRolesDto, @RestId() restId: string) {
|
|
return this.roleService.findAll(restId, dto);
|
|
}
|
|
|
|
@Get('permissions')
|
|
@ApiOperation({ summary: 'Get all permissions' })
|
|
@ApiResponse({ status: 200, description: 'Permissions retrieved successfully' })
|
|
findAllPermissions() {
|
|
return this.permissionService.findAll();
|
|
}
|
|
|
|
@Permissions('create-role')
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create a new role' })
|
|
@ApiBody({ type: CreateRoleDto })
|
|
@ApiResponse({ status: 201, description: 'Role created successfully' })
|
|
create(@Body() dto: CreateRoleDto, @RestId() restId: string) {
|
|
return this.roleService.create(restId, dto);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get a specific role by ID' })
|
|
@ApiResponse({ status: 200, description: 'Role retrieved successfully' })
|
|
@ApiResponse({ status: 404, description: 'Role not found' })
|
|
findOne(@Param('id') id: string, @RestId() restId: string) {
|
|
return this.roleService.findOne(restId, id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Update a role' })
|
|
@ApiBody({ type: UpdateRoleDto })
|
|
@ApiResponse({ status: 200, description: 'Role updated successfully' })
|
|
@ApiResponse({ status: 404, description: 'Role not found' })
|
|
update(@Param('id') id: string, @Body() dto: UpdateRoleDto, @RestId() restId: string) {
|
|
return this.roleService.update(restId, id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: 'Delete a role' })
|
|
@ApiResponse({ status: 200, description: 'Role deleted successfully' })
|
|
@ApiResponse({ status: 404, description: 'Role not found' })
|
|
remove(@Param('id') id: string, @RestId() restId: string) {
|
|
return this.roleService.remove(restId, id);
|
|
}
|
|
}
|