feat: [users] 사용자 관리에 직급/직책 입력 UI 추가
- 사용자 수정/생성 화면에 직급(position_key), 직책(job_title_key) 선택 필드 추가 - HR 사원관리의 position-add-modal 재사용 ([+] 버튼으로 새 직급/직책 추가) - UserService에서 tenant_user_profiles 테이블에 저장 (updateOrInsert) - UpdateUserRequest, StoreUserRequest에 validation 규칙 추가
This commit is contained in:
@@ -105,8 +105,11 @@ public function createUser(array $data): User
|
||||
$data['password'] = Hash::make($plainPassword);
|
||||
}
|
||||
|
||||
// password_confirmation은 User 모델의 fillable이 아니므로 제거
|
||||
// User 모델의 fillable이 아닌 필드 분리
|
||||
unset($data['password_confirmation']);
|
||||
$positionKey = $data['position_key'] ?? null;
|
||||
$jobTitleKey = $data['job_title_key'] ?? null;
|
||||
unset($data['position_key'], $data['job_title_key']);
|
||||
|
||||
// is_active 처리
|
||||
$data['is_active'] = isset($data['is_active']) && $data['is_active'] == '1';
|
||||
@@ -136,6 +139,23 @@ public function createUser(array $data): User
|
||||
$this->syncDepartments($user, $tenantId, $departmentIds);
|
||||
}
|
||||
|
||||
// position_key, job_title_key → tenant_user_profiles 저장
|
||||
if ($tenantId) {
|
||||
$profileFields = [];
|
||||
if (! empty($positionKey)) {
|
||||
$profileFields['position_key'] = $positionKey;
|
||||
}
|
||||
if (! empty($jobTitleKey)) {
|
||||
$profileFields['job_title_key'] = $jobTitleKey;
|
||||
}
|
||||
if (! empty($profileFields)) {
|
||||
DB::table('tenant_user_profiles')->updateOrInsert(
|
||||
['tenant_id' => $tenantId, 'user_id' => $user->id],
|
||||
$profileFields
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 본사만 비밀번호 안내 메일 발송 (비본사는 관리자가 직접 알려줌)
|
||||
if ($plainPassword !== null) {
|
||||
$this->sendPasswordMail($user, $plainPassword, true);
|
||||
@@ -228,8 +248,25 @@ public function updateUser(int $id, array $data): bool
|
||||
$this->syncDepartments($user, $tenantId, $departmentIds);
|
||||
}
|
||||
|
||||
// role_ids, department_ids는 User 모델의 fillable이 아니므로 제거
|
||||
unset($data['role_ids'], $data['department_ids']);
|
||||
// position_key, job_title_key → tenant_user_profiles 저장
|
||||
if ($tenantId) {
|
||||
$profileFields = [];
|
||||
if (array_key_exists('position_key', $data)) {
|
||||
$profileFields['position_key'] = $data['position_key'] ?: null;
|
||||
}
|
||||
if (array_key_exists('job_title_key', $data)) {
|
||||
$profileFields['job_title_key'] = $data['job_title_key'] ?: null;
|
||||
}
|
||||
if (! empty($profileFields)) {
|
||||
DB::table('tenant_user_profiles')->updateOrInsert(
|
||||
['tenant_id' => $tenantId, 'user_id' => $id],
|
||||
$profileFields
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// role_ids, department_ids, position/job_title은 User 모델의 fillable이 아니므로 제거
|
||||
unset($data['role_ids'], $data['department_ids'], $data['position_key'], $data['job_title_key']);
|
||||
|
||||
return $user->update($data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user