Skip to content

Commit 96cf9a5

Browse files
committed
Fix: Incorrect SQL statement in update_days_attended of mod.rs
1 parent b8c33f7 commit 96cf9a5

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/daily_task/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ async fn update_days_attended(member_id: i32, today: NaiveDate, pool: &PgPool) {
158158
r#"
159159
UPDATE AttendanceSummary
160160
SET days_attended = days_attended + 1
161-
WHERE member_id = $2
162-
AND year = $3
163-
AND month = $4
161+
WHERE member_id = $1
162+
AND year = $2
163+
AND month = $3
164164
"#,
165165
)
166166
.bind(member_id)
@@ -181,7 +181,7 @@ async fn update_days_attended(member_id: i32, today: NaiveDate, pool: &PgPool) {
181181
sqlx::query(
182182
r#"
183183
INSERT INTO AttendanceSummary (member_id, year, month, days_attended)
184-
VALUES ($1, $2, 1)
184+
VALUES ($1, $2, $3, 1)
185185
"#,
186186
)
187187
.bind(member_id)

src/graphql/mutations/attendance_mutations.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@ impl AttendanceMutations {
4444

4545
let now = Local::now().with_timezone(&Kolkata).time();
4646
let attendance = sqlx::query_as::<_, Attendance>(
47-
"UPDATE Attendance SET time_in = CASE
48-
WHEN time_in IS NULL THEN $1
49-
ELSE time_in END,
50-
time_out = $1,
51-
is_present = TRUE
52-
WHERE member_id = $2 AND date = $3 RETURNING *
53-
",
47+
"INSERT INTO Attendance (member_id, date, is_present, time_in, time_out)
48+
VALUES ($1, $2, FALSE, $3, $3)
49+
ON CONFLICT (member_id, date) DO UPDATE SET
50+
time_out = $3,
51+
is_present = TRUE
52+
RETURNING *",
5453
)
55-
.bind(now)
5654
.bind(input.member_id)
5755
.bind(input.date)
56+
.bind(now)
5857
.fetch_one(pool.as_ref())
5958
.await?;
6059

0 commit comments

Comments
 (0)