Fix project service
This commit is contained in:
@@ -241,6 +241,7 @@ export async function update(id: string, data: UpdateProjectInput): Promise<Proj
|
||||
* @returns True if deleted, throws error if has dependencies
|
||||
*/
|
||||
export async function deleteProject(id: string): Promise<boolean> {
|
||||
try {
|
||||
const userCheck = await query<{ count: string }>(
|
||||
'SELECT COUNT(*) as count FROM users WHERE project_id = $1',
|
||||
[id]
|
||||
@@ -250,6 +251,13 @@ export async function deleteProject(id: string): Promise<boolean> {
|
||||
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
|
||||
const meterCheck = await query<{ count: string }>(
|
||||
|
||||
Reference in New Issue
Block a user