36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
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);
|
|
});
|
|
}
|