diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-09-01 19:02:31 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-09-01 19:02:31 +0200 |
commit | 98931e63f71a088328ffdbf7db34a2ecfacf3da8 (patch) | |
tree | 2ae628ad0597c06363d52480915b414b19add81c /src/graphql/mutation.rs | |
parent | b9cfbbb420a66296c42fd863fe0bd0fa6f7445c1 (diff) |
Add extended area field for alerts
Diffstat (limited to 'src/graphql/mutation.rs')
-rw-r--r-- | src/graphql/mutation.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/graphql/mutation.rs b/src/graphql/mutation.rs index d6c704a..1440ced 100644 --- a/src/graphql/mutation.rs +++ b/src/graphql/mutation.rs @@ -154,10 +154,29 @@ impl Mutation { Err(e) => return Err(e.into()), }; - let query = format!("INSERT INTO alerts (user_id, area, level) + let query = format!( + "INSERT INTO alerts (user_id, area, level) VALUES($1, {}, $2) - RETURNING id, user_id, extract(epoch from created_at)::double precision as created_at, ST_AsText(area) as area, level, reached_users - ", polygon); + RETURNING + id, + user_id, + extract(epoch from created_at)::double precision as created_at, + ST_AsText(area) as area, + ST_AsText( + ST_Buffer( + area::geography, + CASE + WHEN level = 'One' THEN 0 + WHEN level = 'Two' THEN 1000 + WHEN level = 'Three' THEN 2000 + ELSE 0 + END + ) + ) as extended_area, + level, + reached_users", + polygon + ); match client.query(&query, &[&claims.user_id, &input.level]).await { Ok(rows) => { @@ -168,6 +187,7 @@ impl Mutation { user_id: row.get("user_id"), created_at: row.get::<_, f64>("created_at") as i64, area: row.get("area"), + extended_area: row.get("extended_area"), level: row.get("level"), reached_users: row.get("reached_users"), }) |