From 3f3b1362a9b2f988e67a682b9e2403f793686b1c Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Wed, 8 Jul 2026 15:43:21 -0400 Subject: [PATCH] Fix clock-in failing when no client is selected clockIn and create used `input.clientId?.trim() ?? null`, but clients always send `""` (not undefined) for no-client. `??` doesn't catch the empty string, so `""` was inserted into time_entries.client_id, violating the foreign key to clients.id. Use `|| null` to normalize a blank string to null, matching updateRunning. Co-Authored-By: Claude Opus 4.8 --- src/server/api/routers/time-entries.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/api/routers/time-entries.ts b/src/server/api/routers/time-entries.ts index 0c76877..91e585c 100644 --- a/src/server/api/routers/time-entries.ts +++ b/src/server/api/routers/time-entries.ts @@ -242,7 +242,7 @@ export const timeEntriesRouter = createTRPCRouter({ }); } - const clientId = input.clientId?.trim() ?? null; + const clientId = input.clientId?.trim() || null; let clientRecord: { defaultHourlyRate: number | null } | null = null; if (clientId) { const found = await ctx.db.query.clients.findFirst({ @@ -514,7 +514,7 @@ export const timeEntriesRouter = createTRPCRouter({ create: protectedProcedure .input(createSchema) .mutation(async ({ ctx, input }) => { - const clientId = input.clientId?.trim() ?? null; + const clientId = input.clientId?.trim() || null; if (clientId) { const client = await ctx.db.query.clients.findFirst({ where: and(eq(clients.id, clientId), eq(clients.createdById, ctx.session.user.id)),