import { Body, Controller, Get, Param, ParseUUIDPipe, Patch, Post, Query } from '@nestjs/common'; import { CurrentSession } from '../auth/session.decorator'; import type { AuthenticatedSession } from '../auth/tenant.guard'; import { MarkReadDto, SnoozeDto, UpdatePreferencesDto } from './dto'; import { NotificationsService, type InboxFilter } from './notifications.service'; const FILTERS: InboxFilter[] = [ 'all', 'unread', 'action_required', 'critical', 'intelligence', 'system', ]; @Controller('notifications') export class NotificationsController { constructor(private readonly notificationsService: NotificationsService) {} @Get() list(@CurrentSession() session: AuthenticatedSession, @Query('filter') filter?: string) { const safe = FILTERS.includes(filter as InboxFilter) ? (filter as InboxFilter) : 'all'; return this.notificationsService.list(session, safe); } @Post('mark-read') markRead(@CurrentSession() session: AuthenticatedSession, @Body() dto: MarkReadDto) { return this.notificationsService.markRead(session, dto.ids); } @Post(':id/acknowledge') acknowledge( @CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string, ) { return this.notificationsService.acknowledge(session, id); } @Post(':id/dismiss') dismiss(@CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string) { return this.notificationsService.dismiss(session, id); } @Post(':id/snooze') snooze( @CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string, @Body() dto: SnoozeDto, ) { return this.notificationsService.snooze(session, id, dto.minutes); } @Get('preferences') getPreferences(@CurrentSession() session: AuthenticatedSession) { return this.notificationsService.getPreferences(session); } @Patch('preferences') updatePreferences( @CurrentSession() session: AuthenticatedSession, @Body() dto: UpdatePreferencesDto, ) { return this.notificationsService.updatePreferences(session, dto); } }