Skip to content

Commit

Permalink
feat: manage recruiting stages (#1221)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Jul 29, 2021
1 parent 6693fdf commit 571522c
Show file tree
Hide file tree
Showing 34 changed files with 2,521 additions and 6 deletions.
40 changes: 40 additions & 0 deletions app/Console/Commands/Tests/SetupDummyAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
use App\Services\Company\Employee\Contract\SetContractRenewalDate;
use App\Services\Company\Employee\Pronoun\AssignPronounToEmployee;
use App\Services\Company\Employee\ECoffee\MatchEmployeesForECoffee;
use App\Services\Company\Adminland\JobOpening\CreateRecruitingStage;
use App\Services\Company\Employee\OneOnOne\CreateOneOnOneActionItem;
use App\Services\Company\Employee\OneOnOne\ToggleOneOnOneActionItem;
use App\Services\Company\Employee\Position\AssignPositionToEmployee;
Expand All @@ -87,6 +88,7 @@
use App\Services\Company\Adminland\EmployeeStatus\CreateEmployeeStatus;
use App\Services\Company\Employee\OneOnOne\MarkOneOnOneEntryAsHappened;
use App\Services\Company\Adminland\Expense\AllowEmployeeToManageExpenses;
use App\Services\Company\Adminland\JobOpening\CreateRecruitingStageTemplate;
use App\Services\Company\Employee\WorkFromHome\UpdateWorkFromHomeInformation;
use App\Services\Company\Employee\EmployeeStatus\AssignEmployeeStatusToEmployee;

Expand Down Expand Up @@ -227,6 +229,7 @@ public function handle(): void
$this->addPreviousPositionsHistory();
$this->addBillingAndInvoices();
$this->addWikis();
$this->addRecruitingStages();
$this->addSecondaryBlankAccount();
$this->validateUserAccounts();
$this->stop();
Expand Down Expand Up @@ -2413,6 +2416,43 @@ private function addWikis(): void
}
}

private function addRecruitingStages(): void
{
$this->info('☐ Add recruiting stages');

$templates = collect([
'Engineering flow',
'Sales',
'Marketing with a lot of experience',
]);

$stages = collect([
'Screening call',
'Technical interview',
'Interview with SM, PO',
'Reference check',
'Behavorial interview',
]);

foreach ($templates as $template) {
$template = (new CreateRecruitingStageTemplate)->execute([
'company_id' => $this->company->id,
'author_id' => $this->michael->id,
'name' => $template,
]);

$randomStages = $stages->shuffle()->take(rand(3, 6));
foreach ($randomStages as $stage) {
$stage = (new CreateRecruitingStage)->execute([
'company_id' => $this->company->id,
'author_id' => $this->michael->id,
'recruiting_stage_template_id' => $template->id,
'name' => $stage,
]);
}
}
}

private function addSecondaryBlankAccount(): void
{
$this->info('☐ Create a blank account');
Expand Down
34 changes: 34 additions & 0 deletions app/Helpers/LogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,40 @@ public static function processAuditLog(AuditLog $log): string
]);
break;

case 'recruiting_stage_created':
$sentence = trans('account.log_recruiting_stage_created', [
'recruiting_stage_id' => $log->object->{'recruiting_stage_id'},
'recruiting_stage_name' => $log->object->{'recruiting_stage_name'},
]);
break;

case 'recruiting_stage_updated':
$sentence = trans('account.log_recruiting_stage_updated', [
'recruiting_stage_id' => $log->object->{'recruiting_stage_id'},
'recruiting_stage_name' => $log->object->{'recruiting_stage_name'},
]);
break;

case 'recruiting_stage_destroyed':
$sentence = trans('account.log_recruiting_stage_destroyed', [
'recruiting_stage_name' => $log->object->{'recruiting_stage_name'},
]);
break;

case 'recruiting_stage_template_created':
$sentence = trans('account.log_recruiting_stage_template_created', [
'recruiting_stage_template_id' => $log->object->{'recruiting_stage_template_id'},
'recruiting_stage_template_name' => $log->object->{'recruiting_stage_template_name'},
]);
break;

case 'recruiting_stage_template_updated':
$sentence = trans('account.log_recruiting_stage_template_updated', [
'recruiting_stage_template_id' => $log->object->{'recruiting_stage_template_id'},
'recruiting_stage_template_name' => $log->object->{'recruiting_stage_template_name'},
]);
break;

default:
$sentence = '';
break;
Expand Down
191 changes: 191 additions & 0 deletions app/Http/Controllers/Company/Adminland/AdminRecruitmentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php

namespace App\Http\Controllers\Company\Adminland;

use Inertia\Inertia;
use Inertia\Response;
use Illuminate\Http\Request;
use App\Helpers\InstanceHelper;
use Illuminate\Http\JsonResponse;
use App\Helpers\NotificationHelper;
use App\Http\Controllers\Controller;
use App\Models\Company\RecruitingStageTemplate;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Http\ViewHelpers\Adminland\AdminRecruitmentViewHelper;
use App\Services\Company\Adminland\JobOpening\CreateRecruitingStage;
use App\Services\Company\Adminland\JobOpening\UpdateRecruitingStage;
use App\Services\Company\Adminland\JobOpening\DestroyRecruitingStage;
use App\Services\Company\Adminland\JobOpening\CreateRecruitingStageTemplate;

