perms
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
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 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { Permissions } from 'src/modules/auth/decorators/permissions.decorator';
|
||||
import { RestId } from 'src/common/decorators';
|
||||
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
||||
|
||||
@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 that the admin has' })
|
||||
@ApiResponse({ status: 200, description: 'Permissions retrieved successfully' })
|
||||
async findAllPermissions(@AdminId() adminId: string, @RestId() restId: string) {
|
||||
const adminPermissionNames = await this.permissionService.getFullAdminPermissions(adminId, restId);
|
||||
|
||||
return adminPermissionNames;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user