Compare commits

...

2 Commits

Author SHA1 Message Date
1fdf07cdf7 reverted back to date for schema 2026-01-14 10:46:32 +13:00
4f3eee5a49 quick ui test thingy 2026-01-13 12:07:11 +13:00
3 changed files with 18 additions and 5 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", {
id: integer().primaryKey().generatedAlwaysAsIdentity(),
date: varchar().notNull(),
date: timestamp({ mode: 'date', withTimezone: true }).notNull().defaultNow(),
location: json(),
content: json(),
});

View File

@@ -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);

View File

@@ -29,8 +29,17 @@ import "../styles/global.css"
await uploadEntry(entry)
})
</script>
<script>
const el = document.getElementById('result')
document.querySelector('#export')?.addEventListener('click', async () => {
const res = await fetch('/api/entry/all')
const js = await res.json()
el!.innerText = JSON.stringify(js)
})
</script>
@@ -53,6 +62,9 @@ import "../styles/global.css"
<button id="upload" class="mt-2">
upload
</button>
<button id="export" class="mt-2">
export all
</button>
<div id="result">