Implement expense tracking foundation for v1
This commit is contained in:
26
src/app/expenses/[id]/route.ts
Normal file
26
src/app/expenses/[id]/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { removeExpense } from "@/lib/expenses";
|
||||
|
||||
type RouteContext = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function DELETE(_: Request, context: RouteContext) {
|
||||
const { id } = await context.params;
|
||||
|
||||
try {
|
||||
await removeExpense(id);
|
||||
return new NextResponse(null, { status: 204 });
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Prisma.PrismaClientKnownRequestError &&
|
||||
error.code === "P2025"
|
||||
) {
|
||||
return NextResponse.json({ error: "Expense not found." }, { status: 404 });
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user