56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
import { Controller, Get, Post, Param, Body, Query, UseGuards } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiResponse, ApiQuery } from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
import { RolesGuard } from '../common/guards/roles.guard';
|
|
import { Roles } from '../common/decorators/roles.decorator';
|
|
import { VenueAccessGuard } from '../common/guards/venue-access.guard';
|
|
import { RemindersService } from './reminders.service';
|
|
import { SendRemindersDto } from './dto/send-reminders.dto';
|
|
|
|
@ApiTags('Reminders')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, VenueAccessGuard)
|
|
@Controller('venues/:venueId/reminders')
|
|
export class RemindersController {
|
|
constructor(private service: RemindersService) {}
|
|
|
|
@Get('candidates')
|
|
@ApiOperation({ summary: 'List customers with an unpaid tab and their reminder history' })
|
|
@ApiResponse({ status: 200, description: 'Unpaid tabs with email, amount, reminder count and eligibility' })
|
|
async listCandidates(@Param('venueId') venueId: string) {
|
|
return this.service.listCandidates(venueId);
|
|
}
|
|
|
|
@Post('send')
|
|
@UseGuards(RolesGuard)
|
|
@Roles('admin', 'manager')
|
|
@ApiOperation({ summary: 'Send payment reminders via Resend (admin only)' })
|
|
@ApiResponse({ status: 201, description: 'Reminders sent' })
|
|
@ApiResponse({ status: 400, description: 'Resend not configured' })
|
|
@ApiResponse({ status: 409, description: 'Reminders are already being sent' })
|
|
async send(@Param('venueId') venueId: string, @Body() dto: SendRemindersDto) {
|
|
return this.service.sendReminders(venueId, dto.tabIds);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get reminder history' })
|
|
@ApiQuery({ name: 'customerName', required: false, description: 'Only reminders sent to this customer' })
|
|
@ApiResponse({ status: 200, description: 'List of previously sent reminders' })
|
|
async history(@Param('venueId') venueId: string, @Query('customerName') customerName?: string) {
|
|
return this.service.history(venueId, customerName);
|
|
}
|
|
|
|
@Post('test/:plannedTabId')
|
|
@UseGuards(RolesGuard)
|
|
@Roles('admin', 'manager')
|
|
@ApiOperation({ summary: 'Send a test email to a planned customer (admin only)' })
|
|
@ApiResponse({ status: 201, description: 'Test email sent' })
|
|
@ApiResponse({ status: 400, description: 'Resend not configured or customer has no email' })
|
|
@ApiResponse({ status: 404, description: 'Planned customer not found' })
|
|
async sendTest(
|
|
@Param('venueId') venueId: string,
|
|
@Param('plannedTabId') plannedTabId: string,
|
|
) {
|
|
return this.service.sendTestEmail(venueId, plannedTabId);
|
|
}
|
|
} |