80 lines
1.8 KiB
TypeScript
80 lines
1.8 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 { BomStore } from './bom.store';
|
|
import {
|
|
bomListQuery,
|
|
createBomSchema,
|
|
type BomListQuery,
|
|
type CreateBomInput,
|
|
} from './bom.schemas';
|
|
|
|
@Controller('variants/:variantId/boms')
|
|
export class VariantBomsController {
|
|
constructor(private readonly boms: BomStore) {}
|
|
|
|
@Get()
|
|
@RequirePermission('bom.read')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('variantId', ParseUUIDPipe) variantId: string,
|
|
@Query(new SchemaPipe(bomListQuery)) query: BomListQuery,
|
|
) {
|
|
return this.boms.list(actor, variantId, query);
|
|
}
|
|
|
|
@Get('active')
|
|
@RequirePermission('bom.read')
|
|
active(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('variantId', ParseUUIDPipe) variantId: string,
|
|
) {
|
|
return this.boms.active(actor, variantId);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermission('bom.manage')
|
|
create(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('variantId', ParseUUIDPipe) variantId: string,
|
|
@Body(new SchemaPipe(createBomSchema)) input: CreateBomInput,
|
|
) {
|
|
return this.boms.create(actor, variantId, input);
|
|
}
|
|
}
|
|
|
|
@Controller('boms')
|
|
export class BomsController {
|
|
constructor(private readonly boms: BomStore) {}
|
|
|
|
@Get(':id')
|
|
@RequirePermission('bom.read')
|
|
find(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.boms.find(actor, id);
|
|
}
|
|
|
|
@Post(':id/activate')
|
|
@RequirePermission('bom.manage')
|
|
activate(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.boms.activate(actor, id);
|
|
}
|
|
}
|