This commit is contained in:
35
apps/web/src/app/api/resource-links/[id]/route.ts
Normal file
35
apps/web/src/app/api/resource-links/[id]/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { handleApi } from "@/lib/api";
|
||||
import { deleteResourceLink, updateResourceLink } from "@/lib/services/resource-links";
|
||||
import { requireUser } from "@/lib/services/user";
|
||||
|
||||
export async function PATCH(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params;
|
||||
const body = await request.json();
|
||||
return handleApi(async () => {
|
||||
const { user } = await requireUser();
|
||||
const link = await updateResourceLink({
|
||||
userId: user.id,
|
||||
id,
|
||||
title: typeof body.title === "string" ? body.title : undefined,
|
||||
url: typeof body.url === "string" ? body.url : undefined,
|
||||
category: typeof body.category === "string" ? body.category : undefined,
|
||||
notes: typeof body.notes === "string" || body.notes === null ? body.notes : undefined,
|
||||
status: typeof body.status === "string" ? body.status : undefined,
|
||||
});
|
||||
return { link };
|
||||
});
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params;
|
||||
return handleApi(async () => {
|
||||
const { user } = await requireUser();
|
||||
return deleteResourceLink(user.id, id);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user