feat: 사원-회원 연결 기능 구현 (Phase 2 API)

- store() 수정: create_account=false면 password=NULL 허용 (사원 전용)
- revokeAccount() 추가: 시스템 계정 해제 (password=NULL, 토큰 무효화)
- POST /employees/{id}/revoke-account 라우트 추가
- ko/employee.php, en/employee.php 언어 파일 생성

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-26 00:34:21 +09:00
parent 7ff6f3a57c
commit 2017b8fc79
5 changed files with 110 additions and 6 deletions

View File

@@ -89,6 +89,10 @@ public function show(int $id): TenantUserProfile
/**
* 사원 등록 (users 테이블에 사용자 생성 + tenant_user_profiles 생성)
*
* @param array $data 사원 데이터
* - create_account: bool (true=시스템 계정 생성, false=사원 전용)
* - password: string (create_account=true일 때 필수)
*/
public function store(array $data): TenantUserProfile
{
@@ -96,25 +100,32 @@ public function store(array $data): TenantUserProfile
$userId = $this->apiUserId();
return DB::transaction(function () use ($data, $tenantId, $userId) {
// 1. users 테이블에 사용자 생성
// 1. 비밀번호 결정: create_account=false면 NULL (사원 전용, 로그인 불가)
$password = null;
$createAccount = $data['create_account'] ?? false;
if ($createAccount && ! empty($data['password'])) {
$password = Hash::make($data['password']);
}
// 2. users 테이블에 사용자 생성
$user = User::create([
'user_id' => $data['user_id'] ?? $this->generateUserId($data['email']),
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'] ?? null,
'password' => Hash::make($data['password'] ?? Str::random(16)),
'password' => $password,
'is_active' => $data['is_active'] ?? true,
'created_by' => $userId,
]);
// 2. user_tenants pivot에 관계 추가
// 3. user_tenants pivot에 관계 추가
$user->tenantsMembership()->attach($tenantId, [
'is_active' => true,
'is_default' => true,
'joined_at' => now(),
]);
// 3. tenant_user_profiles 생성
// 4. tenant_user_profiles 생성
$profile = TenantUserProfile::create([
'tenant_id' => $tenantId,
'user_id' => $user->id,
@@ -129,7 +140,7 @@ public function store(array $data): TenantUserProfile
'display_name' => $data['display_name'] ?? null,
]);
// 4. json_extra 사원 정보 설정
// 5. json_extra 사원 정보 설정
$profile->updateEmployeeInfo([
'employee_code' => $data['employee_code'] ?? null,
'resident_number' => $data['resident_number'] ?? null,
@@ -331,6 +342,43 @@ public function createAccount(int $id, string $password): TenantUserProfile
return $profile->fresh(['user', 'department', 'manager']);
}
/**
* 시스템 계정 해제 (비밀번호 제거 → 로그인 불가, 사원 정보 유지)
*/
public function revokeAccount(int $id): TenantUserProfile
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
$profile = TenantUserProfile::query()
->where('tenant_id', $tenantId)
->with('user')
->find($id);
if (! $profile) {
throw new NotFoundHttpException(__('error.not_found'));
}
$user = $profile->user;
// 이미 계정이 없는 경우
if (empty($user->password)) {
throw new \InvalidArgumentException(__('employee.no_account'));
}
// 1. 비밀번호 제거 (로그인 불가)
$user->update([
'password' => null,
'must_change_password' => false,
'updated_by' => $userId,
]);
// 2. 기존 토큰 무효화 (로그아웃 처리)
$user->tokens()->delete();
return $profile->fresh(['user', 'department', 'manager']);
}
/**
* 사용자 ID 자동 생성
*/