first
This commit is contained in:
46
app/Services/Admin/Management/AdminPostCloseNoteService.php
Normal file
46
app/Services/Admin/Management/AdminPostCloseNoteService.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Admin\Management;
|
||||
|
||||
use App\Models\Election;
|
||||
use App\Models\SystemNote;
|
||||
use App\Models\User;
|
||||
use App\Services\RegistrationPeriodService;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class AdminPostCloseNoteService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly RegistrationPeriodService $registrationPeriodService,
|
||||
) {}
|
||||
|
||||
public function requireIfClosed(Election $election, ?string $note): void
|
||||
{
|
||||
if ($this->registrationPeriodService->isOpen($election)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (blank($note)) {
|
||||
throw ValidationException::withMessages([
|
||||
'note' => 'Catatan wajib diisi untuk perubahan selepas tempoh pendaftaran ditutup.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function recordIfClosed(Election $election, Model $noteable, User $actor, ?string $note, string $type): ?SystemNote
|
||||
{
|
||||
if ($this->registrationPeriodService->isOpen($election) || blank($note)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return SystemNote::query()->create([
|
||||
'election_id' => $election->id,
|
||||
'noteable_type' => $noteable::class,
|
||||
'noteable_id' => $noteable->getKey(),
|
||||
'note_type' => $type,
|
||||
'note' => $note,
|
||||
'created_by_user_id' => $actor->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user