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 <noreply@anthropic.com>
This commit is contained in:
2026-07-08 15:43:21 -04:00
co-authored by Claude Opus 4.8
parent 40624f6e6f
commit 3f3b1362a9
+2 -2
View File
@@ -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; let clientRecord: { defaultHourlyRate: number | null } | null = null;
if (clientId) { if (clientId) {
const found = await ctx.db.query.clients.findFirst({ const found = await ctx.db.query.clients.findFirst({
@@ -514,7 +514,7 @@ export const timeEntriesRouter = createTRPCRouter({
create: protectedProcedure create: protectedProcedure
.input(createSchema) .input(createSchema)
.mutation(async ({ ctx, input }) => { .mutation(async ({ ctx, input }) => {
const clientId = input.clientId?.trim() ?? null; const clientId = input.clientId?.trim() || null;
if (clientId) { if (clientId) {
const client = await ctx.db.query.clients.findFirst({ const client = await ctx.db.query.clients.findFirst({
where: and(eq(clients.id, clientId), eq(clients.createdById, ctx.session.user.id)), where: and(eq(clients.id, clientId), eq(clients.createdById, ctx.session.user.id)),