From 54ef9a248b15da4d7fa9b59cc5e6bfd89834fcf4 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Wed, 6 Apr 2022 17:51:07 +0200 Subject: [PATCH] feat(api): dashboard format created_at and edited_at --- api/chalicelib/core/dashboards2.py | 8 ++++++++ api/routers/core.py | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/chalicelib/core/dashboards2.py b/api/chalicelib/core/dashboards2.py index afe65d71a..ac382f3d7 100644 --- a/api/chalicelib/core/dashboards2.py +++ b/api/chalicelib/core/dashboards2.py @@ -4,6 +4,7 @@ import schemas from chalicelib.core import custom_metrics, dashboard from chalicelib.utils import helper from chalicelib.utils import pg_client +from chalicelib.utils.TimeUTC import TimeUTC CATEGORY_DESCRIPTION = { 'categ1': 'lorem', @@ -21,6 +22,9 @@ def get_templates(project_id, user_id): rows = cur.fetchall() for r in rows: r["description"] = CATEGORY_DESCRIPTION.get(r["category"], "") + for w in r["widgets"]: + w["created_at"] = TimeUTC.datetime_to_timestamp(w["created_at"]) + w["edited_at"] = TimeUTC.datetime_to_timestamp(w["edited_at"]) return helper.list_to_camel_case(rows) @@ -85,6 +89,10 @@ def get_dashboard(project_id, user_id, dashboard_id): params = {"userId": user_id, "projectId": project_id, "dashboard_id": dashboard_id} cur.execute(cur.mogrify(pg_query, params)) row = cur.fetchone() + if row is not None: + for w in row["widgets"]: + row["created_at"] = TimeUTC.datetime_to_timestamp(w["created_at"]) + row["edited_at"] = TimeUTC.datetime_to_timestamp(w["edited_at"]) return helper.dict_to_camel_case(row) diff --git a/api/routers/core.py b/api/routers/core.py index 20864288d..06743c054 100644 --- a/api/routers/core.py +++ b/api/routers/core.py @@ -394,7 +394,7 @@ def delete_sumologic(projectId: int, context: schemas.CurrentContext = Depends(O def get_integration_status(context: schemas.CurrentContext = Depends(OR_context)): error, integration = integrations_manager.get_integration(tenant_id=context.tenant_id, user_id=context.user_id) - if error is not None: + if error is not None and integration is None: return {"data": {}} return {"data": integration.get_obfuscated()} @@ -406,7 +406,7 @@ def add_edit_jira_cloud(data: schemas.JiraGithubSchema = Body(...), error, integration = integrations_manager.get_integration(tool=integration_jira_cloud.PROVIDER, tenant_id=context.tenant_id, user_id=context.user_id) - if error is not None: + if error is not None and integration is None: return error data.provider = integration_jira_cloud.PROVIDER return {"data": integration.add_edit(data=data.dict())} @@ -429,7 +429,7 @@ def add_edit_github(data: schemas.JiraGithubSchema = Body(...), def delete_default_issue_tracking_tool(context: schemas.CurrentContext = Depends(OR_context)): error, integration = integrations_manager.get_integration(tenant_id=context.tenant_id, user_id=context.user_id) - if error is not None: + if error is not None and integration is None: return error return {"data": integration.delete()}