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 <noreply@anthropic.com>
This commit is contained in:
2026-03-03 10:05:29 -05:00
parent 5ee4c71fc1
commit 05e241c792

View File

@@ -157,6 +157,9 @@ export class ProjectsService {
const params: any[] = []; const params: any[] = [];
let idx = 1; 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 // Build dynamic SET clause
const fields: [string, string][] = [ const fields: [string, string][] = [
['name', 'name'], ['description', 'description'], ['category', 'category'], ['name', 'name'], ['description', 'description'], ['category', 'category'],
@@ -175,7 +178,8 @@ export class ProjectsService {
for (const [dtoKey, dbCol] of fields) { for (const [dtoKey, dbCol] of fields) {
if (dto[dtoKey] !== undefined) { if (dto[dtoKey] !== undefined) {
sets.push(`${dbCol} = $${idx++}`); 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); await this.findOne(id);
const rows = await this.tenant.query( const rows = await this.tenant.query(
'UPDATE projects SET planned_date = $2, updated_at = NOW() WHERE id = $1 RETURNING *', 'UPDATE projects SET planned_date = $2, updated_at = NOW() WHERE id = $1 RETURNING *',
[id, planned_date], [id, planned_date || null],
); );
return rows[0]; return rows[0];
} }