From 05e241c7923d603ae0185f07b3cfc09a439d7692 Mon Sep 17 00:00:00 2001 From: olsch01 Date: Tue, 3 Mar 2026 10:05:29 -0500 Subject: [PATCH] fix: allow null planned_date when updating projects Empty string date values from the frontend were being passed directly to PostgreSQL, which cannot cast "" to DATE. Normalize empty strings to null for all date columns in the update method and the dedicated updatePlannedDate endpoint. Co-Authored-By: Claude Opus 4.6 --- backend/src/modules/projects/projects.service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/modules/projects/projects.service.ts b/backend/src/modules/projects/projects.service.ts index 11a9faf..77914cb 100644 --- a/backend/src/modules/projects/projects.service.ts +++ b/backend/src/modules/projects/projects.service.ts @@ -157,6 +157,9 @@ export class ProjectsService { const params: any[] = []; let idx = 1; + // Date columns must be null (not empty string) for PostgreSQL DATE type + const dateFields = new Set(['last_replacement_date', 'next_replacement_date', 'planned_date']); + // Build dynamic SET clause const fields: [string, string][] = [ ['name', 'name'], ['description', 'description'], ['category', 'category'], @@ -175,7 +178,8 @@ export class ProjectsService { for (const [dtoKey, dbCol] of fields) { if (dto[dtoKey] !== undefined) { sets.push(`${dbCol} = $${idx++}`); - params.push(dto[dtoKey]); + const val = dateFields.has(dtoKey) && dto[dtoKey] === '' ? null : dto[dtoKey]; + params.push(val); } } @@ -276,7 +280,7 @@ export class ProjectsService { await this.findOne(id); const rows = await this.tenant.query( 'UPDATE projects SET planned_date = $2, updated_at = NOW() WHERE id = $1 RETURNING *', - [id, planned_date], + [id, planned_date || null], ); return rows[0]; }