fixing database connections
This commit is contained in:
+11
-11
@@ -3,7 +3,7 @@
|
||||
namespace Lucent\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Lucent\Database\Database;
|
||||
use Lucent\Primitive\Collection;
|
||||
use PhpOption\Option;
|
||||
|
||||
@@ -12,7 +12,7 @@ class UserRepo
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return DB::table("users")->count();
|
||||
return Database::make()->table("users")->count();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,7 +20,7 @@ class UserRepo
|
||||
*/
|
||||
public function all(): Collection
|
||||
{
|
||||
$usersData = DB::table("users")->get();
|
||||
$usersData = Database::make()->table("users")->get();
|
||||
|
||||
$users = array_map(fn($userData) => $this->fromArray((array)$userData), $usersData->toArray());
|
||||
return new Collection($users);
|
||||
@@ -31,14 +31,14 @@ class UserRepo
|
||||
{
|
||||
$userData = toArray($user);
|
||||
$userData["roles"] = json_encode($userData["roles"]);
|
||||
DB::table("users")->insert($userData);
|
||||
Database::make()->table("users")->insert($userData);
|
||||
}
|
||||
|
||||
public function update(User $user): void
|
||||
{
|
||||
$userData = toArray($user);
|
||||
$userData["roles"] = json_encode($userData["roles"]);
|
||||
DB::table("users")->where("id", $user->id)->update($userData);
|
||||
Database::make()->table("users")->where("id", $user->id)->update($userData);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class UserRepo
|
||||
{
|
||||
$newToken = Token::new(32);
|
||||
|
||||
DB::table("users")
|
||||
Database::make()->table("users")
|
||||
->where("id", $id)
|
||||
->update([
|
||||
'loggedInAt' => Carbon::now()->toJson(),
|
||||
@@ -62,7 +62,7 @@ class UserRepo
|
||||
*/
|
||||
public function findByEmail(Email $email): Option
|
||||
{
|
||||
$user = DB::table("users")->where("email", $email->value())->first();
|
||||
$user = Database::make()->table("users")->where("email", $email->value())->first();
|
||||
|
||||
if (empty($user)) {
|
||||
return none();
|
||||
@@ -76,7 +76,7 @@ class UserRepo
|
||||
*/
|
||||
public function findById(string $id): Option
|
||||
{
|
||||
$user = DB::table("users")->where("id", $id)->first();
|
||||
$user = Database::make()->table("users")->where("id", $id)->first();
|
||||
|
||||
if (empty($user)) {
|
||||
return none();
|
||||
@@ -88,12 +88,12 @@ class UserRepo
|
||||
|
||||
public function updateName(string $userId, Name $name): void
|
||||
{
|
||||
DB::table("users")->where("id", $userId)->update(["name" => $name->value]);
|
||||
Database::make()->table("users")->where("id", $userId)->update(["name" => $name->value]);
|
||||
}
|
||||
|
||||
public function updateEmail(string $userId, Email $email): void
|
||||
{
|
||||
DB::table("users")->where("id", $userId)->update(["email" => $email->value()]);
|
||||
Database::make()->table("users")->where("id", $userId)->update(["email" => $email->value()]);
|
||||
}
|
||||
|
||||
public function fromArray(array $data): User
|
||||
@@ -102,7 +102,7 @@ class UserRepo
|
||||
id: $data["id"],
|
||||
name: new Name($data["name"] ?? ""),
|
||||
email: new Email($data["email"]),
|
||||
roles: json_decode($data["roles"] ?? "[]",true),
|
||||
roles: json_decode($data["roles"] ?? "[]", true),
|
||||
createdAt: $data["createdAt"],
|
||||
updatedAt: $data["updatedAt"],
|
||||
loggedInAt: $data["loggedInAt"] ?? null,
|
||||
|
||||
Reference in New Issue
Block a user