Skip to content

Commit

Permalink
Fix wrong type of user_id when binding to SQL (#363)
Browse files Browse the repository at this point in the history
* Fix wrong type of `user_id` when binding to SQL, open the flag of `persist_to_db`, and add a test case.

* Revert "Fix wrong type of `user_id` when binding to SQL, open the flag of `persist_to_db`, and add a test case."

This reverts commit be7f6f8.

* merge

Co-authored-by: HAOYUatHZ <haoyu@protonmail.com>
  • Loading branch information
silathdiir and 0xmountaintop authored Nov 9, 2021
1 parent 3e0fa61 commit 79fbd48
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/restapi/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ pub async fn get_user(req: HttpRequest, data: web::Data<AppState>) -> Result<Jso
return Ok(Json(user_info.clone()));
}

let sql_query = format!("select * from {} where id = $1 OR l1_address = $1 OR l2_pubkey = $1", ACCOUNT);
let user: AccountDesc = sqlx::query_as(&sql_query).bind(user_id).fetch_one(&data.db).await.map_err(|e| {
log::error!("{:?}", e);
RpcError::bad_request("invalid user ID, l1 address or l2 public key")
})?;
let sql_query = format!("select * from {} where id = $1 OR l1_address = $2 OR l2_pubkey = $2", ACCOUNT);
let user: AccountDesc = sqlx::query_as(&sql_query)
.bind(user_id.parse::<i32>().unwrap_or(-1))
.bind(user_id)
.fetch_one(&data.db)
.await
.map_err(|e| {
log::error!("{:?}", e);
RpcError::bad_request("invalid user ID, l1 address or l2 public key")
})?;

let user_info = AccountDesc {
id: user.id,
Expand Down

0 comments on commit 79fbd48

Please sign in to comment.