get admins, get system roles,
This commit is contained in:
@@ -5,30 +5,35 @@ import { PermissionsService } from '../providers/permissions.service';
|
||||
import { CreateRoleDto } from '../dto/create-role.dto';
|
||||
import { UpdateRoleDto } from '../dto/update-role.dto';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { SuperAdminAuthGuard } from 'src/modules/auth/guards/superAdminAuth.guard';
|
||||
import { Permissions } from 'src/common/decorators/permissions.decorator';
|
||||
import { RestId } from 'src/common/decorators';
|
||||
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
||||
import { Permission } from 'src/common/enums/permission.enum';
|
||||
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ROLES)
|
||||
@ApiBearerAuth()
|
||||
|
||||
@ApiTags('roles')
|
||||
@Controller('admin/roles')
|
||||
@Controller()
|
||||
export class RolesController {
|
||||
constructor(
|
||||
private readonly roleService: RolesService,
|
||||
private readonly permissionService: PermissionsService,
|
||||
) { }
|
||||
|
||||
@Get()
|
||||
@Get('admin/roles')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ROLES)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get all through restaurant roles with pagination and filters' })
|
||||
findAll(@RestId() restId: string) {
|
||||
return this.roleService.findAllGeneralAndRestaurantRoles(restId);
|
||||
}
|
||||
|
||||
@Get('permissions')
|
||||
@Get('admin/roles/permissions')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ROLES)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get all permissions that the admin has' })
|
||||
async findAllPermissions(@AdminId() adminId: string, @RestId() restId: string) {
|
||||
const adminPermissionNames = await this.permissionService.getAdminFullPermissions(adminId, restId);
|
||||
@@ -36,29 +41,53 @@ export class RolesController {
|
||||
return adminPermissionNames;
|
||||
}
|
||||
|
||||
@Post()
|
||||
|
||||
|
||||
@Post('admin/roles')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ROLES)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Create a new role' })
|
||||
@ApiBody({ type: CreateRoleDto })
|
||||
create(@Body() dto: CreateRoleDto, @RestId() restId: string) {
|
||||
return this.roleService.createRestaurantRole(dto, restId);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@Get('admin/roles/:id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ROLES)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get a specific role by ID' })
|
||||
findOne(@Param('id') id: string, @RestId() restId: string) {
|
||||
return this.roleService.findOne(restId, id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@Patch('admin/roles/:id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ROLES)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Update a role' })
|
||||
@ApiBody({ type: UpdateRoleDto })
|
||||
update(@Param('id') id: string, @Body() dto: UpdateRoleDto, @RestId() restId: string) {
|
||||
return this.roleService.update(restId, id, dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete('admin/roles/:id')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@Permissions(Permission.MANAGE_ROLES)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Delete a role' })
|
||||
remove(@Param('id') id: string, @RestId() restId: string) {
|
||||
return this.roleService.remove(restId, id);
|
||||
}
|
||||
|
||||
/** Super Admin Endpoints */
|
||||
@UseGuards(SuperAdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get all system roles for super-admin' })
|
||||
@Get('super-admin/system-roles')
|
||||
@ApiOperation({ summary: 'Get all system roles for super-admin' })
|
||||
findAllSystemRoles() {
|
||||
return this.roleService.findAllSystemRoles();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user