- Add import module with CSV/Excel template download and bulk import endpoints - Support client+subscription and outstanding invoice imports with per-row error handling - Templates include Field Guide sheet with valid plan/area names - Add manager role to unremitted payments endpoint - Add createdAt field to remittance history response
89 lines
2.7 KiB
TypeScript
89 lines
2.7 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', 'manager')
|
|
async getUnremitted(@CurrentUser() user: CurrentUserPayload) {
|
|
const isManager = user.roles?.some((r: string) => ['manager', 'tenant_admin', 'super_admin'].includes(r));
|
|
return this.paymentService.getUnremittedPayments(user.tenantId, isManager ? null : 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);
|
|
}
|
|
|
|
@Get('unremitted-breakdown')
|
|
@Roles('manager')
|
|
async getUnremittedBreakdown(@CurrentUser() user: CurrentUserPayload) {
|
|
return this.paymentService.getUnremittedBreakdown(user.tenantId);
|
|
}
|
|
}
|