From 06cada34047bc4900b7cbebd43c4743ca3472eee Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Thu, 2 Feb 2023 18:40:02 +0100 Subject: [PATCH] feat(chalice): return query-left-name for alerts --- api/chalicelib/core/alerts.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/api/chalicelib/core/alerts.py b/api/chalicelib/core/alerts.py index 7da05c2ee..51f42e640 100644 --- a/api/chalicelib/core/alerts.py +++ b/api/chalicelib/core/alerts.py @@ -29,10 +29,13 @@ def get(id): def get_all(project_id): with pg_client.PostgresClient() as cur: query = cur.mogrify("""\ - SELECT * - FROM public.alerts - WHERE project_id =%(project_id)s AND deleted_at ISNULL - ORDER BY created_at;""", + SELECT alerts.*, + COALESCE(metric_series.name, query ->> 'left') AS lef_name + FROM public.alerts + LEFT JOIN metric_series USING (series_id) + WHERE alerts.project_id =%(project_id)s + AND alerts.deleted_at ISNULL + ORDER BY alerts.created_at;""", {"project_id": project_id}) cur.execute(query=query) all = helper.list_to_camel_case(cur.fetchall())