snapshot
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import { readJson } from "@/server/http/readJson";
|
||||
import { createSnippet, deleteSnippet, getSnippetById, listSnippets, updateSnippet } from "@/server/snippets";
|
||||
import {
|
||||
createSnippet,
|
||||
deleteSnippet,
|
||||
getSnippetById,
|
||||
listSnippets,
|
||||
normalizeDeadlineAtInput,
|
||||
updateSnippet,
|
||||
} from "@/server/snippets";
|
||||
|
||||
export const snippetRoutes = {
|
||||
"/api/snippets": {
|
||||
@@ -16,11 +23,21 @@ export const snippetRoutes = {
|
||||
}
|
||||
const o = body as Record<string, unknown>;
|
||||
const tags = Array.isArray(o.tags) ? o.tags.filter((t): t is string => typeof t === "string") : [];
|
||||
let deadline_at: string | null | undefined;
|
||||
if ("deadline_at" in o) {
|
||||
try {
|
||||
deadline_at = normalizeDeadlineAtInput(o.deadline_at);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : "deadline_at ungültig";
|
||||
return Response.json({ error: msg }, { status: 400 });
|
||||
}
|
||||
}
|
||||
const snippet = createSnippet({
|
||||
title:
|
||||
o.title === null ? null : typeof o.title === "string" ? o.title : undefined,
|
||||
body: typeof o.body === "string" ? o.body : "",
|
||||
tags,
|
||||
deadline_at,
|
||||
});
|
||||
return Response.json(snippet, { status: 201 });
|
||||
},
|
||||
@@ -53,6 +70,7 @@ export const snippetRoutes = {
|
||||
body?: string;
|
||||
tags?: string[];
|
||||
sort_order?: number;
|
||||
deadline_at?: string | null;
|
||||
} = {};
|
||||
if ("title" in o) {
|
||||
patch.title = o.title === null ? null : String(o.title);
|
||||
@@ -66,6 +84,14 @@ export const snippetRoutes = {
|
||||
if ("sort_order" in o && typeof o.sort_order === "number" && Number.isFinite(o.sort_order)) {
|
||||
patch.sort_order = o.sort_order;
|
||||
}
|
||||
if ("deadline_at" in o) {
|
||||
try {
|
||||
patch.deadline_at = normalizeDeadlineAtInput(o.deadline_at);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : "deadline_at ungültig";
|
||||
return Response.json({ error: msg }, { status: 400 });
|
||||
}
|
||||
}
|
||||
const snippet = updateSnippet(id, patch);
|
||||
if (!snippet) {
|
||||
return Response.json({ error: "Not found" }, { status: 404 });
|
||||
|
||||
Reference in New Issue
Block a user