fix: user_exists was a copy of hostname_exists, now fixed
This commit is contained in:
parent
a57759ea80
commit
cb9b8d6d0d
2 changed files with 61 additions and 10 deletions
|
@ -18,6 +18,24 @@
|
||||||
},
|
},
|
||||||
"query": "SELECT ID FROM starchart_forges WHERE hostname = $1"
|
"query": "SELECT ID FROM starchart_forges WHERE hostname = $1"
|
||||||
},
|
},
|
||||||
|
"2afb17ba3753aa440465a836b46b7a1466f25791cfc4d0acdd38bc2755ae3e86": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "ID",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Int64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "SELECT ID FROM starchart_users WHERE username = $1"
|
||||||
|
},
|
||||||
"30de2d37dd1bd602249cd2adfab499e41105249c20dc58cb360f539d6a782fa1": {
|
"30de2d37dd1bd602249cd2adfab499e41105249c20dc58cb360f539d6a782fa1": {
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
|
@ -46,6 +64,24 @@
|
||||||
},
|
},
|
||||||
"query": "INSERT INTO\n starchart_forges (hostname, verified_on, forge_type ) \n VALUES ($1, $2, (SELECT ID FROM starchart_forge_type WHERE name = $3))"
|
"query": "INSERT INTO\n starchart_forges (hostname, verified_on, forge_type ) \n VALUES ($1, $2, (SELECT ID FROM starchart_forge_type WHERE name = $3))"
|
||||||
},
|
},
|
||||||
|
"a81dd4b5df666e22fac211092e7b8425d838dd9023aa2b17659352f30831944d": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "ID",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Int64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "SELECT ID FROM starchart_users WHERE username = $1 AND \n hostname_id = (SELECT ID FROM starchart_forges WHERE hostname = $2)"
|
||||||
|
},
|
||||||
"b4985ad11fafa367302ca9c0126b95bc70f6ae387f9de649aabb2ef424f676db": {
|
"b4985ad11fafa367302ca9c0126b95bc70f6ae387f9de649aabb2ef424f676db": {
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
|
|
|
@ -191,16 +191,31 @@ impl SCDatabase for Database {
|
||||||
/// check if an user exists. When hostname of a forge instace is provided, username search is
|
/// check if an user exists. When hostname of a forge instace is provided, username search is
|
||||||
/// done only on that forge
|
/// done only on that forge
|
||||||
async fn user_exists(&self, username: &str, hostname: Option<&str>) -> DBResult<bool> {
|
async fn user_exists(&self, username: &str, hostname: Option<&str>) -> DBResult<bool> {
|
||||||
match sqlx::query!(
|
match hostname {
|
||||||
"SELECT ID FROM starchart_forges WHERE hostname = $1",
|
Some(hostname) => match sqlx::query!(
|
||||||
hostname
|
"SELECT ID FROM starchart_users WHERE username = $1 AND
|
||||||
)
|
hostname_id = (SELECT ID FROM starchart_forges WHERE hostname = $2)",
|
||||||
.fetch_one(&self.pool)
|
username,
|
||||||
.await
|
hostname,
|
||||||
{
|
)
|
||||||
Ok(_) => Ok(true),
|
.fetch_one(&self.pool)
|
||||||
Err(Error::RowNotFound) => Ok(false),
|
.await
|
||||||
Err(e) => Err(DBError::DBError(Box::new(e).into())),
|
{
|
||||||
|
Ok(_) => Ok(true),
|
||||||
|
Err(Error::RowNotFound) => Ok(false),
|
||||||
|
Err(e) => Err(DBError::DBError(Box::new(e).into())),
|
||||||
|
},
|
||||||
|
None => match sqlx::query!(
|
||||||
|
"SELECT ID FROM starchart_users WHERE username = $1",
|
||||||
|
username
|
||||||
|
)
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => Ok(true),
|
||||||
|
Err(Error::RowNotFound) => Ok(false),
|
||||||
|
Err(e) => Err(DBError::DBError(Box::new(e).into())),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue