feat(notifications): complete notification delivery system with email, push, and in-app support
Add 5 new event listeners (listing.approved, listing.rejected, payment.confirmed, subscription.expiring, inquiry.received), 3 new Handlebars templates, readAt field for in-app read/unread tracking, unread/mark-as-read API endpoints, and unit tests. All 57 notification tests pass, lint clean, typecheck clean. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -2,7 +2,9 @@ import {
|
||||
Controller,
|
||||
Get,
|
||||
Put,
|
||||
Patch,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
Inject,
|
||||
@@ -79,6 +81,43 @@ export class NotificationsController {
|
||||
return this.preferenceRepo.upsert(user.sub, dto.channel, dto.eventType, dto.enabled);
|
||||
}
|
||||
|
||||
@Get('unread')
|
||||
@ApiOperation({ summary: 'Get unread notifications' })
|
||||
@ApiResponse({ status: 200, description: 'Unread notifications retrieved' })
|
||||
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
async getUnread(
|
||||
@CurrentUser() user: JwtPayload,
|
||||
@Query('limit') limit?: number,
|
||||
) {
|
||||
const [notifications, count] = await Promise.all([
|
||||
this.notificationRepo.findUnreadByUserId(user.sub, limit ?? 50),
|
||||
this.notificationRepo.countUnreadByUserId(user.sub),
|
||||
]);
|
||||
return { notifications, unreadCount: count };
|
||||
}
|
||||
|
||||
@Patch(':id/read')
|
||||
@ApiOperation({ summary: 'Mark a notification as read' })
|
||||
@ApiResponse({ status: 200, description: 'Notification marked as read' })
|
||||
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
||||
async markAsRead(
|
||||
@CurrentUser() user: JwtPayload,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
await this.notificationRepo.markAsRead(id, user.sub);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@Patch('read-all')
|
||||
@ApiOperation({ summary: 'Mark all notifications as read' })
|
||||
@ApiResponse({ status: 200, description: 'All notifications marked as read' })
|
||||
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
||||
async markAllAsRead(@CurrentUser() user: JwtPayload) {
|
||||
const count = await this.notificationRepo.markAllAsRead(user.sub);
|
||||
return { markedCount: count };
|
||||
}
|
||||
|
||||
@Get('templates')
|
||||
@ApiOperation({ summary: 'Get available notification templates' })
|
||||
@ApiResponse({ status: 200, description: 'Templates retrieved' })
|
||||
|
||||
Reference in New Issue
Block a user