diff --git a/src/db/schema.ts b/src/db/schema.ts index d059b7c..f84ad50 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -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", { id: integer().primaryKey().generatedAlwaysAsIdentity(), - date: varchar().notNull(), + date: timestamp({ mode: 'date', withTimezone: true }).notNull().defaultNow(), location: json(), content: json(), }); diff --git a/src/pages/api/entry/new.ts b/src/pages/api/entry/new.ts index b37ac59..d55b6c0 100644 --- a/src/pages/api/entry/new.ts +++ b/src/pages/api/entry/new.ts @@ -10,13 +10,14 @@ export async function POST({ request }: APIContext) { try { const body = await request.json(); const entry: typeof entryTable.$inferInsert = body + entry.date = new Date(body.date) await db.insert(entryTable).values(entry) + + return httpResponse({ "success": entry }, 200); } catch(e) { return httpResponse({ "error": `Malformed JSON (${e})` }, 400) } - - return httpResponse(null, 200); } return httpResponse(null, 400);