Revert "Revert "merge 1""

This reverts commit 0c463d1f10.
This commit is contained in:
2022-10-24 01:04:22 +01:00
parent 0c463d1f10
commit b89d71b371
166 changed files with 4250 additions and 1833 deletions

View File

@@ -3,7 +3,11 @@
namespace App\Services;
use App\Exceptions\DiscordAccountRequiredException;
use App\Exceptions\IncompatibleAgeException;
use App\Exceptions\InvalidAgeException;
use App\Notifications\ApplicationConfirmed;
use Carbon\Carbon;
use ContextAwareValidator;
use App\Application;
use App\Events\ApplicationDeniedEvent;
@@ -22,12 +26,27 @@ use Illuminate\Support\Facades\Log;
class ApplicationService
{
/**
* @throws DiscordAccountRequiredException
* @throws IncompatibleAgeException
* @throws InvalidAgeException
*/
public function renderForm($vacancySlug)
{
$vacancyWithForm = Vacancy::with('forms')->where('vacancySlug', $vacancySlug)->get();
$firstVacancy = $vacancyWithForm->first();
if (is_null(Auth::user()->dob)) {
throw new InvalidAgeException("User must have added their age to apply for this vacancy.");
} elseif(Carbon::parse(Auth::user()->dob)->age < $firstVacancy->requiredAge) {
throw new IncompatibleAgeException("Sorry, you must be {$firstVacancy->requiredAge} or older to apply to {$firstVacancy->vacancyName}.");
}
if ($firstVacancy->requiresDiscord && !Auth::user()->hasDiscordConnection()) {
throw new DiscordAccountRequiredException('A discord account is required beyond this point.');
}
if (!$vacancyWithForm->isEmpty() && $firstVacancy->vacancyCount !== 0 && $firstVacancy->vacancyStatus == 'OPEN') {
return view('dashboard.application-rendering.apply')
->with([
@@ -36,7 +55,7 @@ class ApplicationService
]);
} else {
throw new ApplicationNotFoundException('The application you\'re looking for could not be found or it is currently unavailable.', 404);
throw new ApplicationNotFoundException(__('The application you\'re looking for could not be found or it is currently unavailable.'), 404);
}
}
@@ -94,11 +113,12 @@ class ApplicationService
'applicant' => $applicant->name
]);
foreach (User::all() as $user) {
if ($user->hasRole('admin')) {
$user->notify((new NewApplicant($application, $vacancy->first())));
}
}
User::whereHas('roles', function ($q) {
$q->where('name', 'admin');
})->get()->each(function ($user, $key) use ($application, $vacancy) {
$user->notify((new NewApplicant($application, $vacancy->first())));
});
$application->user->notify(new ApplicationConfirmed($application));
return true;