fix : 회원 관리 API 수정 및 ApiResponse 타입 수정
This commit is contained in:
@@ -3,17 +3,50 @@
|
||||
namespace App\Models\Members;
|
||||
|
||||
use App\Models\Commons\Role;
|
||||
use App\Models\File;
|
||||
use App\Models\Commons\File;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use App\Traits\ModelTrait;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, Notifiable, SoftDeletes, ModelTrait;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'phone',
|
||||
'email',
|
||||
'options',
|
||||
'profile_photo_path',
|
||||
];
|
||||
|
||||
protected $guarded = [
|
||||
'id',
|
||||
'user_id',
|
||||
'password',
|
||||
'remember_token',
|
||||
'two_factor_secret',
|
||||
'two_factor_recovery_codes',
|
||||
'two_factor_confirmed_at',
|
||||
'email_verified_at',
|
||||
'last_login_at',
|
||||
'current_team_id',
|
||||
'deleted_at',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'last_login_at' => 'datetime',
|
||||
'options' => 'array',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at'
|
||||
@@ -24,9 +57,8 @@ public function userTenants()
|
||||
return $this->hasMany(UserTenant::class);
|
||||
}
|
||||
|
||||
public function userTenant() // 단일 기본 테넌트
|
||||
public function userTenant()
|
||||
{
|
||||
// 예시: 첫 번째(기본) 테넌트 반환
|
||||
return $this->hasOne(UserTenant::class)->where('is_active', 1);
|
||||
}
|
||||
|
||||
@@ -37,8 +69,7 @@ public function userRoles()
|
||||
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'user_roles')
|
||||
->withPivot('tenant_id', 'assigned_at');
|
||||
return $this->belongsToMany(Role::class, 'user_roles')->withPivot('tenant_id', 'assigned_at');
|
||||
}
|
||||
|
||||
public function userTenantById($tenantId)
|
||||
@@ -50,4 +81,12 @@ public function files()
|
||||
{
|
||||
return $this->morphMany(File::class, 'fileable');
|
||||
}
|
||||
|
||||
public function tenantsMembership(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Tenant::class, 'user_tenants', 'user_id', 'tenant_id')
|
||||
->as('membership') // pivot 대신 membership으로 표기
|
||||
->withPivot(['is_active', 'is_default', 'joined_at', 'left_at', 'deleted_at'])
|
||||
->wherePivotNull('deleted_at'); // 소프트삭제 제외
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,26 @@ class UserTenant extends Model
|
||||
use SoftDeletes, ModelTrait, BelongsToTenant;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'tenant_id', 'is_active', 'joined_at', 'left_at'
|
||||
'user_id', 'tenant_id', 'is_active', 'is_default', 'joined_at', 'left_at'
|
||||
];
|
||||
|
||||
protected $guarded = [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'joined_at' => 'datetime',
|
||||
'left_at' => 'datetime',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
public function user()
|
||||
|
||||
@@ -31,11 +31,28 @@ class Tenant extends Model
|
||||
'billing_tp_code',
|
||||
];
|
||||
|
||||
protected $guarded = [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'plan_id',
|
||||
'subscription_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'trial_ends_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
'last_paid_at' => 'datetime',
|
||||
'max_users' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'admin_memo',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
// 관계 정의 (예시)
|
||||
|
||||
Reference in New Issue
Block a user