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]; }