feat: support for myself party type#185
Conversation
Code Review SummaryThis PR introduces support for 'myself' party types, allowing transactions involving the user themselves to be automatically converted into transfers if configured. This involves changes to the Transaction controller, Party model, and User model configuration. 🚀 Key Improvements
💡 Minor Suggestions
|
| private RecurringTransactionService $recurringTransactionService | ||
| private RecurringTransactionService $recurringTransactionService, | ||
| private TransferService $transferService | ||
| ) { |
There was a problem hiding this comment.
Retrieving the Party model directly in the controller and performing business logic here violates the Single Responsibility Principle. This logic should be encapsulated within the TransactionService or a specific HandleMyselfPartyAction. Additionally, using \App\Models\Party::find ignores the user scope; it should be scoped to the authenticated user for security.
| ) { | |
| $partyId = $data['party_id'] ?? null; | |
| if (config('app.convert_myself_to_transfer') && $partyId) { | |
| $party = $user->parties()->find($partyId); | |
| if ($party?->is_myself && $request->has('from_wallet_id')) { | |
| $transfer = $this->transferService->transfer( | |
| amountToSend: (float) $data['amount'], | |
| fromWallet: $user->wallets()->findOrFail($request['from_wallet_id']), | |
| amountToReceive: (float) $data['amount'], | |
| toWallet: $user->wallets()->findOrFail($data['wallet_id']), | |
| user: $user, | |
| exchangeRate: 1.0, | |
| datetime: $data['datetime'] ?? null, | |
| transactionClientIds: ['income_transaction_client_id' => $data['client_id'] ?? null] | |
| ); | |
| return $this->success($transfer, statusCode: 201); | |
| } | |
| } |
nfebe
left a comment
There was a problem hiding this comment.
Thank for this! I took a quick look and have one comment for now :)
|
|
||
| } | ||
|
|
||
| private function isMyselfTransfer($data, $user, $request): bool |
There was a problem hiding this comment.
The method signature in the implementation includes $request, but the call site on line 263 only passes two arguments. This will cause a TypeError if line 862 is reached.
| private function isMyselfTransfer($data, $user, $request): bool | |
| private function isMyselfTransfer($data, $user): bool |
kofimokome
left a comment
There was a problem hiding this comment.
Your tests are failing
There was a problem hiding this comment.
-
We use whilesmart/eloquent-model-configs read the docs on and understand how to better set the configs
-
Inline I recommend the names of configs to set.
is-myselfset on party andcreate-transfers-for-myself-transactions. Its a boolean and is true by default. Which means if a user doesn't turn this off setting applies. -
Many of the changes in phpunit, testcase.php, seem unrelated.
-
composer lock should not change
| 'files.*' => 'file|mimes:jpg,jpeg,png,pdf|max:1240', | ||
|
|
||
| 'from_wallet_id' => 'required_if:convert_myself_to_transfer,true|integer|exists:wallets,id', | ||
| ]); |
There was a problem hiding this comment.
| ]); |
Create a request instead and there should likely be a dedicated commit for that
There was a problem hiding this comment.
sorry, I didn't quite understand this
There was a problem hiding this comment.
check the Laravel documentation here => https://laravel.com/docs/13.x/validation#form-request-validation
There was a problem hiding this comment.
You haven't updated the codes to use Laravel Requests
| ]); | ||
| } | ||
|
|
||
| private function isMyselfTransfer($data, $user, $request): bool |
There was a problem hiding this comment.
Type hinting the parameters improves code clarity and helps static analysis tools catch errors.
| private function isMyselfTransfer($data, $user, $request): bool | |
| private function isMyselfTransfer(array $data, \App\Models\User $user, Request $request): bool |
| private RecurringTransactionService $recurringTransactionService, | ||
| private TransferService $transferService | ||
| ) { | ||
| } |
added support for party type myself.... Transactions "From" myself (Income) are handled as transfers if configured so. Target issue: #169