chore: auto-fix Biome formatting and configure lint rules
All checks were successful
CI / ci (push) Successful in 15s

Run biome check --write --unsafe to fix tabs, import ordering, and
non-null assertions across entire codebase. Disable a11y rules not
applicable to this single-user app. Exclude auto-generated routeTree.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-15 19:51:34 +01:00
parent 4d0452b7b3
commit b496462df5
63 changed files with 4752 additions and 4672 deletions

View File

@@ -1,25 +1,25 @@
import { Hono } from "hono";
import { zValidator } from "@hono/zod-validator";
import {
createThreadSchema,
updateThreadSchema,
createCandidateSchema,
updateCandidateSchema,
resolveThreadSchema,
} from "../../shared/schemas.ts";
import {
getAllThreads,
getThreadWithCandidates,
createThread,
updateThread,
deleteThread,
createCandidate,
updateCandidate,
deleteCandidate,
resolveThread,
} from "../services/thread.service.ts";
import { unlink } from "node:fs/promises";
import { join } from "node:path";
import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import {
createCandidateSchema,
createThreadSchema,
resolveThreadSchema,
updateCandidateSchema,
updateThreadSchema,
} from "../../shared/schemas.ts";
import {
createCandidate,
createThread,
deleteCandidate,
deleteThread,
getAllThreads,
getThreadWithCandidates,
resolveThread,
updateCandidate,
updateThread,
} from "../services/thread.service.ts";
type Env = { Variables: { db?: any } };
@@ -28,109 +28,113 @@ const app = new Hono<Env>();
// Thread CRUD
app.get("/", (c) => {
const db = c.get("db");
const includeResolved = c.req.query("includeResolved") === "true";
const threads = getAllThreads(db, includeResolved);
return c.json(threads);
const db = c.get("db");
const includeResolved = c.req.query("includeResolved") === "true";
const threads = getAllThreads(db, includeResolved);
return c.json(threads);
});
app.post("/", zValidator("json", createThreadSchema), (c) => {
const db = c.get("db");
const data = c.req.valid("json");
const thread = createThread(db, data);
return c.json(thread, 201);
const db = c.get("db");
const data = c.req.valid("json");
const thread = createThread(db, data);
return c.json(thread, 201);
});
app.get("/:id", (c) => {
const db = c.get("db");
const id = Number(c.req.param("id"));
const thread = getThreadWithCandidates(db, id);
if (!thread) return c.json({ error: "Thread not found" }, 404);
return c.json(thread);
const db = c.get("db");
const id = Number(c.req.param("id"));
const thread = getThreadWithCandidates(db, id);
if (!thread) return c.json({ error: "Thread not found" }, 404);
return c.json(thread);
});
app.put("/:id", zValidator("json", updateThreadSchema), (c) => {
const db = c.get("db");
const id = Number(c.req.param("id"));
const data = c.req.valid("json");
const thread = updateThread(db, id, data);
if (!thread) return c.json({ error: "Thread not found" }, 404);
return c.json(thread);
const db = c.get("db");
const id = Number(c.req.param("id"));
const data = c.req.valid("json");
const thread = updateThread(db, id, data);
if (!thread) return c.json({ error: "Thread not found" }, 404);
return c.json(thread);
});
app.delete("/:id", async (c) => {
const db = c.get("db");
const id = Number(c.req.param("id"));
const deleted = deleteThread(db, id);
if (!deleted) return c.json({ error: "Thread not found" }, 404);
const db = c.get("db");
const id = Number(c.req.param("id"));
const deleted = deleteThread(db, id);
if (!deleted) return c.json({ error: "Thread not found" }, 404);
// Clean up candidate image files
for (const filename of deleted.candidateImages) {
try {
await unlink(join("uploads", filename));
} catch {
// File missing is not an error worth failing the delete over
}
}
// Clean up candidate image files
for (const filename of deleted.candidateImages) {
try {
await unlink(join("uploads", filename));
} catch {
// File missing is not an error worth failing the delete over
}
}
return c.json({ success: true });
return c.json({ success: true });
});
// Candidate CRUD (nested under thread)
app.post("/:id/candidates", zValidator("json", createCandidateSchema), (c) => {
const db = c.get("db");
const threadId = Number(c.req.param("id"));
const db = c.get("db");
const threadId = Number(c.req.param("id"));
// Verify thread exists
const thread = getThreadWithCandidates(db, threadId);
if (!thread) return c.json({ error: "Thread not found" }, 404);
// Verify thread exists
const thread = getThreadWithCandidates(db, threadId);
if (!thread) return c.json({ error: "Thread not found" }, 404);
const data = c.req.valid("json");
const candidate = createCandidate(db, threadId, data);
return c.json(candidate, 201);
const data = c.req.valid("json");
const candidate = createCandidate(db, threadId, data);
return c.json(candidate, 201);
});
app.put("/:threadId/candidates/:candidateId", zValidator("json", updateCandidateSchema), (c) => {
const db = c.get("db");
const candidateId = Number(c.req.param("candidateId"));
const data = c.req.valid("json");
const candidate = updateCandidate(db, candidateId, data);
if (!candidate) return c.json({ error: "Candidate not found" }, 404);
return c.json(candidate);
});
app.put(
"/:threadId/candidates/:candidateId",
zValidator("json", updateCandidateSchema),
(c) => {
const db = c.get("db");
const candidateId = Number(c.req.param("candidateId"));
const data = c.req.valid("json");
const candidate = updateCandidate(db, candidateId, data);
if (!candidate) return c.json({ error: "Candidate not found" }, 404);
return c.json(candidate);
},
);
app.delete("/:threadId/candidates/:candidateId", async (c) => {
const db = c.get("db");
const candidateId = Number(c.req.param("candidateId"));
const deleted = deleteCandidate(db, candidateId);
if (!deleted) return c.json({ error: "Candidate not found" }, 404);
const db = c.get("db");
const candidateId = Number(c.req.param("candidateId"));
const deleted = deleteCandidate(db, candidateId);
if (!deleted) return c.json({ error: "Candidate not found" }, 404);
// Clean up image file if exists
if (deleted.imageFilename) {
try {
await unlink(join("uploads", deleted.imageFilename));
} catch {
// File missing is not an error
}
}
// Clean up image file if exists
if (deleted.imageFilename) {
try {
await unlink(join("uploads", deleted.imageFilename));
} catch {
// File missing is not an error
}
}
return c.json({ success: true });
return c.json({ success: true });
});
// Resolution
app.post("/:id/resolve", zValidator("json", resolveThreadSchema), (c) => {
const db = c.get("db");
const threadId = Number(c.req.param("id"));
const { candidateId } = c.req.valid("json");
const db = c.get("db");
const threadId = Number(c.req.param("id"));
const { candidateId } = c.req.valid("json");
const result = resolveThread(db, threadId, candidateId);
if (!result.success) {
return c.json({ error: result.error }, 400);
}
const result = resolveThread(db, threadId, candidateId);
if (!result.success) {
return c.json({ error: result.error }, 400);
}
return c.json({ success: true, item: result.item });
return c.json({ success: true, item: result.item });
});
export { app as threadRoutes };