Skip to content

Commit

Permalink
Add: Update mutation for attendance record
Browse files Browse the repository at this point in the history
  • Loading branch information
Wreck-X committed Jul 2, 2024
1 parent 9ecca65 commit daf8430
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/db/attendance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub struct Attendance {
pub date: NaiveDate,
pub timein: NaiveTime,
pub timeout: NaiveTime,
pub present: bool,
}
22 changes: 22 additions & 0 deletions src/graphql/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl MutationRoot {
Ok(member)
}


//Mutation for adding Attendance to the Attendance table
async fn add_attendance(
&self,
Expand All @@ -62,4 +63,25 @@ impl MutationRoot {

Ok(attendance)
}

async fn update_attendance_present(
&self,
ctx: &Context<'_>,
id: i32,
date: NaiveDate,
present: bool,
) -> Result<Attendance,sqlx::Error> {
let pool = ctx.data::<Arc<PgPool>>().expect("Pool not found in context");

let attendance = sqlx::query_as::<_, Attendance>(
"UPDATE Attendance SET present = $1 WHERE id = $2 AND date = $3 RETURNING *"
)
.bind(present)
.bind(id)
.bind(date)
.fetch_one(pool.as_ref())
.await?;

Ok(attendance)
}
}

0 comments on commit daf8430

Please sign in to comment.