70 lines
2.0 KiB
TypeScript
70 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 { pageSchema, type PageInput } from '../identity/identity.schemas';
|
|
import type { Principal } from '../identity/identity.types';
|
|
import { SupplierPaymentStore } from './supplier-payment.store';
|
|
import {
|
|
supplierPaymentSchema,
|
|
supplierPaymentReversalSchema,
|
|
type SupplierPaymentInput,
|
|
type SupplierPaymentReversalInput,
|
|
} from './supplier-payment.schemas';
|
|
|
|
@Controller('supplier-invoices/:invoiceId/payments')
|
|
export class InvoicePaymentsController {
|
|
constructor(private readonly payments: SupplierPaymentStore) {}
|
|
@Get()
|
|
@RequirePermission('procurement.read')
|
|
list(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('invoiceId', ParseUUIDPipe) invoiceId: string,
|
|
@Query(new SchemaPipe(pageSchema)) query: PageInput,
|
|
) {
|
|
return this.payments.list(actor, invoiceId, query);
|
|
}
|
|
@Post()
|
|
@RequirePermission('supplier_payment.manage')
|
|
create(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('invoiceId', ParseUUIDPipe) invoiceId: string,
|
|
@Body(new SchemaPipe(supplierPaymentSchema)) input: SupplierPaymentInput,
|
|
) {
|
|
return this.payments.create(actor, invoiceId, input);
|
|
}
|
|
}
|
|
|
|
@Controller('supplier-payments')
|
|
export class SupplierPaymentsController {
|
|
constructor(private readonly payments: SupplierPaymentStore) {}
|
|
@Get(':id')
|
|
@RequirePermission('procurement.read')
|
|
get(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
) {
|
|
return this.payments.find(actor, id);
|
|
}
|
|
@Post(':id/reverse')
|
|
@RequirePermission('supplier_payment.manage')
|
|
reverse(
|
|
@CurrentPrincipal() actor: Principal,
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body(new SchemaPipe(supplierPaymentReversalSchema))
|
|
input: SupplierPaymentReversalInput,
|
|
) {
|
|
return this.payments.reverse(actor, id, input);
|
|
}
|
|
}
|