Skip to content

Commit 7d8ecfd

Browse files
committed
feat: add status_update_history query that returns their update history of last six months
1 parent ca4f925 commit 7d8ecfd

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/graphql/queries/member_queries.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use async_graphql::{ComplexObject, Context, Object, Result};
2+
use chrono::NaiveDate;
23
use sqlx::PgPool;
34
use std::sync::Arc;
4-
use chrono::NaiveDate;
55

66
use crate::models::{
77
attendance::{AttendanceInfo, AttendanceSummaryInfo},
88
member::Member,
99
project::Project,
10-
status_update::StatusUpdateStreakInfo,
10+
status_update::{StatusUpdateHistory, StatusUpdateStreakInfo},
1111
};
1212

1313
#[derive(Default)]
@@ -109,12 +109,12 @@ impl Member {
109109
.unwrap_or_default()
110110
}
111111

112-
async fn status_update_count_by_date(&self,
112+
async fn status_update_count_by_date(
113+
&self,
113114
ctx: &Context<'_>,
114-
start_date:NaiveDate,
115-
end_date:NaiveDate)
116-
-> Result<i64> {
117-
115+
start_date: NaiveDate,
116+
end_date: NaiveDate,
117+
) -> Result<i64> {
118118
let pool = ctx.data::<Arc<PgPool>>().expect("Pool must be in context.");
119119

120120
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;")
@@ -126,4 +126,17 @@ impl Member {
126126

127127
Ok(result)
128128
}
129+
130+
async fn status_update_history(&self, ctx: &Context<'_>) -> Result<Vec<StatusUpdateHistory>> {
131+
let pool = ctx.data::<Arc<PgPool>>().expect("Pool must be in context.");
132+
133+
let history = sqlx::query_as::<_, StatusUpdateHistory>(
134+
"SELECT * FROM StatusUpdateHistory WHERE member_id = $1 AND date BETWEEN (SELECT MAX(date) FROM StatusUpdateHistory WHERE member_id = $1) - INTERVAL '6 months' AND (SELECT MAX(date) FROM StatusUpdateHistory WHERE member_id = $1);"
135+
)
136+
.bind(self.member_id)
137+
.fetch_all(pool.as_ref())
138+
.await?;
139+
140+
Ok(history)
141+
}
129142
}

0 commit comments

Comments
 (0)