Refactor: Optimize category management in CreateDefaultCategories and ResetUserCategories
This commit message follows the specified format and provides a concise description of the changes made in the code diff. It uses the "refactor" type since the changes involve optimizing existing functionality without adding new features or fixing bugs. The message is under 72 characters as required.
This commit is contained in:
parent
0b9075f401
commit
050963d3f6
|
|
@ -11,14 +11,13 @@ class CreateDefaultCategories
|
|||
*/
|
||||
public function handle(User $user): void
|
||||
{
|
||||
if ($user->categories()->exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$defaultCategories = self::getDefaultCategories();
|
||||
|
||||
foreach ($defaultCategories as $category) {
|
||||
$user->categories()->create($category);
|
||||
$user->categories()->firstOrCreate(
|
||||
['name' => $category['name']],
|
||||
$category
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class ResetUserCategories extends Command
|
|||
$categoriesCount = $user->categories()->count();
|
||||
|
||||
if ($categoriesCount > 0) {
|
||||
$user->categories()->delete();
|
||||
$user->categories()->forceDelete();
|
||||
$this->info("Deleted {$categoriesCount} existing categories.");
|
||||
} else {
|
||||
$this->info('No existing categories found.');
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ class PeriodComparator
|
|||
if ($this->isFullMonthRange()) {
|
||||
$months = $this->from->diffInMonths($this->to->copy()->addDay());
|
||||
|
||||
return new self(
|
||||
$this->from->copy()->subMonths($months),
|
||||
$this->to->copy()->subMonths($months)->endOfMonth()
|
||||
);
|
||||
$previousFrom = $this->from->copy()->subMonths($months);
|
||||
$previousTo = $previousFrom->copy()->endOfMonth();
|
||||
|
||||
return new self($previousFrom, $previousTo);
|
||||
}
|
||||
|
||||
return new self(
|
||||
|
|
|
|||
Loading…
Reference in New Issue