fix : 부서생성 API 오류 수정
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user