feat(04-01): update thread service, routes, and hooks for categoryId

- createThread now inserts categoryId from data
- getAllThreads joins categories table, returns categoryName/categoryEmoji
- updateThread accepts optional categoryId
- ThreadListItem interface includes category fields
- useCreateThread hook sends categoryId
- Fix test files to pass categoryId when creating threads

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-15 16:31:48 +01:00
parent 629e14f60c
commit ed8508110f
4 changed files with 30 additions and 23 deletions

View File

@@ -8,7 +8,7 @@ type Db = typeof prodDb;
export function createThread(db: Db = prodDb, data: CreateThread) {
return db
.insert(threads)
.values({ name: data.name })
.values({ name: data.name, categoryId: data.categoryId })
.returning()
.get();
}
@@ -20,6 +20,9 @@ export function getAllThreads(db: Db = prodDb, includeResolved = false) {
name: threads.name,
status: threads.status,
resolvedCandidateId: threads.resolvedCandidateId,
categoryId: threads.categoryId,
categoryName: categories.name,
categoryEmoji: categories.emoji,
createdAt: threads.createdAt,
updatedAt: threads.updatedAt,
candidateCount: sql<number>`(
@@ -36,6 +39,7 @@ export function getAllThreads(db: Db = prodDb, includeResolved = false) {
)`.as("max_price_cents"),
})
.from(threads)
.innerJoin(categories, eq(threads.categoryId, categories.id))
.orderBy(desc(threads.createdAt));
if (!includeResolved) {
@@ -73,7 +77,7 @@ export function getThreadWithCandidates(db: Db = prodDb, threadId: number) {
return { ...thread, candidates: candidateList };
}
export function updateThread(db: Db = prodDb, threadId: number, data: Partial<{ name: string }>) {
export function updateThread(db: Db = prodDb, threadId: number, data: Partial<{ name: string; categoryId: number }>) {
const existing = db.select({ id: threads.id }).from(threads)
.where(eq(threads.id, threadId)).get();
if (!existing) return null;