-
Notifications
You must be signed in to change notification settings - Fork 6
refactor(admin-roles): migrate from server #2205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import type { AdminRole } from '@cpn-console/shared' | ||
| import { adminRoleContract } from '@cpn-console/shared' | ||
| import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Inject, Param, ParseUUIDPipe, Patch, Post, UseGuards } from '@nestjs/common' | ||
| import { RequireAdminPermission } from '../infrastructure/permission/user/user-admin-permission.decorator' | ||
| import { UserGuard } from '../infrastructure/permission/user/user.guard' | ||
| import { ZodValidationPipe } from '../infrastructure/pipe/zod-validation.pipe' | ||
| import { AdminRoleService } from './admin-role.service' | ||
|
|
||
| @Controller('api/v1/admin/roles') | ||
| export class AdminRoleController { | ||
| constructor( | ||
| @Inject(AdminRoleService) private readonly adminRoleService: AdminRoleService, | ||
| ) {} | ||
|
|
||
| @Get('') | ||
| @UseGuards(UserGuard) | ||
| // TODO: ListRoles is intentionally not protected by admin permission because of | ||
|
Check notice on line 17 in apps/server-nestjs/src/modules/admin-role/admin-role.controller.ts
|
||
| // certain behaviours of the legacy client | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: On a identifié ce sujet dans un ticket de backlog ? Car je sens que ça va passer à la trappe et rester un TODO sur un sujet sensible... |
||
| // @RequireAdminPermission('ListRoles') | ||
| async listAdminRoles(): Promise<AdminRole[]> { | ||
| return this.adminRoleService.list() | ||
| } | ||
|
|
||
| @Post('') | ||
| @HttpCode(HttpStatus.CREATED) | ||
| @UseGuards(UserGuard) | ||
| @RequireAdminPermission('ManageRoles') | ||
| async createAdminRole( | ||
| @Body(new ZodValidationPipe(adminRoleContract.createAdminRole.body)) body: typeof adminRoleContract.createAdminRole.body._type, | ||
| ): Promise<AdminRole> { | ||
| return this.adminRoleService.create(body) | ||
| } | ||
|
|
||
| @Patch('') | ||
| @HttpCode(HttpStatus.OK) | ||
| @UseGuards(UserGuard) | ||
| @RequireAdminPermission('ManageRoles') | ||
| async patchAdminRoles( | ||
| @Body(new ZodValidationPipe(adminRoleContract.patchAdminRoles.body)) body: typeof adminRoleContract.patchAdminRoles.body._type, | ||
| ): Promise<AdminRole[]> { | ||
| return this.adminRoleService.patch(body) | ||
| } | ||
|
|
||
| @Get('member-counts') | ||
| @UseGuards(UserGuard) | ||
| @RequireAdminPermission('ManageRoles') | ||
| async adminRoleMemberCounts(): Promise<Record<string, number>> { | ||
| return this.adminRoleService.memberCounts() | ||
| } | ||
|
|
||
| @Delete(':roleId') | ||
| @HttpCode(HttpStatus.NO_CONTENT) | ||
| @UseGuards(UserGuard) | ||
| @RequireAdminPermission('ManageRoles') | ||
| async deleteAdminRole( | ||
| @Param('roleId', ParseUUIDPipe) roleId: string, | ||
| ): Promise<void> { | ||
| await this.adminRoleService.delete(roleId) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Module } from '@nestjs/common' | ||
| import { AuthModule } from '../infrastructure/auth/auth.module' | ||
| import { InfrastructureModule } from '../infrastructure/infrastructure.module' | ||
| import { AdminRoleController } from './admin-role.controller' | ||
| import { AdminRoleService } from './admin-role.service' | ||
|
|
||
| @Module({ | ||
| imports: [InfrastructureModule, AuthModule], | ||
| controllers: [AdminRoleController], | ||
| providers: [AdminRoleService], | ||
| exports: [AdminRoleService], | ||
| }) | ||
| export class AdminRoleModule {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: Le site s'est fait highjacked, apparemment: https://progress-bar.dev/24/?title=modularisation&width=400 😓
Faudrait virer ça, c'était gadget de toute façon