Skip to content

Commit 4666868

Browse files
committed
fix: only import discord if it is in qpay
1 parent 2cc90ac commit 4666868

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/postgres.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ impl QPayMember {
2121
&format!("SELECT discord_username, origination FROM {table} WHERE email = $1"),
2222
&[&self.email],
2323
) {
24-
Ok(row) if row_missing(&row, "discord_username") => InDb::NeedsDiscord,
24+
Ok(row) if self.discord().is_some() && row_missing(&row, "discord_username") => {
25+
InDb::NeedsDiscord
26+
}
2527
Ok(row) if self.origination().is_some() && row_missing(&row, "origination") => {
2628
InDb::NeedsOrigination
2729
}
@@ -36,24 +38,17 @@ impl QPayMember {
3638
db: &mut postgres::Client,
3739
table: &str,
3840
) -> Result<Option<CrobotWebook>> {
39-
match self
40-
.responses
41-
.get("Do you have a discord username? If so, what is it?")
42-
.and_then(|input| match input.is_empty() {
43-
true => None,
44-
false => Some(input),
45-
}) {
46-
None => Ok(None),
47-
Some(username) => {
48-
let query = format!("UPDATE {table} SET discord_username = $1 WHERE email = $2",);
49-
50-
let _result = db
51-
.query(&query, &[username, &self.email])
52-
.with_context(|| "Updating")?;
53-
54-
Ok(Some(CrobotWebook::new(username.to_owned())))
55-
}
56-
}
41+
let Some(username) = self.discord() else {
42+
return Ok(None);
43+
};
44+
45+
let query = format!("UPDATE {table} SET discord_username = $1 WHERE email = $2",);
46+
47+
let _result = db
48+
.query(&query, &[&username, &self.email])
49+
.with_context(|| "Updating")?;
50+
51+
Ok(Some(CrobotWebook::new(username.to_owned())))
5752
}
5853

5954
pub fn create_membership(&self, db: &mut postgres::Client, table: &str) -> Result<()> {

src/qpay.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,10 @@ impl QPayMember {
6060
.get("Are you a domestic or international student?")
6161
.map(|s| s.as_str())
6262
}
63+
64+
pub fn discord(&self) -> Option<&'_ str> {
65+
self.responses
66+
.get("Do you have a discord username? If so, what is it?")
67+
.map(|s| s.as_str())
68+
}
6369
}

0 commit comments

Comments
 (0)