Skip to content

Commit fa49d84

Browse files
committed
fix: handle missing records gracefully for queries
1 parent 51ca00b commit fa49d84

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/graphql/queries/member_queries.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,19 @@ impl StatusInfo {
9898
Ok(rows)
9999
}
100100

101-
async fn on_date(&self, ctx: &Context<'_>, date: NaiveDate) -> Result<StatusUpdateRecord> {
101+
async fn on_date(
102+
&self,
103+
ctx: &Context<'_>,
104+
date: NaiveDate,
105+
) -> Result<Option<StatusUpdateRecord>> {
102106
let pool = ctx.data::<Arc<PgPool>>()?;
103107

104108
let rows = sqlx::query_as::<_, StatusUpdateRecord>(
105109
"SELECT * FROM StatusUpdateHistory WHERE date = $1 AND member_id=$2",
106110
)
107111
.bind(date)
108112
.bind(self.member_id)
109-
.fetch_one(pool.as_ref())
113+
.fetch_optional(pool.as_ref())
110114
.await?;
111115

112116
Ok(rows)
@@ -201,15 +205,19 @@ impl AttendanceInfo {
201205
Ok(rows)
202206
}
203207

204-
async fn on_date(&self, ctx: &Context<'_>, date: NaiveDate) -> Result<AttendanceRecord> {
208+
async fn on_date(
209+
&self,
210+
ctx: &Context<'_>,
211+
date: NaiveDate,
212+
) -> Result<Option<AttendanceRecord>> {
205213
let pool = ctx.data::<Arc<PgPool>>()?;
206214

207215
let rows = sqlx::query_as::<_, AttendanceRecord>(
208216
"SELECT * FROM Attendance WHERE date = $1 AND member_id=$2",
209217
)
210218
.bind(date)
211219
.bind(self.member_id)
212-
.fetch_one(pool.as_ref())
220+
.fetch_optional(pool.as_ref())
213221
.await?;
214222

215223
Ok(rows)

0 commit comments

Comments
 (0)