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:
@@ -6,6 +6,9 @@ interface ThreadListItem {
|
||||
name: string;
|
||||
status: "active" | "resolved";
|
||||
resolvedCandidateId: number | null;
|
||||
categoryId: number;
|
||||
categoryName: string;
|
||||
categoryEmoji: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
candidateCount: number;
|
||||
@@ -60,7 +63,7 @@ export function useThread(threadId: number | null) {
|
||||
export function useCreateThread() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: { name: string }) =>
|
||||
mutationFn: (data: { name: string; categoryId: number }) =>
|
||||
apiPost<ThreadListItem>("/api/threads", data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["threads"] });
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user