fix : 부서생성 API 오류 수정
This commit is contained in:
@@ -28,6 +28,10 @@ class Department extends Model
|
||||
'sort_order'=> 'integer',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'deleted_by','deleted_at'
|
||||
];
|
||||
|
||||
/** Relations */
|
||||
public function departmentUsers()
|
||||
{
|
||||
|
||||
@@ -59,8 +59,8 @@ public function index(array $params)
|
||||
/** 생성 */
|
||||
public function store(array $params)
|
||||
{
|
||||
// 테넌트 강제가 필요하면 아래 라인 사용:
|
||||
// $this->tenantIdOrFail();
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$p = $this->v($params, [
|
||||
'code' => 'nullable|string|max:50',
|
||||
@@ -79,13 +79,14 @@ public function store(array $params)
|
||||
}
|
||||
|
||||
$dept = Department::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'code' => $p['code'] ?? null,
|
||||
'name' => $p['name'],
|
||||
'description' => $p['description'] ?? null,
|
||||
'is_active' => isset($p['is_active']) ? (int)$p['is_active'] : 1,
|
||||
'sort_order' => $p['sort_order'] ?? 0,
|
||||
'created_by' => $p['created_by'] ?? null,
|
||||
'updated_by' => $p['created_by'] ?? null,
|
||||
'created_by' => $userId ?? null,
|
||||
'updated_by' => $userId ?? null,
|
||||
]);
|
||||
|
||||
return $dept->fresh();
|
||||
@@ -202,6 +203,8 @@ public function attachUser(int $deptId, array $params)
|
||||
if (!$dept) return ['error' => '부서를 찾을 수 없습니다.', 'code' => 404];
|
||||
|
||||
$result = DB::transaction(function () use ($dept, $p) {
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$du = DepartmentUser::withTrashed()
|
||||
->where('department_id', $dept->id)
|
||||
->where('user_id', $p['user_id'])
|
||||
@@ -219,6 +222,7 @@ public function attachUser(int $deptId, array $params)
|
||||
|
||||
$payload = [
|
||||
'department_id' => $dept->id,
|
||||
'tenant_id' => $tenantId,
|
||||
'user_id' => $p['user_id'],
|
||||
'is_primary' => isset($p['is_primary']) ? (int)$p['is_primary'] : 0,
|
||||
'joined_at' => !empty($p['joined_at']) ? Carbon::parse($p['joined_at']) : now(),
|
||||
|
||||
@@ -25,7 +25,7 @@ protected function tenantId(): int
|
||||
}
|
||||
|
||||
/** (선택) API 사용자 ID 필요할 때 401로 던지고 싶다면 */
|
||||
protected function apiUserIdOrFail(): int
|
||||
protected function apiUserId(): int
|
||||
{
|
||||
$uid = app('api_user');
|
||||
if (!$uid) {
|
||||
|
||||
Reference in New Issue
Block a user