Skip to content

Commit 6588045

Browse files
authored
Merge pull request #68 from he1senbrg/main
Fix: Attendance not being logged
2 parents dc4f648 + c9ebe2c commit 6588045

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/graphql/mutations/attendance_mutations.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,15 @@ 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, TRUE, $3, $3)
49+
ON CONFLICT (member_id, date) DO UPDATE SET
50+
time_out = $3
51+
RETURNING *",
5452
)
55-
.bind(now)
5653
.bind(input.member_id)
5754
.bind(input.date)
55+
.bind(now)
5856
.fetch_one(pool.as_ref())
5957
.await?;
6058

0 commit comments

Comments
 (0)