71 lines
1.7 KiB
TypeScript
71 lines
1.7 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 { QuoteStore } from './quote.store';
|
|
import { QuoteResponseStore } from './quote-response.store';
|
|
import {
|
|
issueQuoteSchema,
|
|
quoteQuerySchema,
|
|
quoteResponseSchema,
|
|
type IssueQuoteInput,
|
|
type QuoteQuery,
|
|
type QuoteResponseInput,
|
|
} from './quote.schemas';
|
|
|
|
@Controller('b2b/quotes')
|
|
export class QuotesController {
|
|
constructor(
|
|
private readonly quotes: QuoteStore,
|
|
private readonly responses: QuoteResponseStore,
|
|
) {}
|
|
|
|
@Get()
|
|
@RequirePermission('b2b.quote.read')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Query(new SchemaPipe(quoteQuerySchema)) query: QuoteQuery,
|
|
) {
|
|
return this.quotes.list(actor, query);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermission('b2b.quote.manage')
|
|
issue(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Body(new SchemaPipe(issueQuoteSchema)) input: IssueQuoteInput,
|
|
) {
|
|
return this.quotes.issue(actor, input);
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePermission('b2b.quote.read')
|
|
get(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.quotes.get(actor, id);
|
|
}
|
|
|
|
@Post(':id/response')
|
|
@RequirePermission('b2b.quote.manage')
|
|
respond(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(quoteResponseSchema)) input: QuoteResponseInput,
|
|
) {
|
|
return this.responses.respond(actor, id, input);
|
|
}
|
|
}
|