Skip to content

Commit

Permalink
chore: revert 196 (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Sep 21, 2023
1 parent bd253d6 commit 0a55521
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 9 additions & 12 deletions src/stores/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,10 @@ impl ClientStore for sqlx::PgPool {
client.token
);

let mut transaction = self.begin().await?;

sqlx::query("DELETE FROM public.clients WHERE id = $1 OR device_token = $2")
.bind(id)
.bind(client.token.clone())
.execute(&mut transaction)
.await?;

let mut insert_query = sqlx::QueryBuilder::new(
let mut query_builder = sqlx::QueryBuilder::new(
"INSERT INTO public.clients (id, tenant_id, push_type, device_token)",
);
insert_query.push_values(
query_builder.push_values(
vec![(id, tenant_id, client.push_type, client.token)],
|mut b, client| {
b.push_bind(client.0)
Expand All @@ -51,8 +43,13 @@ impl ClientStore for sqlx::PgPool {
.push_bind(client.3);
},
);
insert_query.build().execute(&mut transaction).await?;
transaction.commit().await?;
query_builder.push(
" ON CONFLICT (id) DO UPDATE SET device_token = EXCLUDED.device_token, tenant_id = \
EXCLUDED.tenant_id, push_type = EXCLUDED.push_type",
);
let query = query_builder.build();

self.execute(query).await?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/stores/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub trait NotificationStore {
client_id: &str,
payload: &MessagePayload,
) -> stores::Result<Notification>;
async fn get_notification(&self, tenant_id: &str, id: &str) -> stores::Result<Notification>;
async fn delete_notification(&self, tenant_id: &str, id: &str) -> stores::Result<()>;
async fn get_notification(&self, id: &str, tenant_id: &str) -> stores::Result<Notification>;
async fn delete_notification(&self, id: &str, tenant_id: &str) -> stores::Result<()>;
}

#[async_trait]
Expand Down

0 comments on commit 0a55521

Please sign in to comment.