(request: NextRequest)
| 159 | } |
| 160 | |
| 161 | export async function DELETE(request: NextRequest) { |
| 162 | try { |
| 163 | const { searchParams } = new URL(request.url); |
| 164 | const id = searchParams.get('id'); |
| 165 | const action = searchParams.get('action'); |
| 166 | |
| 167 | const notifications = await loadNotifications(); |
| 168 | |
| 169 | // Delete all read notifications |
| 170 | if (action === 'clearRead') { |
| 171 | const updated = notifications.filter((n) => !n.read); |
| 172 | await saveNotifications(updated); |
| 173 | return NextResponse.json({ success: true, deleted: notifications.length - updated.length }); |
| 174 | } |
| 175 | |
| 176 | // Delete single notification |
| 177 | if (id) { |
| 178 | const index = notifications.findIndex((n) => n.id === id); |
| 179 | if (index === -1) { |
| 180 | return NextResponse.json({ error: 'Notification not found' }, { status: 404 }); |
| 181 | } |
| 182 | |
| 183 | notifications.splice(index, 1); |
| 184 | await saveNotifications(notifications); |
| 185 | return NextResponse.json({ success: true }); |
| 186 | } |
| 187 | |
| 188 | return NextResponse.json({ error: 'Invalid request' }, { status: 400 }); |
| 189 | } catch (error) { |
| 190 | console.error('Failed to delete notification:', error); |
| 191 | return NextResponse.json({ error: 'Failed to delete notification' }, { status: 500 }); |
| 192 | } |
| 193 | } |
nothing calls this directly
no test coverage detected