Files
fiberops-api/src/invoice/invoice.controller.ts
kevin-asprec c14521a41d fix: add collector role to API endpoints for mobile dashboard access
Collector users were blocked from ticket, payment, invoice, and client
endpoints requiring 'technician' role. Added 'collector' to @Roles
decorators and the COLLECTOR role to the shared role hierarchy.
2026-05-06 02:15:20 +08:00

59 lines
1.6 KiB
TypeScript

import {
Controller,
Get,
Post,
Patch,
Param,
Query,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { InvoiceService } from './invoice.service';
import { Roles } from '../common/decorators/roles.decorator';
import { RolesGuard } from '../common/guards/roles.guard';
import { TenantGuard } from '../common/guards/tenant.guard';
import { CurrentUser, CurrentUserPayload } from '../common/decorators/current-user.decorator';
@Controller('invoices')
@UseGuards(AuthGuard('jwt'), TenantGuard, RolesGuard)
export class InvoiceController {
constructor(private readonly invoiceService: InvoiceService) {}
@Get()
@Roles('technician', 'collector')
async findAll(
@CurrentUser() user: CurrentUserPayload,
@Query('clientId') clientId?: string,
@Query('status') status?: string,
) {
return this.invoiceService.findAll(user.tenantId, { clientId, status });
}
@Get(':id')
@Roles('technician', 'collector')
async findById(
@CurrentUser() user: CurrentUserPayload,
@Param('id') id: string,
) {
return this.invoiceService.findById(user.tenantId, id);
}
@Post('generate/:clientId')
@Roles('manager')
async generate(
@CurrentUser() user: CurrentUserPayload,
@Param('clientId') clientId: string,
) {
return this.invoiceService.generateForClient(user.tenantId, clientId);
}
@Patch(':id/void')
@Roles('tenant_admin')
async voidInvoice(
@CurrentUser() user: CurrentUserPayload,
@Param('id') id: string,
) {
return this.invoiceService.voidInvoice(user.tenantId, id);
}
}