102 lines
2.9 KiB
TypeScript
102 lines
2.9 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
HttpCode,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
import { NotificationService } from './notification.service';
|
|
import { CreateReminderDto } from './dto/create-reminder.dto';
|
|
import { UpdateReminderDto } from './dto/update-reminder.dto';
|
|
import { QueryRemindersDto } from './dto/query-reminders.dto';
|
|
import { MessageBudgetService } from './message-budget.service';
|
|
|
|
@ApiTags('Notifications')
|
|
@Controller('notifications')
|
|
export class NotificationController {
|
|
constructor(
|
|
private readonly service: NotificationService,
|
|
private readonly messageBudget: MessageBudgetService,
|
|
) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List reminders with filters' })
|
|
findAll(@Query() query: QueryRemindersDto) {
|
|
return this.service.findAll(query);
|
|
}
|
|
|
|
@Get('upcoming')
|
|
@ApiOperation({ summary: 'Get pending reminders in the next 24 hours' })
|
|
@ApiQuery({ name: 'minutes', required: false, type: Number })
|
|
findUpcoming(@Query('minutes') minutes?: string) {
|
|
return this.service.findUpcoming(minutes ? parseInt(minutes, 10) : undefined);
|
|
}
|
|
|
|
@Get('budget')
|
|
@ApiOperation({ summary: 'Get message budget status for today' })
|
|
getBudget() {
|
|
return this.messageBudget.getStatus();
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create a reminder' })
|
|
create(@Body() dto: CreateReminderDto) {
|
|
return this.service.createReminder(dto);
|
|
}
|
|
|
|
@Get(':id/delivery-status')
|
|
@ApiOperation({ summary: 'Check delivery status of a fired reminder via sync service' })
|
|
getDeliveryStatus(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.service.getDeliveryStatus(id);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get a reminder by ID' })
|
|
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.service.findOne(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Update a reminder' })
|
|
update(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() dto: UpdateReminderDto,
|
|
) {
|
|
return this.service.updateReminder(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HttpCode(204)
|
|
@ApiOperation({ summary: 'Dismiss a reminder' })
|
|
dismiss(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.service.dismissReminder(id);
|
|
}
|
|
|
|
@Post(':id/preview')
|
|
@ApiOperation({ summary: 'Preview AI-generated nudge message without sending' })
|
|
@ApiQuery({ name: 'agent', required: false, type: String })
|
|
preview(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Query('agent') agent?: string,
|
|
) {
|
|
return this.service.previewMessage(id, agent);
|
|
}
|
|
|
|
@Post(':id/fire')
|
|
@ApiOperation({ summary: 'Manually trigger a reminder (for testing)' })
|
|
fire(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.service.fireById(id);
|
|
}
|
|
|
|
@Post(':id/retry')
|
|
@ApiOperation({ summary: 'Reset a failed reminder to pending for retry' })
|
|
retry(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.service.retryById(id);
|
|
}
|
|
}
|