summaryrefslogtreecommitdiff
path: root/src/graphql
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-09-10 16:19:08 +0200
committerSanto Cariotti <santo@dcariotti.me>2024-09-10 16:19:08 +0200
commit2d3e4e8c026bb7f17eee98840b70694d99a655c2 (patch)
tree59f63e20b14539c26bded0e47c3605c6e0f7ee6f /src/graphql
parent4bf39092ecbfbd69aac83f331b92d0fffa431d1b (diff)
Fix notification for alert with no position IDs
Diffstat (limited to 'src/graphql')
-rw-r--r--src/graphql/types/alert.rs52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/graphql/types/alert.rs b/src/graphql/types/alert.rs
index f74023a..ba93c03 100644
--- a/src/graphql/types/alert.rs
+++ b/src/graphql/types/alert.rs
@@ -299,33 +299,37 @@ pub mod mutations {
let placeholders: Vec<String> = (1..=position_ids.len())
.map(|i| format!("${}", i))
.collect();
- let query = format!(
- "SELECT DISTINCT u.notification_token FROM positions p JOIN users u ON u.id = p.user_id
- WHERE p.id IN ({}) AND notification_token IS NOT NULL",
- placeholders.join(", ")
- );
- let tokens: Vec<String> = client
- .query(
- &query,
- &position_ids
- .iter()
- .map(|id| id as &(dyn tokio_postgres::types::ToSql + Sync))
- .collect::<Vec<&(dyn tokio_postgres::types::ToSql + Sync)>>(),
+ if placeholders.len() > 0 {
+ let query = format!(
+ "SELECT DISTINCT u.notification_token FROM positions p JOIN users u ON u.id = p.user_id
+ WHERE p.id IN ({}) AND notification_token IS NOT NULL",
+ placeholders.join(", ")
+ );
+
+ println!("{query}");
+ let tokens: Vec<String> = client
+ .query(
+ &query,
+ &position_ids
+ .iter()
+ .map(|id| id as &(dyn tokio_postgres::types::ToSql + Sync))
+ .collect::<Vec<&(dyn tokio_postgres::types::ToSql + Sync)>>(),
+ )
+ .await
+ .unwrap()
+ .iter()
+ .map(|row| format!("ExponentPushToken[{}]", row.get::<usize, String>(0)))
+ .collect();
+
+ expo::send(
+ tokens,
+ "New Alert!".to_string(),
+ "Keep an eye open".to_string(),
)
.await
- .unwrap()
- .iter()
- .map(|row| format!("ExponentPushToken[{}]", row.get::<usize, String>(0)))
- .collect();
-
- expo::send(
- tokens,
- "New Alert!".to_string(),
- "Keep an eye open".to_string(),
- )
- .await
- .unwrap();
+ .unwrap();
+ }
Ok(alert)
}