chore: auto-fix Biome formatting and configure lint rules
All checks were successful
CI / ci (push) Successful in 15s
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:
@@ -1,14 +1,14 @@
|
||||
import { Hono } from "hono";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { Hono } from "hono";
|
||||
import {
|
||||
createCategorySchema,
|
||||
updateCategorySchema,
|
||||
createCategorySchema,
|
||||
updateCategorySchema,
|
||||
} from "../../shared/schemas.ts";
|
||||
import {
|
||||
getAllCategories,
|
||||
createCategory,
|
||||
updateCategory,
|
||||
deleteCategory,
|
||||
createCategory,
|
||||
deleteCategory,
|
||||
getAllCategories,
|
||||
updateCategory,
|
||||
} from "../services/category.service.ts";
|
||||
|
||||
type Env = { Variables: { db?: any } };
|
||||
@@ -16,44 +16,44 @@ type Env = { Variables: { db?: any } };
|
||||
const app = new Hono<Env>();
|
||||
|
||||
app.get("/", (c) => {
|
||||
const db = c.get("db");
|
||||
const cats = getAllCategories(db);
|
||||
return c.json(cats);
|
||||
const db = c.get("db");
|
||||
const cats = getAllCategories(db);
|
||||
return c.json(cats);
|
||||
});
|
||||
|
||||
app.post("/", zValidator("json", createCategorySchema), (c) => {
|
||||
const db = c.get("db");
|
||||
const data = c.req.valid("json");
|
||||
const cat = createCategory(db, data);
|
||||
return c.json(cat, 201);
|
||||
const db = c.get("db");
|
||||
const data = c.req.valid("json");
|
||||
const cat = createCategory(db, data);
|
||||
return c.json(cat, 201);
|
||||
});
|
||||
|
||||
app.put(
|
||||
"/:id",
|
||||
zValidator("json", updateCategorySchema.omit({ id: true })),
|
||||
(c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const data = c.req.valid("json");
|
||||
const cat = updateCategory(db, id, data);
|
||||
if (!cat) return c.json({ error: "Category not found" }, 404);
|
||||
return c.json(cat);
|
||||
},
|
||||
"/:id",
|
||||
zValidator("json", updateCategorySchema.omit({ id: true })),
|
||||
(c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const data = c.req.valid("json");
|
||||
const cat = updateCategory(db, id, data);
|
||||
if (!cat) return c.json({ error: "Category not found" }, 404);
|
||||
return c.json(cat);
|
||||
},
|
||||
);
|
||||
|
||||
app.delete("/:id", (c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const result = deleteCategory(db, id);
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const result = deleteCategory(db, id);
|
||||
|
||||
if (!result.success) {
|
||||
if (result.error === "Cannot delete the Uncategorized category") {
|
||||
return c.json({ error: result.error }, 400);
|
||||
}
|
||||
return c.json({ error: result.error }, 404);
|
||||
}
|
||||
if (!result.success) {
|
||||
if (result.error === "Cannot delete the Uncategorized category") {
|
||||
return c.json({ error: result.error }, 400);
|
||||
}
|
||||
return c.json({ error: result.error }, 404);
|
||||
}
|
||||
|
||||
return c.json({ success: true });
|
||||
return c.json({ success: true });
|
||||
});
|
||||
|
||||
export { app as categoryRoutes };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Hono } from "hono";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { join } from "node:path";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { Hono } from "hono";
|
||||
|
||||
const ALLOWED_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
||||
const MAX_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
@@ -9,38 +9,39 @@ const MAX_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
const app = new Hono();
|
||||
|
||||
app.post("/", async (c) => {
|
||||
const body = await c.req.parseBody();
|
||||
const file = body["image"];
|
||||
const body = await c.req.parseBody();
|
||||
const file = body.image;
|
||||
|
||||
if (!file || typeof file === "string") {
|
||||
return c.json({ error: "No image file provided" }, 400);
|
||||
}
|
||||
if (!file || typeof file === "string") {
|
||||
return c.json({ error: "No image file provided" }, 400);
|
||||
}
|
||||
|
||||
// Validate file type
|
||||
if (!ALLOWED_TYPES.includes(file.type)) {
|
||||
return c.json(
|
||||
{ error: "Invalid file type. Accepted: jpeg, png, webp" },
|
||||
400,
|
||||
);
|
||||
}
|
||||
// Validate file type
|
||||
if (!ALLOWED_TYPES.includes(file.type)) {
|
||||
return c.json(
|
||||
{ error: "Invalid file type. Accepted: jpeg, png, webp" },
|
||||
400,
|
||||
);
|
||||
}
|
||||
|
||||
// Validate file size
|
||||
if (file.size > MAX_SIZE) {
|
||||
return c.json({ error: "File too large. Maximum size is 5MB" }, 400);
|
||||
}
|
||||
// Validate file size
|
||||
if (file.size > MAX_SIZE) {
|
||||
return c.json({ error: "File too large. Maximum size is 5MB" }, 400);
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
const ext = file.type.split("/")[1] === "jpeg" ? "jpg" : file.type.split("/")[1];
|
||||
const filename = `${Date.now()}-${randomUUID()}.${ext}`;
|
||||
// Generate unique filename
|
||||
const ext =
|
||||
file.type.split("/")[1] === "jpeg" ? "jpg" : file.type.split("/")[1];
|
||||
const filename = `${Date.now()}-${randomUUID()}.${ext}`;
|
||||
|
||||
// Ensure uploads directory exists
|
||||
await mkdir("uploads", { recursive: true });
|
||||
// Ensure uploads directory exists
|
||||
await mkdir("uploads", { recursive: true });
|
||||
|
||||
// Write file
|
||||
const buffer = await file.arrayBuffer();
|
||||
await Bun.write(join("uploads", filename), buffer);
|
||||
// Write file
|
||||
const buffer = await file.arrayBuffer();
|
||||
await Bun.write(join("uploads", filename), buffer);
|
||||
|
||||
return c.json({ filename }, 201);
|
||||
return c.json({ filename }, 201);
|
||||
});
|
||||
|
||||
export { app as imageRoutes };
|
||||
|
||||
@@ -1,66 +1,70 @@
|
||||
import { Hono } from "hono";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { createItemSchema, updateItemSchema } from "../../shared/schemas.ts";
|
||||
import {
|
||||
getAllItems,
|
||||
getItemById,
|
||||
createItem,
|
||||
updateItem,
|
||||
deleteItem,
|
||||
} from "../services/item.service.ts";
|
||||
import { unlink } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { Hono } from "hono";
|
||||
import { createItemSchema, updateItemSchema } from "../../shared/schemas.ts";
|
||||
import {
|
||||
createItem,
|
||||
deleteItem,
|
||||
getAllItems,
|
||||
getItemById,
|
||||
updateItem,
|
||||
} from "../services/item.service.ts";
|
||||
|
||||
type Env = { Variables: { db?: any } };
|
||||
|
||||
const app = new Hono<Env>();
|
||||
|
||||
app.get("/", (c) => {
|
||||
const db = c.get("db");
|
||||
const items = getAllItems(db);
|
||||
return c.json(items);
|
||||
const db = c.get("db");
|
||||
const items = getAllItems(db);
|
||||
return c.json(items);
|
||||
});
|
||||
|
||||
app.get("/:id", (c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const item = getItemById(db, id);
|
||||
if (!item) return c.json({ error: "Item not found" }, 404);
|
||||
return c.json(item);
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const item = getItemById(db, id);
|
||||
if (!item) return c.json({ error: "Item not found" }, 404);
|
||||
return c.json(item);
|
||||
});
|
||||
|
||||
app.post("/", zValidator("json", createItemSchema), (c) => {
|
||||
const db = c.get("db");
|
||||
const data = c.req.valid("json");
|
||||
const item = createItem(db, data);
|
||||
return c.json(item, 201);
|
||||
const db = c.get("db");
|
||||
const data = c.req.valid("json");
|
||||
const item = createItem(db, data);
|
||||
return c.json(item, 201);
|
||||
});
|
||||
|
||||
app.put("/:id", zValidator("json", updateItemSchema.omit({ id: true })), (c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const data = c.req.valid("json");
|
||||
const item = updateItem(db, id, data);
|
||||
if (!item) return c.json({ error: "Item not found" }, 404);
|
||||
return c.json(item);
|
||||
});
|
||||
app.put(
|
||||
"/:id",
|
||||
zValidator("json", updateItemSchema.omit({ id: true })),
|
||||
(c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const data = c.req.valid("json");
|
||||
const item = updateItem(db, id, data);
|
||||
if (!item) return c.json({ error: "Item not found" }, 404);
|
||||
return c.json(item);
|
||||
},
|
||||
);
|
||||
|
||||
app.delete("/:id", async (c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const deleted = deleteItem(db, id);
|
||||
if (!deleted) return c.json({ error: "Item not found" }, 404);
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const deleted = deleteItem(db, id);
|
||||
if (!deleted) return c.json({ error: "Item 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 worth failing the delete over
|
||||
}
|
||||
}
|
||||
// Clean up image file if exists
|
||||
if (deleted.imageFilename) {
|
||||
try {
|
||||
await unlink(join("uploads", deleted.imageFilename));
|
||||
} catch {
|
||||
// File missing is not an error worth failing the delete over
|
||||
}
|
||||
}
|
||||
|
||||
return c.json({ success: true });
|
||||
return c.json({ success: true });
|
||||
});
|
||||
|
||||
export { app as itemRoutes };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Hono } from "hono";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { Hono } from "hono";
|
||||
import { db as prodDb } from "../../db/index.ts";
|
||||
import { settings } from "../../db/schema.ts";
|
||||
|
||||
@@ -8,30 +8,38 @@ type Env = { Variables: { db?: any } };
|
||||
const app = new Hono<Env>();
|
||||
|
||||
app.get("/:key", (c) => {
|
||||
const database = c.get("db") ?? prodDb;
|
||||
const key = c.req.param("key");
|
||||
const row = database.select().from(settings).where(eq(settings.key, key)).get();
|
||||
if (!row) return c.json({ error: "Setting not found" }, 404);
|
||||
return c.json(row);
|
||||
const database = c.get("db") ?? prodDb;
|
||||
const key = c.req.param("key");
|
||||
const row = database
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, key))
|
||||
.get();
|
||||
if (!row) return c.json({ error: "Setting not found" }, 404);
|
||||
return c.json(row);
|
||||
});
|
||||
|
||||
app.put("/:key", async (c) => {
|
||||
const database = c.get("db") ?? prodDb;
|
||||
const key = c.req.param("key");
|
||||
const body = await c.req.json<{ value: string }>();
|
||||
const database = c.get("db") ?? prodDb;
|
||||
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);
|
||||
}
|
||||
if (!body.value && body.value !== "") {
|
||||
return c.json({ error: "value is required" }, 400);
|
||||
}
|
||||
|
||||
database
|
||||
.insert(settings)
|
||||
.values({ key, value: body.value })
|
||||
.onConflictDoUpdate({ target: settings.key, set: { value: body.value } })
|
||||
.run();
|
||||
database
|
||||
.insert(settings)
|
||||
.values({ key, value: body.value })
|
||||
.onConflictDoUpdate({ target: settings.key, set: { value: body.value } })
|
||||
.run();
|
||||
|
||||
const row = database.select().from(settings).where(eq(settings.key, key)).get();
|
||||
return c.json(row);
|
||||
const row = database
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, key))
|
||||
.get();
|
||||
return c.json(row);
|
||||
});
|
||||
|
||||
export { app as settingsRoutes };
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { Hono } from "hono";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { Hono } from "hono";
|
||||
import {
|
||||
createSetupSchema,
|
||||
updateSetupSchema,
|
||||
syncSetupItemsSchema,
|
||||
createSetupSchema,
|
||||
syncSetupItemsSchema,
|
||||
updateSetupSchema,
|
||||
} from "../../shared/schemas.ts";
|
||||
import {
|
||||
getAllSetups,
|
||||
getSetupWithItems,
|
||||
createSetup,
|
||||
updateSetup,
|
||||
deleteSetup,
|
||||
syncSetupItems,
|
||||
removeSetupItem,
|
||||
createSetup,
|
||||
deleteSetup,
|
||||
getAllSetups,
|
||||
getSetupWithItems,
|
||||
removeSetupItem,
|
||||
syncSetupItems,
|
||||
updateSetup,
|
||||
} from "../services/setup.service.ts";
|
||||
|
||||
type Env = { Variables: { db?: any } };
|
||||
@@ -22,63 +22,63 @@ const app = new Hono<Env>();
|
||||
// Setup CRUD
|
||||
|
||||
app.get("/", (c) => {
|
||||
const db = c.get("db");
|
||||
const setups = getAllSetups(db);
|
||||
return c.json(setups);
|
||||
const db = c.get("db");
|
||||
const setups = getAllSetups(db);
|
||||
return c.json(setups);
|
||||
});
|
||||
|
||||
app.post("/", zValidator("json", createSetupSchema), (c) => {
|
||||
const db = c.get("db");
|
||||
const data = c.req.valid("json");
|
||||
const setup = createSetup(db, data);
|
||||
return c.json(setup, 201);
|
||||
const db = c.get("db");
|
||||
const data = c.req.valid("json");
|
||||
const setup = createSetup(db, data);
|
||||
return c.json(setup, 201);
|
||||
});
|
||||
|
||||
app.get("/:id", (c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const setup = getSetupWithItems(db, id);
|
||||
if (!setup) return c.json({ error: "Setup not found" }, 404);
|
||||
return c.json(setup);
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const setup = getSetupWithItems(db, id);
|
||||
if (!setup) return c.json({ error: "Setup not found" }, 404);
|
||||
return c.json(setup);
|
||||
});
|
||||
|
||||
app.put("/:id", zValidator("json", updateSetupSchema), (c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const data = c.req.valid("json");
|
||||
const setup = updateSetup(db, id, data);
|
||||
if (!setup) return c.json({ error: "Setup not found" }, 404);
|
||||
return c.json(setup);
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const data = c.req.valid("json");
|
||||
const setup = updateSetup(db, id, data);
|
||||
if (!setup) return c.json({ error: "Setup not found" }, 404);
|
||||
return c.json(setup);
|
||||
});
|
||||
|
||||
app.delete("/:id", (c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const deleted = deleteSetup(db, id);
|
||||
if (!deleted) return c.json({ error: "Setup not found" }, 404);
|
||||
return c.json({ success: true });
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const deleted = deleteSetup(db, id);
|
||||
if (!deleted) return c.json({ error: "Setup not found" }, 404);
|
||||
return c.json({ success: true });
|
||||
});
|
||||
|
||||
// Setup Items
|
||||
|
||||
app.put("/:id/items", zValidator("json", syncSetupItemsSchema), (c) => {
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const { itemIds } = c.req.valid("json");
|
||||
const db = c.get("db");
|
||||
const id = Number(c.req.param("id"));
|
||||
const { itemIds } = c.req.valid("json");
|
||||
|
||||
const setup = getSetupWithItems(db, id);
|
||||
if (!setup) return c.json({ error: "Setup not found" }, 404);
|
||||
const setup = getSetupWithItems(db, id);
|
||||
if (!setup) return c.json({ error: "Setup not found" }, 404);
|
||||
|
||||
syncSetupItems(db, id, itemIds);
|
||||
return c.json({ success: true });
|
||||
syncSetupItems(db, id, itemIds);
|
||||
return c.json({ success: true });
|
||||
});
|
||||
|
||||
app.delete("/:id/items/:itemId", (c) => {
|
||||
const db = c.get("db");
|
||||
const setupId = Number(c.req.param("id"));
|
||||
const itemId = Number(c.req.param("itemId"));
|
||||
removeSetupItem(db, setupId, itemId);
|
||||
return c.json({ success: true });
|
||||
const db = c.get("db");
|
||||
const setupId = Number(c.req.param("id"));
|
||||
const itemId = Number(c.req.param("itemId"));
|
||||
removeSetupItem(db, setupId, itemId);
|
||||
return c.json({ success: true });
|
||||
});
|
||||
|
||||
export { app as setupRoutes };
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Hono } from "hono";
|
||||
import {
|
||||
getCategoryTotals,
|
||||
getGlobalTotals,
|
||||
getCategoryTotals,
|
||||
getGlobalTotals,
|
||||
} from "../services/totals.service.ts";
|
||||
|
||||
type Env = { Variables: { db?: any } };
|
||||
@@ -9,10 +9,10 @@ type Env = { Variables: { db?: any } };
|
||||
const app = new Hono<Env>();
|
||||
|
||||
app.get("/", (c) => {
|
||||
const db = c.get("db");
|
||||
const categoryTotals = getCategoryTotals(db);
|
||||
const globalTotals = getGlobalTotals(db);
|
||||
return c.json({ categories: categoryTotals, global: globalTotals });
|
||||
const db = c.get("db");
|
||||
const categoryTotals = getCategoryTotals(db);
|
||||
const globalTotals = getGlobalTotals(db);
|
||||
return c.json({ categories: categoryTotals, global: globalTotals });
|
||||
});
|
||||
|
||||
export { app as totalRoutes };
|
||||
|
||||
Reference in New Issue
Block a user