- Add await before all service calls in auth, OAuth routes - Convert settings.ts direct DB calls: remove .get()/.run(), use await + destructuring - Auth middleware: await getUserCount, getSession, refreshSession - Fix formatting in threads.ts for biome compliance - All files pass lint
42 lines
1014 B
TypeScript
42 lines
1014 B
TypeScript
import { eq } from "drizzle-orm";
|
|
import { Hono } from "hono";
|
|
import { settings } from "../../db/schema.ts";
|
|
|
|
type Env = { Variables: { db?: any } };
|
|
|
|
const app = new Hono<Env>();
|
|
|
|
app.get("/:key", async (c) => {
|
|
const database = c.get("db");
|
|
const key = c.req.param("key");
|
|
const [row] = await database
|
|
.select()
|
|
.from(settings)
|
|
.where(eq(settings.key, key));
|
|
if (!row) return c.json({ error: "Setting not found" }, 404);
|
|
return c.json(row);
|
|
});
|
|
|
|
app.put("/:key", async (c) => {
|
|
const database = c.get("db");
|
|
const key = c.req.param("key");
|
|
const body = await c.req.json<{ value: string }>();
|
|
|
|
if (!body.value && body.value !== "") {
|
|
return c.json({ error: "value is required" }, 400);
|
|
}
|
|
|
|
await database
|
|
.insert(settings)
|
|
.values({ key, value: body.value })
|
|
.onConflictDoUpdate({ target: settings.key, set: { value: body.value } });
|
|
|
|
const [row] = await database
|
|
.select()
|
|
.from(settings)
|
|
.where(eq(settings.key, key));
|
|
return c.json(row);
|
|
});
|
|
|
|
export { app as settingsRoutes };
|