fix: [QMS] 점검표 토글 해제 안되는 버그 수정
- PHP foreach 참조(&)와 ?? 연산자 조합 시 임시 복사본이 생성되어 원본 배열 수정 불가 - `$category['subItems'] ?? []` → `empty() + continue` + `$category['subItems']` 로 변경 - 토글 API가 항상 is_completed: true 반환하던 문제 해결 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -93,17 +93,59 @@ public function save(int $id, array $data): array
|
||||
$template->refresh();
|
||||
|
||||
$this->auditLogger->log(
|
||||
$this->tenantId(),
|
||||
self::AUDIT_TARGET,
|
||||
$template->id,
|
||||
'updated',
|
||||
$before,
|
||||
$template->toArray(),
|
||||
$this->apiUserId()
|
||||
$template->toArray()
|
||||
);
|
||||
|
||||
return $this->getByType($template->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 항목 완료 토글
|
||||
*/
|
||||
public function toggleItem(int $id, string $subItemId): array
|
||||
{
|
||||
$template = ChecklistTemplate::findOrFail($id);
|
||||
$categories = $template->categories;
|
||||
$toggled = null;
|
||||
|
||||
foreach ($categories as &$category) {
|
||||
if (empty($category['subItems'])) {
|
||||
continue;
|
||||
}
|
||||
foreach ($category['subItems'] as &$subItem) {
|
||||
if ($subItem['id'] === $subItemId) {
|
||||
$subItem['is_completed'] = ! ($subItem['is_completed'] ?? false);
|
||||
$subItem['completed_at'] = $subItem['is_completed'] ? now()->toIso8601String() : null;
|
||||
$toggled = $subItem;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
unset($subItem);
|
||||
}
|
||||
unset($category);
|
||||
|
||||
if (! $toggled) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
$template->update([
|
||||
'categories' => $categories,
|
||||
'updated_by' => $this->apiUserId(),
|
||||
]);
|
||||
|
||||
return [
|
||||
'id' => $toggled['id'],
|
||||
'name' => $toggled['name'],
|
||||
'is_completed' => $toggled['is_completed'],
|
||||
'completed_at' => $toggled['completed_at'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 항목별 파일 목록 조회
|
||||
*/
|
||||
@@ -152,7 +194,7 @@ public function uploadDocument(int $templateId, string $subItemId, $uploadedFile
|
||||
);
|
||||
|
||||
// 파일 저장
|
||||
Storage::disk('tenant')->put($filePath, file_get_contents($uploadedFile->getPathname()));
|
||||
Storage::disk('r2')->put($filePath, file_get_contents($uploadedFile->getPathname()));
|
||||
|
||||
// DB 레코드 생성
|
||||
$file = File::create([
|
||||
|
||||
Reference in New Issue
Block a user