83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { SchemaPipe } from '../common/validation.pipe';
|
|
import {
|
|
CurrentPrincipal,
|
|
RequirePermission,
|
|
} from '../identity/access.decorator';
|
|
import type { Principal } from '../identity/identity.types';
|
|
import { SampleActionStore } from './sample-action.store';
|
|
import { SampleStore } from './sample.store';
|
|
import {
|
|
sampleDecisionSchema,
|
|
sampleDispatchSchema,
|
|
sampleQuerySchema,
|
|
sampleRequestSchema,
|
|
type SampleDecisionInput,
|
|
type SampleDispatchInput,
|
|
type SampleQuery,
|
|
type SampleRequestInput,
|
|
} from './sample.schemas';
|
|
|
|
@Controller('b2b/samples')
|
|
export class SamplesController {
|
|
constructor(
|
|
private readonly samples: SampleStore,
|
|
private readonly actions: SampleActionStore,
|
|
) {}
|
|
|
|
@Get()
|
|
@RequirePermission('b2b.sample.read')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Query(new SchemaPipe(sampleQuerySchema)) query: SampleQuery,
|
|
) {
|
|
return this.samples.list(actor, query);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermission('b2b.sample.request')
|
|
request(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Body(new SchemaPipe(sampleRequestSchema)) input: SampleRequestInput,
|
|
) {
|
|
return this.samples.request(actor, input);
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePermission('b2b.sample.read')
|
|
get(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.samples.get(actor, id);
|
|
}
|
|
|
|
@Post(':id/decision')
|
|
@RequirePermission('b2b.sample.review')
|
|
decide(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(sampleDecisionSchema)) input: SampleDecisionInput,
|
|
) {
|
|
return this.actions.decide(actor, id, input);
|
|
}
|
|
|
|
@Post(':id/dispatch')
|
|
@RequirePermission('b2b.sample.dispatch')
|
|
dispatch(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(sampleDispatchSchema)) input: SampleDispatchInput,
|
|
) {
|
|
return this.actions.dispatch(actor, id, input);
|
|
}
|
|
}
|