refactor: code style changes
Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Exceptions\InvalidInviteException;
|
||||
use App\Exceptions\PublicTeamInviteException;
|
||||
use App\Exceptions\UserAlreadyInvitedException;
|
||||
@@ -18,7 +16,6 @@ use Mpociot\Teamwork\TeamInvite;
|
||||
|
||||
class TeamService
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a team
|
||||
*
|
||||
@@ -26,8 +23,8 @@ class TeamService
|
||||
* @param $ownerID
|
||||
* @return Team
|
||||
*/
|
||||
public function createTeam($teamName, $ownerID): Team {
|
||||
|
||||
public function createTeam($teamName, $ownerID): Team
|
||||
{
|
||||
$team = Team::create([
|
||||
'name' => $teamName,
|
||||
'owner_id' => $ownerID,
|
||||
@@ -40,7 +37,6 @@ class TeamService
|
||||
|
||||
public function updateTeam(Team $team, $teamDescription, $joinType): bool
|
||||
{
|
||||
|
||||
$team->description = $teamDescription;
|
||||
$team->openJoin = $joinType;
|
||||
|
||||
@@ -55,7 +51,6 @@ class TeamService
|
||||
*/
|
||||
public function inviteUser(Team $team, $userID): bool
|
||||
{
|
||||
|
||||
$user = User::findOrFail($userID);
|
||||
|
||||
if (! $team->openJoin) {
|
||||
@@ -63,6 +58,7 @@ class TeamService
|
||||
Teamwork::inviteToTeam($user, $team, function (TeamInvite $invite) use ($user) {
|
||||
Mail::to($user)->send(new InviteToTeam($invite));
|
||||
});
|
||||
|
||||
return true;
|
||||
} else {
|
||||
throw new UserAlreadyInvitedException('This user has already been invited.');
|
||||
@@ -70,20 +66,20 @@ class TeamService
|
||||
} else {
|
||||
throw new PublicTeamInviteException('You can\'t invite users to public teams.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts or denies a user invite
|
||||
*
|
||||
* @param Authenticatable $user
|
||||
* @param Authenticatable $user
|
||||
* @param $action
|
||||
* @param $token
|
||||
* @return bool True on success or exception on failure
|
||||
*
|
||||
* @throws InvalidInviteException Thrown when the invite code / url is invalid
|
||||
*/
|
||||
public function processInvite(Authenticatable $user, $action, $token): bool {
|
||||
|
||||
public function processInvite(Authenticatable $user, $action, $token): bool
|
||||
{
|
||||
switch ($action) {
|
||||
case 'accept':
|
||||
|
||||
@@ -91,9 +87,7 @@ class TeamService
|
||||
|
||||
if ($invite && $invite->user->is($user)) {
|
||||
Teamwork::acceptInvite($invite);
|
||||
|
||||
} else {
|
||||
|
||||
throw new InvalidInviteException('Invalid or expired invite URL.');
|
||||
}
|
||||
|
||||
@@ -104,11 +98,8 @@ class TeamService
|
||||
$invite = Teamwork::getInviteFromDenyToken($token);
|
||||
|
||||
if ($invite && $invite->user->is($user)) {
|
||||
|
||||
Teamwork::denyInvite($invite);
|
||||
|
||||
} else {
|
||||
|
||||
throw new InvalidInviteException('Invalid or expired invite URL.');
|
||||
}
|
||||
|
||||
@@ -119,18 +110,15 @@ class TeamService
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Team $team
|
||||
* @param Team $team
|
||||
* @param $associatedVacancies
|
||||
* @return string The success message, exception/bool if error
|
||||
*/
|
||||
public function updateVacancies(Team $team, $associatedVacancies): string
|
||||
{
|
||||
|
||||
// P.S. To future developers
|
||||
// This method gave me a lot of trouble lol. It's hard to write code when you're half asleep.
|
||||
// There may be an n+1 query in the view and I don't think there's a way to avoid that without writing a lot of extra code.
|
||||
@@ -160,6 +148,7 @@ class TeamService
|
||||
} else {
|
||||
$team->vacancies()->attach($requestVacancies);
|
||||
}
|
||||
|
||||
return 'Assignments changed successfully.';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user