1
0

FlameAnvil Project Sync (#481)

* FlameAnvil Project Sync

* Perm fixes

* Fix compile

* Fix clippy + run prepare
This commit is contained in:
Geometrically
2022-11-20 19:50:14 -07:00
committed by GitHub
parent 589761bfd9
commit f259d81249
23 changed files with 2501 additions and 1493 deletions

View File

@@ -160,7 +160,7 @@ impl TeamMember {
u.avatar_url avatar_url, u.username username, u.bio bio,
u.created created, u.role user_role, u.badges badges, u.balance balance,
u.payout_wallet payout_wallet, u.payout_wallet_type payout_wallet_type,
u.payout_address payout_address
u.payout_address payout_address, u.flame_anvil_key flame_anvil_key
FROM team_members tm
INNER JOIN users u ON u.id = tm.user_id
WHERE tm.team_id = $1
@@ -191,7 +191,8 @@ impl TeamMember {
balance: m.balance,
payout_wallet: m.payout_wallet.map(|x| RecipientWallet::from_string(&x)),
payout_wallet_type: m.payout_wallet_type.map(|x| RecipientType::from_string(&x)),
payout_address: m.payout_address
payout_address: m.payout_address,
flame_anvil_key: m.flame_anvil_key,
},
payouts_split: m.payouts_split
})))
@@ -228,7 +229,7 @@ impl TeamMember {
u.avatar_url avatar_url, u.username username, u.bio bio,
u.created created, u.role user_role, u.badges badges, u.balance balance,
u.payout_wallet payout_wallet, u.payout_wallet_type payout_wallet_type,
u.payout_address payout_address
u.payout_address payout_address, u.flame_anvil_key flame_anvil_key
FROM team_members tm
INNER JOIN users u ON u.id = tm.user_id
WHERE tm.team_id = ANY($1)
@@ -260,7 +261,8 @@ impl TeamMember {
balance: m.balance,
payout_wallet: m.payout_wallet.map(|x| RecipientWallet::from_string(&x)),
payout_wallet_type: m.payout_wallet_type.map(|x| RecipientType::from_string(&x)),
payout_address: m.payout_address
payout_address: m.payout_address,
flame_anvil_key: m.flame_anvil_key,
},
payouts_split: m.payouts_split
})))
@@ -517,15 +519,24 @@ impl TeamMember {
Ok(())
}
pub async fn delete<'a, 'b, E>(
pub async fn delete<'a, 'b>(
id: TeamId,
user_id: UserId,
executor: E,
) -> Result<(), super::DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
let result = sqlx::query!(
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<(), super::DatabaseError> {
sqlx::query!(
"
UPDATE mods
SET flame_anvil_user = NULL
WHERE (team_id = $1 AND flame_anvil_user = $2 )
",
id as TeamId,
user_id as UserId,
)
.execute(&mut *transaction)
.await?;
sqlx::query!(
"
DELETE FROM team_members
WHERE (team_id = $1 AND user_id = $2 AND NOT role = $3)
@@ -534,16 +545,9 @@ impl TeamMember {
user_id as UserId,
crate::models::teams::OWNER_ROLE,
)
.execute(executor)
.execute(&mut *transaction)
.await?;
if result.rows_affected() != 1 {
return Err(super::DatabaseError::Other(format!(
"Deleting a member failed; {} rows deleted",
result.rows_affected()
)));
}
Ok(())
}