mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-23 21:24:04 +00:00
Remove app/Space folder and extract model business logic into services
Relocate all 14 files from the catch-all app/Space namespace into proper locations: data providers to Support/Formatters, installation utilities to Services/Installation, PDF utils to Services/Pdf, module/update classes to Services/Module and Services/Update, SiteApi trait to Traits, and helpers to Support. Extract ~1,400 lines of business logic from 8 fat models (Invoice, Payment, Estimate, RecurringInvoice, Company, Customer, Expense, User) into 9 new service classes with constructor injection. Controllers now depend on services instead of calling static model methods. Shared item/tax creation logic consolidated into DocumentItemService.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Http\Requests\UserRequest;
|
||||
use App\Notifications\MailResetPasswordNotification;
|
||||
use App\Traits\HasCustomFieldsTrait;
|
||||
use Carbon\Carbon;
|
||||
@@ -15,7 +14,6 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Silber\Bouncer\BouncerFacade;
|
||||
use Silber\Bouncer\Database\HasRolesAndAbilities;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@@ -349,42 +347,6 @@ class User extends Authenticatable implements HasMedia
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function createFromRequest(UserRequest $request)
|
||||
{
|
||||
$user = self::create($request->getUserPayload());
|
||||
|
||||
$user->setSettings([
|
||||
'language' => CompanySetting::getSetting('language', $request->header('company')),
|
||||
]);
|
||||
|
||||
$companies = collect($request->companies);
|
||||
$user->companies()->sync($companies->pluck('id'));
|
||||
|
||||
foreach ($companies as $company) {
|
||||
BouncerFacade::scope()->to($company['id']);
|
||||
|
||||
BouncerFacade::sync($user)->roles([$company['role']]);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function updateFromRequest(UserRequest $request)
|
||||
{
|
||||
$this->update($request->getUserPayload());
|
||||
|
||||
$companies = collect($request->companies);
|
||||
$this->companies()->sync($companies->pluck('id'));
|
||||
|
||||
foreach ($companies as $company) {
|
||||
BouncerFacade::scope()->to($company['id']);
|
||||
|
||||
BouncerFacade::sync($this)->roles([$company['role']]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function checkAccess($data)
|
||||
{
|
||||
if (! empty($data->data['super_admin_only']) && $data->data['super_admin_only']) {
|
||||
@@ -409,47 +371,4 @@ class User extends Authenticatable implements HasMedia
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function deleteUsers($ids)
|
||||
{
|
||||
foreach ($ids as $id) {
|
||||
$user = self::find($id);
|
||||
|
||||
if ($user->invoices()->exists()) {
|
||||
$user->invoices()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->estimates()->exists()) {
|
||||
$user->estimates()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->customers()->exists()) {
|
||||
$user->customers()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->recurringInvoices()->exists()) {
|
||||
$user->recurringInvoices()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->expenses()->exists()) {
|
||||
$user->expenses()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->payments()->exists()) {
|
||||
$user->payments()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->items()->exists()) {
|
||||
$user->items()->update(['creator_id' => null]);
|
||||
}
|
||||
|
||||
if ($user->settings()->exists()) {
|
||||
$user->settings()->delete();
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user