From 52352f7896dde7d3f093e1c645f104b667796e43 Mon Sep 17 00:00:00 2001 From: hskwon Date: Thu, 21 Aug 2025 15:43:06 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EB=B6=80=EC=84=9C=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20API=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Commons/Department.php | 4 ++++ app/Services/DepartmentService.php | 12 ++++++++---- app/Services/Service.php | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/Models/Commons/Department.php b/app/Models/Commons/Department.php index 7dbe7db..c54d950 100644 --- a/app/Models/Commons/Department.php +++ b/app/Models/Commons/Department.php @@ -28,6 +28,10 @@ class Department extends Model 'sort_order'=> 'integer', ]; + protected $hidden = [ + 'deleted_by','deleted_at' + ]; + /** Relations */ public function departmentUsers() { diff --git a/app/Services/DepartmentService.php b/app/Services/DepartmentService.php index d8522f8..2cdc045 100644 --- a/app/Services/DepartmentService.php +++ b/app/Services/DepartmentService.php @@ -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(), diff --git a/app/Services/Service.php b/app/Services/Service.php index 49e19ca..b51f3b2 100644 --- a/app/Services/Service.php +++ b/app/Services/Service.php @@ -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) {