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.
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Patch,
|
|
Param,
|
|
Body,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { PaymentService } from './payment.service';
|
|
import { RecordPaymentDto } from './dto/record-payment.dto';
|
|
import { CreateRemittanceDto } from './dto/create-remittance.dto';
|
|
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('payments')
|
|
@UseGuards(AuthGuard('jwt'), TenantGuard, RolesGuard)
|
|
export class PaymentController {
|
|
constructor(private readonly paymentService: PaymentService) {}
|
|
|
|
@Get()
|
|
@Roles('technician', 'collector')
|
|
async findAll(
|
|
@CurrentUser() user: CurrentUserPayload,
|
|
@Query('clientId') clientId?: string,
|
|
) {
|
|
return this.paymentService.findAll(user.tenantId, { clientId });
|
|
}
|
|
|
|
@Post()
|
|
@Roles('technician', 'collector')
|
|
async record(
|
|
@CurrentUser() user: CurrentUserPayload,
|
|
@Body() dto: RecordPaymentDto,
|
|
) {
|
|
return this.paymentService.recordPayment(user.tenantId, user.sub, dto);
|
|
}
|
|
|
|
@Get('unremitted')
|
|
@Roles('technician', 'collector')
|
|
async getUnremitted(@CurrentUser() user: CurrentUserPayload, @Query('collectorId') collectorId?: string) {
|
|
return this.paymentService.getUnremittedPayments(user.tenantId, collectorId || user.sub);
|
|
}
|
|
|
|
@Get('remittances')
|
|
@Roles('technician', 'collector')
|
|
async findRemittances(@CurrentUser() user: CurrentUserPayload) {
|
|
return this.paymentService.findRemittances(user.tenantId);
|
|
}
|
|
|
|
@Post('remittances')
|
|
@Roles('technician', 'collector')
|
|
async submitRemittance(
|
|
@CurrentUser() user: CurrentUserPayload,
|
|
@Body() dto: CreateRemittanceDto,
|
|
) {
|
|
return this.paymentService.submitRemittance(user.tenantId, user.sub, dto);
|
|
}
|
|
|
|
@Patch('remittances/:id/confirm')
|
|
@Roles('manager')
|
|
async confirmRemittance(
|
|
@CurrentUser() user: CurrentUserPayload,
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.paymentService.confirmRemittance(user.tenantId, id, user.sub);
|
|
}
|
|
|
|
@Patch('remittances/:id/reject')
|
|
@Roles('manager')
|
|
async rejectRemittance(
|
|
@CurrentUser() user: CurrentUserPayload,
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.paymentService.rejectRemittance(user.tenantId, id, user.sub);
|
|
}
|
|
}
|