From 5f51d25bc186160fc506afe11c782a8f6d5858da Mon Sep 17 00:00:00 2001 From: Esteban Date: Tue, 3 Feb 2026 02:05:10 -0600 Subject: [PATCH] Fix project service --- water-api/src/services/project.service.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/water-api/src/services/project.service.ts b/water-api/src/services/project.service.ts index d0655f9..7a6d923 100644 --- a/water-api/src/services/project.service.ts +++ b/water-api/src/services/project.service.ts @@ -241,14 +241,22 @@ export async function update(id: string, data: UpdateProjectInput): Promise { - const userCheck = await query<{ count: string }>( - 'SELECT COUNT(*) as count FROM users WHERE project_id = $1', - [id] - ); - const userCount = parseInt(userCheck.rows[0]?.count || '0', 10); + try { + const userCheck = await query<{ count: string }>( + 'SELECT COUNT(*) as count FROM users WHERE project_id = $1', + [id] + ); + const userCount = parseInt(userCheck.rows[0]?.count || '0', 10); - if (userCount > 0) { - throw new Error(`Cannot delete project: ${userCount} user(s) are assigned to this project`); + if (userCount > 0) { + throw new Error(`Cannot delete project: ${userCount} user(s) are assigned to this project`); + } + } catch (error) { + if (error instanceof Error && error.message.includes('column') && error.message.includes('project_id')) { + console.warn('Warning: users.project_id column does not exist. Skipping user dependency check. Please run add_user_project_relation.sql migration.'); + } else { + throw error; + } } // Check for dependent meters