mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 22:12:10 +00:00
fix: refactored the codebase
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@@ -14,6 +15,7 @@ use Illuminate\Support\Carbon;
|
||||
* @property string $name
|
||||
* @property bool $is_moderator
|
||||
* @property Carbon|null $last_seen_at
|
||||
* @property Carbon|null $inactive_at
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Room $room
|
||||
@@ -26,6 +28,7 @@ class Player extends Model
|
||||
'name',
|
||||
'is_moderator',
|
||||
'last_seen_at',
|
||||
'inactive_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -33,6 +36,7 @@ class Player extends Model
|
||||
return [
|
||||
'is_moderator' => 'boolean',
|
||||
'last_seen_at' => 'datetime',
|
||||
'inactive_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -79,4 +83,14 @@ class Player extends Model
|
||||
'last_seen_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Player> $query
|
||||
* @return Builder<Player>
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->whereNull('inactive_at');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
@@ -81,6 +82,12 @@ class Room extends Model
|
||||
|
||||
}
|
||||
|
||||
/** @return HasMany<Player, $this> */
|
||||
public function activePlayers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Player::class)->whereNull('inactive_at');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<User, $this> */
|
||||
public function owner(): BelongsTo
|
||||
{
|
||||
@@ -97,4 +104,10 @@ class Room extends Model
|
||||
{
|
||||
return $this->closed_at !== null;
|
||||
}
|
||||
|
||||
/** @return BelongsToMany<User, $this> */
|
||||
public function favoritedBy(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'user_room_favorites')->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
@@ -66,4 +67,10 @@ class User extends Authenticatable implements PasskeyUser
|
||||
{
|
||||
return $this->hasMany(Room::class, 'owner_id');
|
||||
}
|
||||
|
||||
/** @return BelongsToMany<Room, $this> */
|
||||
public function favoriteRooms(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Room::class, 'user_room_favorites')->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user