50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { SchemaPipe } from '../common/validation.pipe';
|
|
import {
|
|
CurrentPrincipal,
|
|
RequirePermission,
|
|
} from '../identity/access.decorator';
|
|
import { pageSchema, type PageInput } from '../identity/identity.schemas';
|
|
import type { Principal } from '../identity/identity.types';
|
|
import { GroupStore } from './group.store';
|
|
import { groupSchema, type GroupInput } from './catalog.schemas';
|
|
|
|
@Controller('catalog-groups')
|
|
export class GroupsController {
|
|
constructor(private readonly groups: GroupStore) {}
|
|
@Get()
|
|
@RequirePermission('catalog.read')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Query(new SchemaPipe(pageSchema)) page: PageInput,
|
|
) {
|
|
return this.groups.list(actor, page);
|
|
}
|
|
@Post()
|
|
@RequirePermission('catalog.manage')
|
|
create(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Body(new SchemaPipe(groupSchema)) input: GroupInput,
|
|
) {
|
|
return this.groups.save(actor, input);
|
|
}
|
|
@Put(':id')
|
|
@RequirePermission('catalog.manage')
|
|
update(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(groupSchema)) input: GroupInput,
|
|
) {
|
|
return this.groups.save(actor, input, id);
|
|
}
|
|
}
|