reverted back to date for schema

This commit is contained in:
2026-01-14 10:46:32 +13:00
parent 4f3eee5a49
commit 1fdf07cdf7
2 changed files with 5 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
import { integer, pgTable, varchar, date, json } from "drizzle-orm/pg-core"; import { integer, pgTable, json, timestamp } from "drizzle-orm/pg-core";
export const entryTable = pgTable("entries", { export const entryTable = pgTable("entries", {
id: integer().primaryKey().generatedAlwaysAsIdentity(), id: integer().primaryKey().generatedAlwaysAsIdentity(),
date: varchar().notNull(), date: timestamp({ mode: 'date', withTimezone: true }).notNull().defaultNow(),
location: json(), location: json(),
content: json(), content: json(),
}); });

View File

@@ -10,13 +10,14 @@ export async function POST({ request }: APIContext) {
try { try {
const body = await request.json(); const body = await request.json();
const entry: typeof entryTable.$inferInsert = body const entry: typeof entryTable.$inferInsert = body
entry.date = new Date(body.date)
await db.insert(entryTable).values(entry) await db.insert(entryTable).values(entry)
return httpResponse({ "success": entry }, 200);
} catch(e) { } catch(e) {
return httpResponse({ "error": `Malformed JSON (${e})` }, 400) return httpResponse({ "error": `Malformed JSON (${e})` }, 400)
} }
return httpResponse(null, 200);
} }
return httpResponse(null, 400); return httpResponse(null, 400);