(request: NextRequest)
| 126 | } |
| 127 | |
| 128 | export async function PATCH(request: NextRequest) { |
| 129 | try { |
| 130 | const body = await request.json(); |
| 131 | const { id, read, action } = body; |
| 132 | |
| 133 | const notifications = await loadNotifications(); |
| 134 | |
| 135 | // Mark all as read |
| 136 | if (action === 'markAllRead') { |
| 137 | notifications.forEach((n) => (n.read = true)); |
| 138 | await saveNotifications(notifications); |
| 139 | return NextResponse.json({ success: true, updated: notifications.length }); |
| 140 | } |
| 141 | |
| 142 | // Mark single notification as read/unread |
| 143 | if (id) { |
| 144 | const notification = notifications.find((n) => n.id === id); |
| 145 | if (!notification) { |
| 146 | return NextResponse.json({ error: 'Notification not found' }, { status: 404 }); |
| 147 | } |
| 148 | |
| 149 | notification.read = read !== undefined ? read : !notification.read; |
| 150 | await saveNotifications(notifications); |
| 151 | return NextResponse.json(notification); |
| 152 | } |
| 153 | |
| 154 | return NextResponse.json({ error: 'Invalid request' }, { status: 400 }); |
| 155 | } catch (error) { |
| 156 | console.error('Failed to update notification:', error); |
| 157 | return NextResponse.json({ error: 'Failed to update notification' }, { status: 500 }); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | export async function DELETE(request: NextRequest) { |
| 162 | try { |
nothing calls this directly
no test coverage detected