refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
64
app/Services/Contact/Occupation/CreateOccupation.php
Normal file
64
app/Services/Contact/Occupation/CreateOccupation.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Contact\Occupation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Models\Contact\Occupation;
|
||||
|
||||
class CreateOccupation extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'contact_id' => 'required|integer|exists:contacts,id',
|
||||
'company_id' => 'required|integer|exists:companies,id',
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string|max:1000',
|
||||
'salary' => 'nullable|integer',
|
||||
'salary_unit' => [
|
||||
'nullable',
|
||||
Rule::in(Occupation::$salaryUnits),
|
||||
],
|
||||
'currently_works_here' => 'nullable|boolean',
|
||||
'start_date' => 'nullable|date_format:Y-m-d',
|
||||
'end_date' => 'nullable|date_format:Y-m-d',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a occupation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return Occupation
|
||||
*/
|
||||
public function execute(array $data): Occupation
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
$contact = Contact::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['contact_id']);
|
||||
|
||||
$contact->throwInactive();
|
||||
|
||||
return Occupation::create([
|
||||
'account_id' => $data['account_id'],
|
||||
'contact_id' => $data['contact_id'],
|
||||
'company_id' => $data['company_id'],
|
||||
'title' => $data['title'],
|
||||
'description' => $this->nullOrValue($data, 'description'),
|
||||
'salary' => $this->nullOrValue($data, 'salary'),
|
||||
'salary_unit' => $this->nullOrValue($data, 'salary_unit'),
|
||||
'currently_works_here' => $this->nullOrValue($data, 'currently_works_here'),
|
||||
'start_date' => $this->nullOrDate($data, 'start_date'),
|
||||
'end_date' => $this->nullOrDate($data, 'end_date'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
40
app/Services/Contact/Occupation/DestroyOccupation.php
Normal file
40
app/Services/Contact/Occupation/DestroyOccupation.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Contact\Occupation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use App\Models\Contact\Occupation;
|
||||
|
||||
class DestroyOccupation extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'occupation_id' => 'required|integer|exists:occupations,id',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an occupation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(array $data): bool
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
$occupation = Occupation::where('account_id', $data['account_id'])
|
||||
->findOrFail($data['occupation_id']);
|
||||
|
||||
$occupation->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
66
app/Services/Contact/Occupation/UpdateOccupation.php
Normal file
66
app/Services/Contact/Occupation/UpdateOccupation.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Contact\Occupation;
|
||||
|
||||
use App\Services\BaseService;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Models\Contact\Occupation;
|
||||
|
||||
class UpdateOccupation extends BaseService
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the service.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|integer|exists:accounts,id',
|
||||
'contact_id' => 'required|integer|exists:contacts,id',
|
||||
'company_id' => 'required|integer|exists:companies,id',
|
||||
'occupation_id' => 'required|integer|exists:occupations,id',
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string|max:1000',
|
||||
'salary' => 'nullable|integer',
|
||||
'salary_unit' => [
|
||||
'nullable',
|
||||
Rule::in(Occupation::$salaryUnits),
|
||||
],
|
||||
'currently_works_here' => 'nullable|boolean',
|
||||
'start_date' => 'nullable|date_format:Y-m-d',
|
||||
'end_date' => 'nullable|date_format:Y-m-d',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a occupation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return Occupation
|
||||
*/
|
||||
public function execute(array $data): Occupation
|
||||
{
|
||||
$this->validate($data);
|
||||
|
||||
/** @var Occupation */
|
||||
$occupation = Occupation::where('account_id', $data['account_id'])
|
||||
->where('contact_id', $data['contact_id'])
|
||||
->where('company_id', $data['company_id'])
|
||||
->findOrFail($data['occupation_id']);
|
||||
|
||||
$occupation->contact->throwInactive();
|
||||
|
||||
$occupation->update([
|
||||
'title' => $data['title'],
|
||||
'description' => $this->nullOrValue($data, 'description'),
|
||||
'salary' => $this->nullOrValue($data, 'salary'),
|
||||
'salary_unit' => $this->nullOrValue($data, 'salary_unit'),
|
||||
'currently_works_here' => $this->nullOrValue($data, 'currently_works_here'),
|
||||
'start_date' => $this->nullOrDate($data, 'start_date'),
|
||||
'end_date' => $this->nullOrDate($data, 'end_date'),
|
||||
]);
|
||||
|
||||
return $occupation;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user