-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to delete a work log (#1074)
- Loading branch information
Showing
14 changed files
with
365 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace App\Services\Company\Employee\Worklog; | ||
|
||
use Carbon\Carbon; | ||
use App\Jobs\LogAccountAudit; | ||
use App\Services\BaseService; | ||
use App\Jobs\LogEmployeeAudit; | ||
use App\Models\Company\Worklog; | ||
|
||
class DestroyWorklog extends BaseService | ||
{ | ||
/** | ||
* Get the validation rules that apply to the service. | ||
* | ||
* @return array | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'company_id' => 'required|integer|exists:companies,id', | ||
'author_id' => 'required|integer|exists:employees,id', | ||
'employee_id' => 'required|integer|exists:employees,id', | ||
'worklog_id' => 'required|integer|exists:worklogs,id', | ||
]; | ||
} | ||
|
||
/** | ||
* Destroy a work log. | ||
* | ||
* @param array $data | ||
* @return bool | ||
*/ | ||
public function execute(array $data): bool | ||
{ | ||
$this->validateRules($data); | ||
|
||
$this->author($data['author_id']) | ||
->inCompany($data['company_id']) | ||
->asAtLeastHR() | ||
->canBypassPermissionLevelIfEmployeeOrManager($data['author_id'], $data['employee_id']) | ||
->canExecuteService(); | ||
|
||
$this->validateEmployeeBelongsToCompany($data); | ||
|
||
$worklog = Worklog::where('employee_id', $data['employee_id']) | ||
->findOrFail($data['worklog_id']); | ||
|
||
$worklog->delete(); | ||
|
||
LogAccountAudit::dispatch([ | ||
'company_id' => $data['company_id'], | ||
'action' => 'worklog_destroyed', | ||
'author_id' => $this->author->id, | ||
'author_name' => $this->author->name, | ||
'audited_at' => Carbon::now(), | ||
'objects' => json_encode([ | ||
'date' => $worklog->created_at->format('Y-m-d'), | ||
]), | ||
])->onQueue('low'); | ||
|
||
LogEmployeeAudit::dispatch([ | ||
'employee_id' => $data['employee_id'], | ||
'action' => 'worklog_destroyed', | ||
'author_id' => $this->author->id, | ||
'author_name' => $this->author->name, | ||
'audited_at' => Carbon::now(), | ||
'objects' => json_encode([ | ||
'date' => $worklog->created_at->format('Y-m-d'), | ||
]), | ||
])->onQueue('low'); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.