Skip to content

Commit 9a3292e

Browse files
he1senbrgivinjabraham
authored andcommitted
Revert: Using insert instead of update in mark_attendance.
1 parent 58266ed commit 9a3292e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/graphql/mutations/attendance_mutations.rs

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

4545
let now = Local::now().with_timezone(&Kolkata).time();
4646
let attendance = sqlx::query_as::<_, Attendance>(
47-
"INSERT INTO Attendance (member_id, date, is_present, time_in, time_out)
48-
VALUES ($1, $2, TRUE, $3, $3)
49-
ON CONFLICT (member_id, date) DO UPDATE SET
50-
time_out = $3
51-
RETURNING *",
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+
",
5254
)
55+
.bind(now)
5356
.bind(input.member_id)
5457
.bind(input.date)
55-
.bind(now)
5658
.fetch_one(pool.as_ref())
5759
.await?;
5860

0 commit comments

Comments
 (0)