Repository navigation
feat(api): create routines - #74
Merged
Merged
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.
What changed
POST /routinesfor authenticated users.How it works
Routine creation spans three related tables:
routines,routine_exercises, androutine_schedules. The service uses one database transaction so these writes behave as a single operation. If validation or any insert fails, PostgreSQL rolls everything back instead of leaving a partially created routine.Before inserting anything, the service deduplicates the requested exercise IDs and queries only exercises available to the current user. Built-in exercises have no owner, while custom exercises must belong to that user.
Because exercise IDs are unique and the requested IDs were deduplicated, matching the number returned by the query to the number requested proves that every requested exercise was found and accessible.
The transaction callback is named
currentTransactionto distinguish the active transaction object from thedatabase.transaction(...)method that creates it.Validation
pnpm lintpnpm typecheckpnpm test— 97 tests passedThe repository-wide format check still reports an existing Windows line-ending issue across unrelated files; this PR does not reformat those files.