Added diploma support

This commit is contained in:
xeovalyte 2024-10-09 12:14:56 +02:00
parent 1aa7a0565d
commit 570edc1b44
Signed by: xeovalyte
SSH Key Fingerprint: SHA256:kSQDrQDmKzljJzfGYcd3m9RqHi4h8rSwkZ3sQ9kBURo
7 changed files with 64 additions and 66 deletions

View File

@ -3019,8 +3019,8 @@ details.collapse summary::-webkit-details-marker {
max-width: 42rem;
}
.max-w-4xl {
max-width: 56rem;
.max-w-3xl {
max-width: 48rem;
}
.max-w-lg {

View File

@ -9,9 +9,7 @@ pub fn Members() -> Element {
rsx! {
div {
class: "flex justify-center",
div {
class: "max-w-4xl w-full",
class: "max-w-3xl w-full",
h2 { class: "font-bold text-lg", "Leden" },
match &*members.read_unchecked() {
Some(Ok(res)) => rsx! {
@ -39,7 +37,6 @@ pub fn Members() -> Element {
}
}
}
}
}
#[derive(Props, Clone, PartialEq)]

View File

@ -7,9 +7,7 @@ pub fn Users() -> Element {
rsx! {
div {
class: "flex justify-center",
div {
class: "max-w-4xl w-full",
class: "max-w-3xl w-full",
h2 { class: "font-bold text-lg", "Gebruikers" },
match &*users.read_unchecked() {
Some(Ok(res)) => rsx! {
@ -36,7 +34,6 @@ pub fn Users() -> Element {
}
}
}
}
}
#[derive(Props, Clone, PartialEq)]

View File

@ -251,9 +251,11 @@ fn Members() -> Element {
}
div {
class: "",
span { "LS2" },
if let Some(d) = member.diploma {
span { "{d}" }
span { class: "mx-1.5", "" }
span { "A1, B2" }
}
span { {member.hours.join(", ")} }
}
},
div {
@ -308,7 +310,7 @@ fn Members() -> Element {
async fn fetch_members() -> Result<Vec<Member>, ServerFnError> {
let user = Session::fetch_current_user().await?;
let members = Member::fetch_from_user(user.id).await?;
let members = Member::fetch_from_user(&user.id).await?;
Ok(members)
}

View File

@ -1,6 +1,8 @@
#[cfg(feature = "server")]
use crate::util::surrealdb::{thing_to_string, DB};
use serde::{Deserialize, Serialize};
#[cfg(feature = "server")]
use surrealdb::sql::Thing;
#[cfg(feature = "server")]
mod migration;
@ -57,12 +59,10 @@ impl Member {
}
}
pub async fn fetch_from_user(user_id: String) -> Result<Vec<Self>, crate::Error> {
pub async fn fetch_from_user(user_id: &str) -> Result<Vec<Self>, crate::Error> {
let mut res = DB
.query(
"SELECT VALUE ->user_to_member->member.* FROM ONLY type::thing('user', $user_id)",
)
.bind(("user_id", user_id))
.query("SELECT VALUE ->user_to_member->member.* FROM ONLY $user")
.bind(("user", Thing::from(("user", user_id))))
.await?;
res = res.check()?;

View File

@ -202,7 +202,7 @@ impl MembersMigration {
}
pub async fn migrate(id: u16) -> Result<(), Box<dyn std::error::Error>> {
let members_store = MEMBERS_STORE.lock().await;
let mut members_store = MEMBERS_STORE.lock().await;
let members_migration = match members_store.get(&id) {
Some(mm) => mm,
@ -212,31 +212,30 @@ impl MembersMigration {
let mut transaction = DB.query(BeginStatement::default());
for member in members_migration.updated.clone() {
// TODO add hours and diploma support
let id = member.id.clone();
transaction = transaction.query(format!("UPDATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id};"))
transaction = transaction.query(format!("UPDATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id}, diploma = $diploma_{id};"))
.bind((format!("id_{id}"), member.id))
.bind((format!("name_first_{id}"), member.name.first))
.bind((format!("name_full_{id}"), member.name.full))
.bind((format!("hours_{id}"), member.hours))
.bind((format!("groups_{id}"), member.groups));
.bind((format!("groups_{id}"), member.groups))
.bind((format!("diploma_{id}"), member.diploma));
}
for member in members_migration.inserted.clone() {
// TODO add hours and diploma support
let id = member.id.clone();
transaction = transaction.query(format!("CREATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id};"))
transaction = transaction.query(format!("CREATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id}, diploma = $diploma_{id};"))
.bind((format!("id_{id}"), member.id))
.bind((format!("name_first_{id}"), member.name.first))
.bind((format!("name_full_{id}"), member.name.full))
.bind((format!("hours_{id}"), member.hours))
.bind((format!("groups_{id}"), member.groups));
.bind((format!("groups_{id}"), member.groups))
.bind((format!("diploma_{id}"), member.diploma));
}
for member in members_migration.removed.clone() {
// TODO add hours and diploma support
let id = member.id.clone();
transaction = transaction
@ -249,6 +248,8 @@ impl MembersMigration {
.await?
.check()?;
members_store.remove(&id);
Ok(())
}
}

View File

@ -66,6 +66,7 @@ async fn apply_queries() -> surrealdb::Result<()> {
DEFINE FIELD name.full ON TABLE member TYPE string;
DEFINE FIELD registration_token ON TABLE member TYPE string
VALUE rand::string(16);
DEFINE FIELD diploma ON TABLE member TYPE option<string>;
DEFINE FIELD hours ON TABLE member TYPE set<string>;
DEFINE FIELD groups ON TABLE member TYPE set<string>;
",