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);
|
||||
});
|
||||
}
|
||||
15
apps/web/src/app/api/resource-links/export/route.ts
Normal file
15
apps/web/src/app/api/resource-links/export/route.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { handleApi } from "@/lib/api";
|
||||
import { exportResourceLinksToBacklog } from "@/lib/services/resource-links";
|
||||
import { requireUser } from "@/lib/services/user";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
return handleApi(async () => {
|
||||
const { user } = await requireUser();
|
||||
return exportResourceLinksToBacklog({
|
||||
userId: user.id,
|
||||
weekStart: String(body.weekStart ?? ""),
|
||||
ids: Array.isArray(body.ids) ? body.ids.map(String) : [],
|
||||
});
|
||||
});
|
||||
}
|
||||
40
apps/web/src/app/api/resource-links/route.ts
Normal file
40
apps/web/src/app/api/resource-links/route.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { handleApi } from "@/lib/api";
|
||||
import { requireUser } from "@/lib/services/user";
|
||||
import {
|
||||
createResourceLink,
|
||||
getResourceBacklogSections,
|
||||
listResourceLinks,
|
||||
type ResourceLinkStatus,
|
||||
} from "@/lib/services/resource-links";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const weekStart = searchParams.get("weekStart") ?? undefined;
|
||||
const status = (searchParams.get("status") ?? undefined) as ResourceLinkStatus | undefined;
|
||||
const includeSections = searchParams.get("includeSections") === "1";
|
||||
|
||||
return handleApi(async () => {
|
||||
const { user } = await requireUser();
|
||||
const [links, sections] = await Promise.all([
|
||||
listResourceLinks(user.id, { weekStart, status }),
|
||||
includeSections ? getResourceBacklogSections() : Promise.resolve([]),
|
||||
]);
|
||||
return { links, sections };
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
return handleApi(async () => {
|
||||
const { user } = await requireUser();
|
||||
const link = await createResourceLink({
|
||||
userId: user.id,
|
||||
date: String(body.date),
|
||||
title: String(body.title ?? ""),
|
||||
url: String(body.url ?? ""),
|
||||
category: typeof body.category === "string" ? body.category : undefined,
|
||||
notes: typeof body.notes === "string" ? body.notes : undefined,
|
||||
});
|
||||
return { link };
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user