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 { CreditStore } from './credit.store';
|
|
import { CreditReviewStore } from './credit-review.store';
|
|
import {
|
|
creditDecisionSchema,
|
|
creditQuerySchema,
|
|
proposeCreditSchema,
|
|
suspendCreditSchema,
|
|
type CreditDecisionInput,
|
|
type CreditQuery,
|
|
type ProposeCreditInput,
|
|
type SuspendCreditInput,
|
|
} from './credit.schemas';
|
|
|
|
@Controller('b2b/credit-policies')
|
|
export class CreditPoliciesController {
|
|
constructor(
|
|
private readonly policies: CreditStore,
|
|
private readonly reviews: CreditReviewStore,
|
|
) {}
|
|
|
|
@Get()
|
|
@RequirePermission('b2b.credit.read')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Query(new SchemaPipe(creditQuerySchema)) query: CreditQuery,
|
|
) {
|
|
return this.policies.list(actor, query);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermission('b2b.credit.propose')
|
|
propose(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Body(new SchemaPipe(proposeCreditSchema)) input: ProposeCreditInput,
|
|
) {
|
|
return this.policies.propose(actor, input);
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePermission('b2b.credit.read')
|
|
get(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.policies.get(actor, id);
|
|
}
|
|
|
|
@Post(':id/decision')
|
|
@RequirePermission('b2b.credit.review')
|
|
review(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(creditDecisionSchema)) input: CreditDecisionInput,
|
|
) {
|
|
return this.reviews.review(actor, id, input);
|
|
}
|
|
|
|
@Post(':id/suspend')
|
|
@RequirePermission('b2b.credit.review')
|
|
suspend(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(suspendCreditSchema)) input: SuspendCreditInput,
|
|
) {
|
|
return this.reviews.suspend(actor, id, input);
|
|
}
|
|
}
|