Skip to content

Commit ca4f925

Browse files
committed
feat: add statusUpdateCountByDate query to get status update count of a member between two dates
1 parent 3c3bcec commit ca4f925

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/graphql/queries/member_queries.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use async_graphql::{ComplexObject, Context, Object, Result};
22
use sqlx::PgPool;
33
use std::sync::Arc;
4+
use chrono::NaiveDate;
45

56
use crate::models::{
67
attendance::{AttendanceInfo, AttendanceSummaryInfo},
@@ -107,4 +108,22 @@ impl Member {
107108
.await
108109
.unwrap_or_default()
109110
}
111+
112+
async fn status_update_count_by_date(&self,
113+
ctx: &Context<'_>,
114+
start_date:NaiveDate,
115+
end_date:NaiveDate)
116+
-> Result<i64> {
117+
118+
let pool = ctx.data::<Arc<PgPool>>().expect("Pool must be in context.");
119+
120+
let result : i64 = sqlx::query_scalar("SELECT count(*) AS updatecount FROM statusupdatehistory WHERE is_updated = TRUE and member_id=$1 and date BETWEEN $2 and $3;")
121+
.bind(self.member_id)
122+
.bind(start_date)
123+
.bind(end_date)
124+
.fetch_one(pool.as_ref())
125+
.await?;
126+
127+
Ok(result)
128+
}
110129
}

0 commit comments

Comments
 (0)