From 7e9dbd60f55f02ab065c764f8230aabaa6778eed Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 5 Sep 2024 11:25:29 +0200 Subject: Keep a device token for the user notification --- src/graphql/types/user.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src/graphql/types') diff --git a/src/graphql/types/user.rs b/src/graphql/types/user.rs index b185a16..09404ec 100644 --- a/src/graphql/types/user.rs +++ b/src/graphql/types/user.rs @@ -1,5 +1,5 @@ use crate::{errors::AppError, state::AppState}; -use async_graphql::{Context, Object}; +use async_graphql::{Context, InputObject, Object}; use serde::{Deserialize, Serialize}; use tokio_postgres::Client; @@ -13,6 +13,7 @@ pub struct User { pub password: String, pub name: Option, pub address: Option, + pub notification_token: Option, pub is_admin: bool, } @@ -38,11 +39,20 @@ impl User { self.address.clone().unwrap_or(String::default()) } + async fn notification_token(&self) -> String { + String::from("******") + } + async fn is_admin(&self) -> bool { self.is_admin } } +#[derive(InputObject, Debug)] +pub struct RegisterNotificationToken { + pub token: String, +} + /// Get users from the database pub async fn get_users<'ctx>( ctx: &Context<'ctx>, @@ -68,7 +78,7 @@ pub async fn get_users<'ctx>( let rows = client .query( - "SELECT id, email, password, name, address, is_admin FROM users LIMIT $1 OFFSET $2", + "SELECT id, email, name, address, is_admin FROM users LIMIT $1 OFFSET $2", &[&limit.unwrap_or(20), &offset.unwrap_or(0)], ) .await @@ -79,9 +89,10 @@ pub async fn get_users<'ctx>( .map(|row| User { id: row.get("id"), email: row.get("email"), - password: row.get("password"), + password: String::new(), name: row.get("name"), address: row.get("address"), + notification_token: None, is_admin: row.get("is_admin"), }) .collect(); @@ -107,7 +118,7 @@ pub async fn get_user_by_id<'ctx>(ctx: &Context<'ctx>, id: i32) -> Result(ctx: &Context<'ctx>, id: i32) -> Result(ctx: &Context<'ctx>, id: i32) -> Result(ctx: &Context<'ctx>, id: i32) -> Result Result { let rows = client .query( - "SELECT id, email, password, name, address, is_admin FROM users WHERE id = $1", + "SELECT id, email, name, address, is_admin FROM users WHERE id = $1", &[&id], ) .await @@ -162,9 +174,10 @@ pub async fn find_user(client: &Client, id: i32) -> Result { .map(|row| User { id: row.get("id"), email: row.get("email"), - password: row.get("password"), + password: String::new(), name: row.get("name"), address: row.get("address"), + notification_token: None, is_admin: row.get("is_admin"), }) .collect(); -- cgit v1.2.3-71-g8e6c