Skip to content

Keep one open session per member when admins add or edit logs - #157

Open
wayx112 wants to merge 1 commit into
Team6083:mainfrom
wayx112:fix/one-open-session
Open

wayx112 wants to merge 1 commit into
Team6083:mainfrom
wayx112:fix/one-open-session

Conversation

@wayx112

@wayx112 wayx112 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Clocking in takes the member's clock-in lock and refuses a second open log (#144), but the admin log form and the Admin API wrote logs directly:

  • Creating a "Currently in" log for someone already clocked in gave them two open logs. The home page then listed them twice, and Clock-out closed only one, so the button still said Clock-out.
  • Setting a finished log back to "Currently in" did the same if they were in, and kept the log's old clock-out time in the database (the disabled field isn't sent, and undefined left it unchanged).

This PR changes:

  • Same lock and check: writeOpenLog (in timelog-dto.ts) runs the lock, the "already open" check and the write in one transaction, with the same retries as clock-in. Clock-in now uses it too. It covers createTimeLog, updateTimeLog (the log being edited doesn't count against itself) and the Admin API's create and update.
  • Form: the refusal shows on the status field ("This member is already clocked in on another log. Clock that one out first.") instead of an error page.
  • API: POST /api/admin/timelogs and PUT /api/admin/timelogs/{id} answer 409 conflict; added to the OpenAPI file.
  • Clock-out time: a log saved as "Currently in" has no clock-out time.

Logs saved as Done or Locked don't take the lock, as before.

Evidence

On a local preview, as an admin:

Create Log, Currently in, for someone already in   status field error; still 1 open log
POST /api/admin/timelogs, same                     409 {"code":"conflict"}
Done log edited back to Currently in               saved; outTime is null
Test Files  25 passed (25)
     Tests  335 passed (335)

New tests: an admin create (form and API) is refused while the member is in; a finished log can reopen and loses its clock-out time, saving it again is fine, and a second one can't reopen. The existing clock-in tests pass unchanged. tsc --noEmit, ESLint on the changed files and npm run build pass.

Merge danger

Door: two-way. No schema change; uses the existing ClockInLock collection.

Blast radius: clock-in (refactored to share the helper), the admin log form, and the Admin API's time log create and update.

🤖 Generated with Claude Code

Clocking in takes the member's clock-in lock and refuses a second open log (Team6083#144), but the admin log form and the Admin API wrote logs directly. Creating a "Currently in" log for someone already in, or setting a finished log back to "Currently in", left them with two open logs: the home page listed them twice and Clock-out closed only one. A finished log set back to "Currently in" also kept its old clock-out time.

Those writes now go through the same lock and check. The form shows the refusal on the status field, and the API answers 409 conflict. An open log has no clock-out time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant