-
Notifications
You must be signed in to change notification settings - Fork 2
fix: Prevent synables from having an updated at less than the created_at #98
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
base: main
Are you sure you want to change the base?
Conversation
Code Review Summary✨ This pull request introduces group functionality to transactions, enhances the handling of recurring transactions, and updates OpenAPI documentation. Key areas of change include the 🚀 Key Improvements
💡 Minor Suggestions
🚨 Critical Issues
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review complete. See the overview comment for a summary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use groupables
instead of modifying that table. The idea is that the number of things that can be grouped can change.
🔍 Code Review💡 1. **app/Http/Controllers/API/v1/TransactionController.php** (Lines 272-274) - CLARITYWhen syncing a single group, it's clearer to explicitly pass an array to Suggested Code:
Current Code: if (isset($data['group_id'])) {{"\n"}} $transaction->groups()->sync($data['group_id']);{{"\n"}} } 💡 2. **app/Http/Controllers/API/v1/TransactionController.php** (Lines 534-551) - REFACTORThe logic to ensure Suggested Code:
Current Code: if (isset($validatedData['updated_at'])) {{"\n"}} // Ensure the updated at is always greater than the created at{{"\n"}} $created_at = $transaction->created_at;{{"\n"}} $updated_at = Carbon::parse($validatedData['updated_at']);{{"\n"}} if ($updated_at->lt($created_at)) {{"\n"}} // Remove the value so that laravel defaults to now();{{"\n"}} unset($validatedData['updated_at']);{{"\n"}} }{{"\n"}} }{{"\n"}} 💡 3. **app/Http/Controllers/API/v1/TransactionController.php** (Lines 560-562) - CLARITYSimilar to the Suggested Code:
Current Code: if (isset($validatedData['group_id'])) {{"\n"}} $transaction->groups()->sync([$validatedData['group_id']]);{{"\n"}} } 💡 4. **app/Http/Traits/ApiQueryable.php** (Line 25) - BUGChanging from Suggested Code:
Current Code: $query = $query->where('updated_at', '>', $date)->withTrashed(); Verdict: APPROVE Posted as a comment because posting a review failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review complete. See the overview comment for a summary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review complete. See the overview comment for a summary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with updated_at and created_at does not only affect transactions. It affects all models that are syncable.
-
I would recommend creating a validation rule (validator) and using it in all the controllers validation logic.
-
It would have one message defined in one place and all you need to do is add it to the rules array.
tests/Feature/TransactionsTest.php
Outdated
]); | ||
} | ||
|
||
public function test_api_user_can_not_update_their_transactions_with_an_older_date() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function test_api_user_can_not_update_their_transactions_with_an_older_date() | |
public function test_api_user_can_not_update_their_transactions_with_an_older_date() // Is this name accurate? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you suggest a better name?
|
Is @austin047 aware? |
No description provided.