-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from nightly-labs/stats-api
Stats api init methods
- Loading branch information
Showing
40 changed files
with
493 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
export interface Subscription { subscription_type: string, valid_from: bigint, valid_till: bigint, } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,44 @@ | ||
use super::table_struct::Team; | ||
use crate::db::Db; | ||
use crate::tables::registered_app::table_struct::REGISTERED_APPS_TABLE_NAME; | ||
use crate::tables::team::table_struct::TEAM_TABLE_NAME; | ||
use crate::{db::Db, tables::registered_app::table_struct::DbRegisteredApp}; | ||
use sqlx::{query_as, Transaction}; | ||
|
||
impl Db { | ||
pub async fn get_team_by_team_id( | ||
&self, | ||
tx: Option<&mut Transaction<'_, sqlx::Postgres>>, | ||
team_id: &String, | ||
) -> Result<Team, sqlx::Error> { | ||
) -> Result<Option<Team>, sqlx::Error> { | ||
let query = format!("SELECT * FROM {TEAM_TABLE_NAME} WHERE team_id = $1"); | ||
let typed_query = query_as::<_, Team>(&query); | ||
|
||
match tx { | ||
Some(tx) => return typed_query.bind(&team_id).fetch_one(&mut **tx).await, | ||
Some(tx) => return typed_query.bind(&team_id).fetch_optional(&mut **tx).await, | ||
None => { | ||
return typed_query | ||
.bind(&team_id) | ||
.fetch_one(&self.connection_pool) | ||
.fetch_optional(&self.connection_pool) | ||
.await | ||
} | ||
} | ||
} | ||
|
||
pub async fn get_registered_apps_by_team_id( | ||
&self, | ||
team_id: &String, | ||
) -> Result<Vec<DbRegisteredApp>, sqlx::Error> { | ||
let query = format!( | ||
"SELECT r.* FROM {REGISTERED_APPS_TABLE_NAME} r | ||
INNER JOIN team t ON r.team_id = t.team_id | ||
WHERE t.team_id = $1 | ||
ORDER BY t.registration_timestamp DESC" | ||
); | ||
let typed_query = query_as::<_, DbRegisteredApp>(&query); | ||
|
||
return typed_query | ||
.bind(&team_id) | ||
.fetch_all(&self.connection_pool) | ||
.await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.