Skip to content

Commit

Permalink
Merge pull request #54 from thboss/develop
Browse files Browse the repository at this point in the history
add unlink discord
  • Loading branch information
B3none authored Jul 1, 2020
2 parents 30dc551 + 16a4d92 commit 8d441b7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function registerRoutes()
Route::post('/discord/update/{discordId}', DiscordController::class . '@updateName');
Route::get('/discord/check/{discordId}', DiscordController::class . '@checkDiscordLink');
Route::get('/discord/name/{discordId}', DiscordController::class . '@getName');
Route::post('/discord/delete/{discordId}', DiscordController::class . '@unlinkDiscord');

// Authorised player endpoints
Route::get('/player/discord/{discordId}', PlayerController::class . '@getPlayerByDiscordId');
Expand Down
13 changes: 13 additions & 0 deletions src/Controllers/DiscordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ public function linkDiscord(string $discordId, string $code): string
return 'Failure! Please try again and if you\'re really struggling contact B3none';
}

/**
* Unlink Discord
*
* @param string $discordId
* @return string
*/
public function unlinkDiscord(string $discordId): string
{
return response()->json(
$this->discordHelper->unlinkDiscord($discordId)
);
}

/**
* Generate discord link
*
Expand Down
24 changes: 24 additions & 0 deletions src/Helpers/DiscordHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@ public function updateName(string $discordId, string $discordName): array
];
}

/**
* Delete a player from the DB
*
* @param string $discordId
* @return array
*/
public function unlinkDiscord(string $discordId): array
{
if (!$this->isAlreadyLinked($discordId)) {
return [
'success' => false,
'error' => 'unlink_discord'
];
}

$delete = $this->db->delete('players', [
'discord' => $discordId,
]);

return [
'success' => $delete->execute()
];
}

/**
* Update the name in the DB
*
Expand Down

0 comments on commit 8d441b7

Please sign in to comment.