Skip to content

Commit

Permalink
feat(project): populate total task field after task creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj-Gupta4 committed Mar 3, 2025
1 parent fff789a commit 9345490
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/backend/app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,18 @@ async def create(
await cur.execute(sql, data)
result = await cur.fetchall()

return bool(result)
if success := bool(result):
update_project_sql = """
UPDATE projects
SET total_tasks = (
SELECT COALESCE(MAX(project_task_index), 0)
FROM public.tasks WHERE project_id = %(project_id)s
)
WHERE id = %(project_id)s;
"""
await cur.execute(update_project_sql, {"project_id": project_id})

return success


class DbProject(BaseModel):
Expand Down

0 comments on commit 9345490

Please sign in to comment.