feat: add entries

This commit is contained in:
redglow
2026-06-20 17:43:53 +02:00
parent 3c4e6d3612
commit dc576d6b19
6 changed files with 165 additions and 8 deletions
+31
View File
@@ -1,13 +1,44 @@
import express from "express";
import multer from "multer";
import ViteExpress from "vite-express";
import z from "zod";
import { db } from "./db/database.js";
const upload = multer({
dest: "uploads/",
});
const app = express();
const AddInput = z.object({
file: z.object({ filename: z.string() }),
body: z.object({
publication_date: z.coerce
.date()
.transform((x) => new Date(x).toISOString()),
title: z.string().nonempty(),
text: z.string().nonempty(),
}),
});
app.get("/hello", (_, res) => {
res.send("Hello Vite + React + TypeScript!");
});
app.post("/api/announcements/add", upload.single("image"), async (req, res) => {
const addInput = AddInput.parse(req);
await db
.insertInto("announcements")
.values({
title: addInput.body.title,
text: addInput.body.text,
publication_date: addInput.body.publication_date,
image: addInput.file.filename,
})
.execute();
res.redirect("/");
});
app.get("/api/announcements", async (_, res) => {
// await new Promise((resolve) => setTimeout(resolve, 1000));
const announcements = await db