Skip to content

Commit 944696a

Browse files
delete endpoint
1 parent 6e3861d commit 944696a

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/app/api/admin/trees/[id]/route.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,21 @@ export async function PUT(req: NextRequest, { params }: IParams) {
3838
}
3939

4040
/**
41-
* Example DELETE API route. REPLACE THIS DOCSTRING.
42-
* @returns {message: string}
41+
* Deletes one tree row by id, returns deleted tree
42+
* @returns { message: Tree, status: number } if successful
43+
* @returns { message: string, status: number } if error
4344
*/
44-
export async function DELETE() {
45-
return NextResponse.json({ message: "Example trees slug DELETE message" });
45+
export async function DELETE(req: NextRequest, { params }: IParams) {
46+
try {
47+
const { id } = await params;
48+
const { data, error } = await supabase.from("trees").delete().eq("id", id).limit(1).select().single();
49+
50+
if (error) {
51+
return NextResponse.json({ message: error.message }, { status: postgrestErrorToHttpStatus(error) });
52+
}
53+
54+
return NextResponse.json({ message: data }, { status: 200 });
55+
} catch (error) {
56+
return NextResponse.json({ message: "Unexpected Server Error" }, { status: 500 });
57+
}
4658
}

0 commit comments

Comments
 (0)