class AdminRecruitmentController extends Controller
{
/**
* Show the recruitment page.
*
* @return Response
*/
public function index(): Response
{
$company = InstanceHelper::getLoggedCompany();

$templates = AdminRecruitmentViewHelper::index($company);

return Inertia::render('Adminland/Recruitment/Index', [
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
'templates' => $templates,
]);
}

/**
* Create the template.
*
* @param Request $request
* @param int $companyId
* @return JsonResponse
*/
public function store(Request $request, int $companyId): JsonResponse
{
$company = InstanceHelper::getLoggedCompany();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

$data = [
'company_id' => $company->id,
'author_id' => $loggedEmployee->id,
'name' => $request->input('name'),
];

$template = (new CreateRecruitingStageTemplate)->execute($data);

return response()->json([
'data' => [
'id' => $template->id,
'name' => $template->name,
'stages' => null,
'url' => route('recruitment.show', [
'company' => $company,
'template' => $template,
]),
],
], 201);
}

/**
* Show the template content.
*
* @param Request $request
* @param int $companyId
* @param int $templateId
* @return mixed
*/
public function show(Request $request, int $companyId, int $templateId)
{
$company = InstanceHelper::getLoggedCompany();

try {
$template = RecruitingStageTemplate::where('company_id', $company->id)
->findOrFail($templateId);
} catch (ModelNotFoundException $e) {
return redirect('home');
}

$template = AdminRecruitmentViewHelper::show($company, $template);

return Inertia::render('Adminland/Recruitment/Show', [
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
'template' => $template,
]);
}

/**
* Create the stage.
*
* @param Request $request
* @param int $companyId
* @param int $templateId
* @return JsonResponse
*/
public function storeStage(Request $request, int $companyId, int $templateId): JsonResponse
{
$company = InstanceHelper::getLoggedCompany();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

$data = [
'company_id' => $company->id,
'author_id' => $loggedEmployee->id,
'recruiting_stage_template_id' => $templateId,
'name' => $request->input('name'),
];

$stage = (new CreateRecruitingStage)->execute($data);

return response()->json([
'data' => [
'id' => $stage->id,
'name' => $stage->name,
'position' => $stage->position,
],
], 201);
}

/**
* Update the stage.
*
* @param Request $request
* @param int $companyId
* @param int $templateId
* @param int $stageId
* @return JsonResponse
*/
public function updateStage(Request $request, int $companyId, int $templateId, int $stageId): JsonResponse
{
$company = InstanceHelper::getLoggedCompany();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

$data = [
'company_id' => $company->id,
'author_id' => $loggedEmployee->id,
'recruiting_stage_template_id' => $templateId,
'recruiting_stage_id' => $stageId,
'name' => $request->input('name'),
'position' => $request->input('position'),
];

$stage = (new UpdateRecruitingStage)->execute($data);

return response()->json([
'data' => [
'id' => $stage->id,
'name' => $stage->name,
'position' => $stage->position,
],
], 200);
}

/**
* Delete the stage.
*
* @param Request $request
* @param int $companyId
* @param int $templateId
* @param int $stageId
* @return JsonResponse
*/
public function destroyStage(Request $request, int $companyId, int $templateId, int $stageId): JsonResponse
{
$company = InstanceHelper::getLoggedCompany();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

$data = [
'company_id' => $company->id,
'author_id' => $loggedEmployee->id,
'recruiting_stage_template_id' => $templateId,
'recruiting_stage_id' => $stageId,
];

(new DestroyRecruitingStage)->execute($data);

return response()->json([
'data' => true,
], 200);
}
}
74 changes: 74 additions & 0 deletions app/Http/ViewHelpers/Adminland/AdminRecruitmentViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Http\ViewHelpers\Adminland;

use App\Models\Company\Company;
use Illuminate\Support\Collection;
use App\Models\Company\RecruitingStageTemplate;

class AdminRecruitmentViewHelper
{
/**
* Get all the recruiting stage templates in the company.
*
* @param Company $company
* @return Collection
*/
public static function index(Company $company): ?Collection
{
$templates = $company->recruitingStageTemplates()
->with('stages')
->orderBy('name')
->get();

$templatesCollection = collect();
foreach ($templates as $template) {
$stages = $template->stages;
$stagesCollection = collect();
foreach ($stages as $stage) {
$stagesCollection->push([
'id' => $stage->id,
'name' => $stage->name,
'position' => $stage->position,
]);
}

$templatesCollection->push([
'id' => $template->id,
'name' => $template->name,
'stages' => $stagesCollection,
'url' => route('recruitment.show', [
'company' => $company,
'template' => $template,
]),
]);
}

return $templatesCollection;
}

/**
* Get the information about the given template.
*
* @param Company $company
* @return array
*/
public static function show(Company $company, RecruitingStageTemplate $template): ?array
{
$stages = $template->stages;
$stagesCollection = collect();
foreach ($stages as $stage) {
$stagesCollection->push([
'id' => $stage->id,
'name' => $stage->name,
'position' => $stage->position,
]);
}

return [
'id' => $template->id,
'name' => $template->name,
'stages' => $stagesCollection,
];
}
}
10 changes: 10 additions & 0 deletions app/Models/Company/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ public function wikis()
return $this->hasMany(Wiki::class);
}

/**
* Get all recruiting stage templates in the company.
*
* @return HasMany
*/
public function recruitingStageTemplates()
{
return $this->hasMany(RecruitingStageTemplate::class);
}

/**
* Get the logo associated with the company.
*
Expand Down
Loading

0 comments on commit 571522c

Please sign in to comment.