Skip to content

Commit 8c064ef

Browse files
Merge pull request #128 from Khushal928/develop
Add a query that returns their status update count
2 parents 3840498 + 72e8ed1 commit 8c064ef

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/graphql/queries/member_queries.rs

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

56
use crate::models::{
67
attendance::{AttendanceInfo, AttendanceSummaryInfo},
78
member::Member,
89
project::Project,
9-
status_update::StatusUpdateStreakInfo,
10+
status_update::{StatusUpdateHistory, StatusUpdateStreakInfo},
1011
};
1112

1213
#[derive(Default)]
@@ -107,4 +108,35 @@ impl Member {
107108
.await
108109
.unwrap_or_default()
109110
}
111+
112+
async fn status_update_count_by_date(
113+
&self,
114+
ctx: &Context<'_>,
115+
start_date: NaiveDate,
116+
end_date: NaiveDate,
117+
) -> Result<i64> {
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+
}
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+
}
110142
}

0 commit comments

Comments
 (0)