57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { SchemaPipe } from '../common/validation.pipe';
|
|
import { CurrentPrincipal, RequirePermission } from './access.decorator';
|
|
import { RoleStore } from './role.store';
|
|
import { PERMISSIONS } from './permissions';
|
|
import {
|
|
pageSchema,
|
|
roleSchema,
|
|
type PageInput,
|
|
type RoleInput,
|
|
} from './identity.schemas';
|
|
import type { Principal } from './identity.types';
|
|
|
|
@Controller('roles')
|
|
export class RolesController {
|
|
constructor(private readonly roles: RoleStore) {}
|
|
@Get('permissions')
|
|
@RequirePermission('roles.read')
|
|
permissions() {
|
|
return PERMISSIONS;
|
|
}
|
|
@Get()
|
|
@RequirePermission('roles.read')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Query(new SchemaPipe(pageSchema)) page: PageInput,
|
|
) {
|
|
return this.roles.list(actor, page);
|
|
}
|
|
@Post()
|
|
@RequirePermission('roles.manage')
|
|
create(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Body(new SchemaPipe(roleSchema)) input: RoleInput,
|
|
) {
|
|
return this.roles.save(actor, input);
|
|
}
|
|
@Patch(':id')
|
|
@RequirePermission('roles.manage')
|
|
update(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(roleSchema)) input: RoleInput,
|
|
) {
|
|
return this.roles.save(actor, input, id);
|
|
}
|
|
}
|