@@ -1,56 +1,28 @@
|
||||
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 { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
|
||||
import { z } from 'zod';
|
||||
import { Reminder, ReminderCandidate, SendRemindersResult, sendRemindersSchema } from '@kooltap/shared';
|
||||
import { zod } from '../common/zod.pipe';
|
||||
import { Authorized, Roles } from '../common/auth';
|
||||
import { RemindersService } from './reminders.service';
|
||||
import { SendRemindersDto } from './dto/send-reminders.dto';
|
||||
|
||||
@ApiTags('Reminders')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, VenueAccessGuard)
|
||||
@Controller('venues/:venueId/reminders')
|
||||
@Authorized()
|
||||
export class RemindersController {
|
||||
constructor(private service: RemindersService) {}
|
||||
constructor(private reminders: 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);
|
||||
candidates(@Param('venueId') venueId: string): Promise<{ candidates: ReminderCandidate[]; cooldownDays: number }> {
|
||||
return this.reminders.candidates(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);
|
||||
send(@Param('venueId') venueId: string, @Body(zod(sendRemindersSchema)) dto: z.output<typeof sendRemindersSchema>): Promise<SendRemindersResult> {
|
||||
return this.reminders.send(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);
|
||||
history(@Param('venueId') venueId: string, @Query('customerName') customerName?: string): Promise<Reminder[]> {
|
||||
return this.reminders.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user