feat(api): implement DELETE endpoint for removing specific properties by URL

This commit is contained in:
ryan 2025-06-19 14:50:09 +03:00
parent ff0f252389
commit 7b9977db6b

View file

@ -0,0 +1,44 @@
//Handles DELETE requests for specific properties
import { NextRequest, NextResponse } from 'next/server';
import { deletePropertyByUrl } from '@/lib/database';
// DELETE /api/urls/[encodedUrl]/properties/[property] - Delete a property from a URL
export async function DELETE(
request: NextRequest,
{ params }: { params: { encodedUrl: string; property: string } }
) {
const url = decodeURIComponent(params.encodedUrl);
const property = decodeURIComponent(params.property);
console.log('[API] Deleting property', property, 'from URL', url);
try {
if (!property) {
return NextResponse.json(
{ error: 'Property name is required' },
{ status: 400 }
);
}
await deletePropertyByUrl(url, property);
console.log('[API] Successfully deleted property:', property);
return NextResponse.json(
{ message: 'Property deleted', property: property },
{ status: 200 }
);
} catch (error) {
console.log('[API] Delete error:', error);
return NextResponse.json(
{
error: 'Failed to delete property',
details: error instanceof Error ? error.message : 'Unknown error',
property: property,
url: url
},
{ status: 500 }
);
}
}