Skip to content

Commit

Permalink
fix: only import discord if it is in qpay
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Feb 16, 2025
1 parent 2cc90ac commit 4666868
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ impl QPayMember {
&format!("SELECT discord_username, origination FROM {table} WHERE email = $1"),
&[&self.email],
) {
Ok(row) if row_missing(&row, "discord_username") => InDb::NeedsDiscord,
Ok(row) if self.discord().is_some() && row_missing(&row, "discord_username") => {
InDb::NeedsDiscord
}
Ok(row) if self.origination().is_some() && row_missing(&row, "origination") => {
InDb::NeedsOrigination
}
Expand All @@ -36,24 +38,17 @@ impl QPayMember {
db: &mut postgres::Client,
table: &str,
) -> Result<Option<CrobotWebook>> {
match self
.responses
.get("Do you have a discord username? If so, what is it?")
.and_then(|input| match input.is_empty() {
true => None,
false => Some(input),
}) {
None => Ok(None),
Some(username) => {
let query = format!("UPDATE {table} SET discord_username = $1 WHERE email = $2",);

let _result = db
.query(&query, &[username, &self.email])
.with_context(|| "Updating")?;

Ok(Some(CrobotWebook::new(username.to_owned())))
}
}
let Some(username) = self.discord() else {
return Ok(None);
};

let query = format!("UPDATE {table} SET discord_username = $1 WHERE email = $2",);

let _result = db
.query(&query, &[&username, &self.email])
.with_context(|| "Updating")?;

Ok(Some(CrobotWebook::new(username.to_owned())))
}

pub fn create_membership(&self, db: &mut postgres::Client, table: &str) -> Result<()> {
Expand Down
6 changes: 6 additions & 0 deletions src/qpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@ impl QPayMember {
.get("Are you a domestic or international student?")
.map(|s| s.as_str())
}

pub fn discord(&self) -> Option<&'_ str> {
self.responses
.get("Do you have a discord username? If so, what is it?")
.map(|s| s.as_str())
}
}

0 comments on commit 4666868

Please sign in to comment.