Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update isUnusedAttendanceCode to allow any non-conflicting Event #426

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

yimmyj
Copy link
Contributor

@yimmyj yimmyj commented Apr 4, 2024

No description provided.

Copy link

github-actions bot commented Apr 4, 2024

Thanks for contributing!
If you've made changes to the API's functionality, please make sure to bump the package
version—see this guide to semantic versioning for details—and
document those changes as appropriate.

Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Copy link
Member

@nik-dange nik-dange left a comment

Choose a reason for hiding this comment

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

make sure to change the package version + migration number once again, since we merged in Eric's PR before yours

Copy link
Member

@nik-dange nik-dange left a comment

Choose a reason for hiding this comment

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

Quick thing, did you test checking in to an event when there are multiple events with the same checkin code? I recall that the checkin route uses find by checkin code, double check this functionality

services/AttendanceService.ts Outdated Show resolved Hide resolved
Copy link
Member

@nik-dange nik-dange left a comment

Choose a reason for hiding this comment

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

Couple small nits. I think we'll need to stress test this with a few different situations to make sure it works as intended just to make sure there's no strange edge cases. Can you validate this w/ Postman testing?

repositories/EventRepository.ts Outdated Show resolved Hide resolved
repositories/EventRepository.ts Outdated Show resolved Hide resolved
tests/event.test.ts Outdated Show resolved Hide resolved
tests/event.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@nik-dange nik-dange left a comment

Choose a reason for hiding this comment

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

Left two questions


// If there are eligible events, return the first one
if (validEvents.length > 0) {
return validEvents[0];
Copy link
Member

Choose a reason for hiding this comment

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

What defines the first event? Is it sorted by start time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory there should never be more than one eligible event; that would mean that there are two events occurring at the same time sharing an attendance code which wouldn't make any sense. This is handled by isAvailableAttendanceCode and tested in the attached postman screenshots.

However, since the check-in period is defined as 30 minutes before and after an event, two events happening one after another with the same attendance code could cause an issue.

The solution to this could be to simply disallow this case, which involves changing isAvailableAttendanceCode to check for conflicting events in this "check-in period" rather than the duration of the event itself. Let me know your thoughts on this change!

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the "check-in period" approach. However, realistically, we can allow more padding room cases like this, such as not allowing events with the same checkin code 3 days before and after the event. This would avoid the edge case of having a time precisely in the "check-in period"s of two close events with the same checkin code.

Comment on lines +46 to +62
// Otherwise, find the closest event to the current time
const currentTime = new Date();
let closestEvent = null;
let closestTimeDifference = Infinity;

matchingEvents.forEach((event) => {
const eventStartTime = new Date(event.start);
const timeDifference = Math.abs(eventStartTime.getTime() - currentTime.getTime());

// Update closest event if necessary
if (timeDifference < closestTimeDifference) {
closestEvent = event;
closestTimeDifference = timeDifference;
}
});

return closestEvent;
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, what's the edge case that warrants this code? Shouldn't all potentially valid events be caught in the above code? I know we're validating it one more time in the AttendanceService, just curious what the reasoning for adding it was

Copy link
Member

Choose a reason for hiding this comment

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

And side note, if there is a use case that warrants this code, does it make more sense to use validEvents instead of matchingEvents?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use case is the small pop-up that announces whether an event "hasn't occurred yet / has already occurred / doesn't exist" when the user enters an attendance code that isn't matched to an event currently going on, in AttendanceService's validateEventToAttend method.

The way it used to work when attendance codes were unique is that the validate method would simply check if the one event with the matching attendance code hasn't started, has already ended, or doesn't exist in the schema.

However with repeated attendance codes, it is possible for events sharing the same code to be simultaneously "too early" AND "too late," so I chose to return the closest event to the current date as a "guess" as to what the user meant to check in to when they entered a code. For example, if code "ABC" was used both for an event a year ago and two days in the future, I'm assuming that the user meant to check in to the one two days in the future, and will show the "hasn't occurred yet" message. Let me know if this implementation needs more consideration.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we shouldn't have the "hasn't occurred yet" message at all as it give away the checkin code for a future event, nullifying the secrecy of the checkin code.

Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

Just my 2 cents


// If there are eligible events, return the first one
if (validEvents.length > 0) {
return validEvents[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the "check-in period" approach. However, realistically, we can allow more padding room cases like this, such as not allowing events with the same checkin code 3 days before and after the event. This would avoid the edge case of having a time precisely in the "check-in period"s of two close events with the same checkin code.

Comment on lines +46 to +62
// Otherwise, find the closest event to the current time
const currentTime = new Date();
let closestEvent = null;
let closestTimeDifference = Infinity;

matchingEvents.forEach((event) => {
const eventStartTime = new Date(event.start);
const timeDifference = Math.abs(eventStartTime.getTime() - currentTime.getTime());

// Update closest event if necessary
if (timeDifference < closestTimeDifference) {
closestEvent = event;
closestTimeDifference = timeDifference;
}
});

return closestEvent;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we shouldn't have the "hasn't occurred yet" message at all as it give away the checkin code for a future event, nullifying the secrecy of the checkin code.

@sumeet-bansal sumeet-bansal removed their request for review September 13, 2024 01:13
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.

4 participants