import { Body, Controller, Get, Patch } from "@nestjs/common"; import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger"; import { CurrentUser } from "@edr/api-common"; import type { TCurrentUser } from "@tria-plc/api-common/modules/auth/types/current-user.type"; import { BookingStaff } from "../../common/booking-guards"; import { FREIGHT_PERMS } from "../../seed/freight-permissions.registry"; import { UpdateManualPaymentSettingDto } from "./dto/update-manual-payment-setting.dto"; import { ManualPaymentSettingsService } from "./manual-payment-settings.service"; @ApiTags("payment-settings") @ApiBearerAuth() @Controller("payment-settings/manual") export class ManualPaymentSettingsController { constructor(private readonly service: ManualPaymentSettingsService) {} /** * Read is gated on `manual_payment:view`, which Finance also holds — the * Manual Payments worklist reads this to know which currency tabs to offer. */ @Get() @BookingStaff([ FREIGHT_PERMS.settings.manualPayment.view, FREIGHT_PERMS.admin, ]) @ApiOperation({ summary: "Whether manual (offline) invoice settlement is enabled, per currency", }) get() { return this.service.get(); } @Patch() @BookingStaff([ FREIGHT_PERMS.settings.manualPayment.manage, FREIGHT_PERMS.admin, ]) @ApiOperation({ summary: "Enable or disable manual invoice settlement, per currency", }) update( @Body() dto: UpdateManualPaymentSettingDto, @CurrentUser() user: TCurrentUser, ) { return this.service.update(dto, user?.id ?? null); } }