refactor(attendance): extract check-in/check-out logic into service layer#361
Open
LoopyB wants to merge 1 commit into
Open
refactor(attendance): extract check-in/check-out logic into service layer#361LoopyB wants to merge 1 commit into
LoopyB wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the attendance check-in/check-out workflow by extracting attendance business logic from
shiftattendance.controller.jsinto a dedicated service layer.The goal is to improve backend maintainability, testability, and future readiness for payroll, reporting, guard reliability metrics, and AI-assisted guard recommendation logic.
Changes
src/services/attendance.service.jsshiftattendance.controller.jsso it now acts as a thin request/response layerShift.locationacceptedByfield rather than the virtualassignedGuardaliasArchitectural impact
This supports the backend service-layer pattern by separating HTTP controller concerns from attendance domain logic.
Before this refactor, the attendance controller was responsible for request handling, coordinate validation, shift lookup, guard assignment validation, duplicate check-in prevention, location/radius checks, attendance persistence, and attendance history retrieval.
After this refactor, the controller delegates business logic to the attendance service and remains focused on:
This makes the attendance workflow easier to test, maintain, and extend.
Future readiness
This refactor creates a cleaner foundation for future backend features, including:
Testing
Passed
Ran ESLint successfully on:
src/services/attendance.service.jssrc/controllers/shiftattendance.controller.jstests/attendance.controller.test.jstests/services/attendance.service.test.jsAdded and ran focused service-level Jest tests:
npm test -- tests/services/attendance.service.test.jsResult:
Full test suite note
I also ran:
npm testThe full backend test suite currently fails due to existing repo-wide test issues unrelated to this attendance service refactor.
Observed existing issues include:
The new attendance service unit tests pass independently, and ESLint passes on all files touched by this PR.
Attendance controller test note
I also attempted the attendance controller test using Node VM modules:
This progressed past the Jest/ESM import.meta.url issue, but the test then failed because process.env.MONGO_URI was not configured for a test database environment.
Because this PR is scoped to the attendance service-layer refactor, it adds and verifies focused service-level unit coverage rather than attempting to fix the wider Jest/Mongo integration test setup.