Files
Memento/src/routes/api/entry/new/+server.ts
2026-02-17 12:36:02 +13:00

22 lines
649 B
TypeScript

import { db } from "$lib/server/db";
import { entryTable } from "$lib/server/db/schema";
import { httpResponse } from "$lib/server/http";
export async function POST({ request }) {
if (request.headers.get("Content-Type") === "application/json") {
try {
const body = await request.json();
const entry: typeof entryTable.$inferInsert = body
await db.insert(entryTable).values(entry)
return httpResponse({ "success": entry }, 200);
} catch(e) {
return httpResponse({ "error": `Malformed JSON (${e})` }, 400)
}
}
return httpResponse(null, 400);
}