Skip to content

Commit 7655247

Browse files
committed
fix incorrect query in mark attendance and remove time fields from its input
1 parent 8690495 commit 7655247

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/graphql/mutations/attendance_mutations.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl AttendanceMutations {
2929
let secret_key = ctx.data::<String>().expect("ROOT_SECRET must be found in context");
3030

3131
let mut mac = HmacSha256::new_from_slice(secret_key.as_bytes()).expect("HMAC can take key of any size");
32-
let message = format!("{}{}{}{}", input.member_id, input.date, input.time_in, input.time_out);
32+
let message = format!("{}{}", input.member_id, input.date);
3333
mac.update(message.as_bytes());
3434

3535
let expected_signature = mac.finalize().into_bytes();
@@ -41,15 +41,16 @@ impl AttendanceMutations {
4141

4242
let now = Local::now().with_timezone(&Kolkata).date_naive();
4343
let attendance = sqlx::query_as::<_, Attendance>(
44-
"INSERT INTO Attendance (member_id, date, is_present, time_in, time_out, created_at, updated_at)
45-
VALUES ($1, $2, $3, $4, $5, $6, $6) RETURNING *",
44+
"UPDATE Attendance SET time_in = CASE
45+
WHEN time_in IN NULL THEN $1
46+
ELSE time_in END,
47+
time_out = $1
48+
WHERE id = $2 AND date = $3 RETURNING *
49+
",
4650
)
51+
.bind(now)
4752
.bind(input.member_id)
4853
.bind(input.date)
49-
.bind(true)
50-
.bind(input.time_in)
51-
.bind(input.time_out)
52-
.bind(now)
5354
.fetch_one(pool.as_ref())
5455
.await?;
5556

src/models/attendance.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,5 @@ pub struct AttendanceSummaryInfo {
4646
pub struct MarkAttendanceInput {
4747
pub member_id: i32,
4848
pub date: NaiveDate,
49-
pub time_in: NaiveTime,
50-
pub time_out: NaiveTime,
5149
pub hmac_signature: String,
5250
}

0 commit comments

Comments
 (0)