Skip to content

Leave tracking from amD#170

Open
naveen28204280 wants to merge 5 commits intoamfoss:developfrom
naveen28204280:leave_tracking
Open

Leave tracking from amD#170
naveen28204280 wants to merge 5 commits intoamfoss:developfrom
naveen28204280:leave_tracking

Conversation

@naveen28204280
Copy link

This PR

  • creates a table Leave for
    • mutation mark_ leave
    • query leave_count
  • add discord_id optional param for Member object so amD can query using discord_id itself
    These are currently meant only to be accessed by amD for marking and fetching leaves

@naveen28204280
Copy link
Author

@hrideshmg Could you review this please ?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces leave tracking functionality to support the amD Discord bot by creating a Leave table in the database and adding corresponding GraphQL mutation and query operations. The changes enable tracking member leaves with approval workflows and querying leave counts within date ranges.

Changes:

  • Created a Leave database table with foreign key references to Member via discord_id, including constraints for leave approval validation
  • Added mark_leave mutation to record new leave entries with discord_id, reason, duration, and optional approver
  • Added leave_count query method to Member type for calculating total leave duration within a date range
  • Extended the member query to accept discord_id as an optional parameter alongside existing member_id and email options

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 14 comments.

File Description
migrations/20260214152404_create_leave_table.sql Creates Leave table schema with foreign keys, defaults, and constraints including self-approval prevention
src/models/attendance.rs Defines MarkLeaveInput, MarkLeaveOutput, and LeaveCountOutput structs for GraphQL API
src/graphql/mutations/attendance_mutations.rs Implements mark_leave mutation to insert leave records with current timestamp
src/graphql/queries/member_queries.rs Adds discord_id parameter to member query and implements leave_count resolver on Member type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 415 to 433
let leave = sqlx::query_as::<_, LeaveCountOutput>(
r#"
SELECT discord_id, SUM(duration) AS count
FROM "Leave"
WHERE date > $1
AND (date + duration) < $2
AND discord_id = $3
GROUP BY discord_id
"#,
)
.bind(start_date)
.bind(end_date)
.bind(
self.discord_id
.as_ref()
.expect("Leave count needs discord_id"),
)
.fetch_one(pool.as_ref())
.await?;
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The leave_count query will fail when a member has no leaves in the specified date range. The fetch_one method expects exactly one row, but when there are no matching leaves, the GROUP BY query returns zero rows, causing a database error. Consider using fetch_optional and returning a default count of 0 when no leaves are found, or modifying the query to always return a result using COALESCE.

Copilot uses AI. Check for mistakes.
Copy link
Member

@hrideshmg hrideshmg Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this method is moved into a leave object, this can be refactored to return a simple integer rather than returning both discord_id and count. The former is available in the parent member object.

See: #170 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this method is moved into a leave object, this can be refactored to return a simple integer rather than returning both discord_id and count. The former is available in the parent member object.

See: #170 (comment)

Wouldn't that be more difficult when you're running an allMembers query ?
This way we can directly compare with discord_id

Copy link
Member

@hrideshmg hrideshmg Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way we can directly compare with discord_id

You can still do that, discord_id in this current implementation is redundant as its one the same level as your leave_count query.

The refactor was suggested because we need to add another records query as well, see the linked comment.

Comment on lines 404 to 409
async fn leave_count(
&self,
ctx: &Context<'_>,
start_date: NaiveDate,
end_date: NaiveDate,
) -> Result<LeaveCountOutput> {
Copy link
Member

@hrideshmg hrideshmg Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave should be a nested object with two methods under it that return leave_count and records respectively as we need to be able to query on which days the member took a leave.

See the records and updateCount methods under StatusInfo for reference.

@amfoss amfoss deleted a comment from Copilot AI Feb 22, 2026
@amfoss amfoss deleted a comment from Copilot AI Feb 22, 2026
@amfoss amfoss deleted a comment from Copilot AI Feb 22, 2026
@amfoss amfoss deleted a comment from Copilot AI Feb 22, 2026
@amfoss amfoss deleted a comment from Copilot AI Feb 22, 2026
@amfoss amfoss deleted a comment from Copilot AI Feb 22, 2026
@amfoss amfoss deleted a comment from Copilot AI Feb 22, 2026
@amfoss amfoss deleted a comment from Copilot AI Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants