Skip to content

Commit 124d83f

Browse files
hrideshmgivinjabraham
authored andcommitted
feat: add attribute to query for status updates
1 parent 2fab0b5 commit 124d83f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/graphql/queries/member_queries.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,27 @@ impl StatusInfo {
214214
}
215215
}
216216

217+
#[ComplexObject]
218+
impl StatusUpdateRecord {
219+
async fn on_break(&self, ctx: &Context<'_>) -> Result<bool> {
220+
let pool = ctx.data::<Arc<PgPool>>().expect("Pool must be in context.");
221+
222+
let is_on_break = sqlx::query_scalar(
223+
"SELECT EXISTS (
224+
SELECT 1 from StatusBreaks
225+
WHERE year = (SELECT year FROM Member WHERE member_id = $1)
226+
AND $2 BETWEEN start_date AND end_date
227+
)",
228+
)
229+
.bind(self.member_id)
230+
.bind(self.date)
231+
.fetch_optional(pool.as_ref())
232+
.await?;
233+
234+
Ok(is_on_break.unwrap_or(false))
235+
}
236+
}
237+
217238
#[Object]
218239
impl AttendanceInfo {
219240
async fn records(

src/models/status_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use chrono::NaiveDate;
33
use sqlx::FromRow;
44

55
#[derive(SimpleObject, FromRow)]
6+
#[graphql(complex)]
67
pub struct StatusUpdateRecord {
78
pub update_id: i32,
89
pub member_id: i32,

0 commit comments

Comments
 (0)