1 | <?php |
||
2 | |||
3 | namespace App\Utils\Candidates; |
||
4 | |||
5 | use App\Events\CandidateMoved; |
||
6 | use App\Events\CandidateRated; |
||
7 | use App\Models\Candidate; |
||
8 | use App\Utils\StageHelper; |
||
9 | use Illuminate\Support\Facades\Auth; |
||
10 | |||
11 | class CandidateUpdater |
||
12 | { |
||
13 | public static function updateCandidate($candidateId, $request) |
||
14 | { |
||
15 | $candidate = Candidate::findOrFail($candidateId); |
||
16 | |||
17 | if (isset($request->recruitment_id)) { |
||
18 | return self::moveCandidate($candidate, $request->recruitment_id); |
||
19 | } |
||
20 | |||
21 | if (isset($request->rate)) { |
||
22 | event(new CandidateRated($candidate, $candidate->rate, $request->rate, Auth::user()->id)); |
||
23 | $candidate->rate = $request->rate; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
24 | $candidate->save(); |
||
25 | } |
||
26 | |||
27 | return $candidate; |
||
28 | } |
||
29 | |||
30 | public static function moveCandidate($candidate, $recruitmentId) |
||
31 | { |
||
32 | $prevRecruitmentId = $candidate->recruitment_id; |
||
33 | $candidate->recruitment_id = $recruitmentId; |
||
34 | $candidate->stage_id = StageHelper::getFirstStage($recruitmentId)->id; |
||
35 | $candidate->save(); |
||
36 | |||
37 | event(new CandidateMoved($candidate, $prevRecruitmentId, $recruitmentId, Auth::user()->id)); |
||
38 | |||
39 | return $candidate; |
||
40 | } |
||
41 | } |
||
42 |