Added a function to set a member roles to admin

This commit is contained in:
xeovalyte 2025-02-26 15:14:51 +01:00
parent 10297f9114
commit 0b8d6e2cc2
Signed by: xeovalyte
SSH Key Fingerprint: SHA256:GWI1hq+MNKR2UOcvk7n9tekASXT8vyazK7vDF9Xyciw

View File

@ -17,6 +17,7 @@ struct Cli {
enum Commands {
Serve,
CreateAdminMember,
SetMemberAdmin { relatiecode: String },
}
pub async fn parse(pool: PgPool) {
@ -29,6 +30,11 @@ pub async fn parse(pool: PgPool) {
Some(Commands::CreateAdminMember) => {
create_admin_member(&pool).await.unwrap();
}
Some(Commands::SetMemberAdmin {
relatiecode: member_id,
}) => {
set_member_admin(&pool, member_id).await.unwrap();
}
None => {}
}
}
@ -54,3 +60,17 @@ pub async fn create_admin_member(pool: &PgPool) -> Result<(), sqlx::Error> {
Ok(())
}
pub async fn set_member_admin(pool: &PgPool, id: &str) -> Result<(), sqlx::Error> {
sqlx::query!(
"
UPDATE ONLY members SET roles = $1 WHERE member_id = $2
",
Roles::ADMIN.bits() as i64,
id
)
.execute(pool)
.await?;
Ok(())
}