Skip to content

Commit 0a1e9c0

Browse files
authored
fix: resolve chapter dropdown in notes & ask modal, update resource request validation (#487)
* fix: resolve chapter dropdown in notes & ask modal, update resource request validation * refactor(resources): unify node_id to chapter_id across form modal and requests * style: format ResourceFormModal with prettier
1 parent 4b50dea commit 0a1e9c0

6 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎app/Http/Controllers/ResourceController.php‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,7 @@ public function store(StoreResourceRequest $request)
332332
$isModerator = $request->user()->can('moderate resources');
333333
$status = $isModerator ? 'approved' : 'pending';
334334

335-
$chapterId = ! empty($validated['chapter_id'])
336-
? (int) $validated['chapter_id']
337-
: (! empty($validated['node_id']) ? (int) $validated['node_id'] : null);
335+
$chapterId = ! empty($validated['chapter_id']) ? (int) $validated['chapter_id'] : null;
338336
$subjectId = $chapterId
339337
? (int) (Chapter::where('id', $chapterId)->value('subject_id') ?? $validated['subject_id'])
340338
: (int) $validated['subject_id'];
@@ -381,9 +379,8 @@ public function update(UpdateResourceRequest $request, Resource $resource)
381379
'items' => $validated['items'],
382380
];
383381

384-
$inputChapterId = $validated['chapter_id'] ?? $validated['node_id'] ?? null;
385-
if (array_key_exists('chapter_id', $validated) || array_key_exists('node_id', $validated)) {
386-
$chapterId = ! empty($inputChapterId) ? (int) $inputChapterId : null;
382+
if (array_key_exists('chapter_id', $validated)) {
383+
$chapterId = ! empty($validated['chapter_id']) ? (int) $validated['chapter_id'] : null;
387384
$updateData['chapter_id'] = $chapterId;
388385

389386
if ($chapterId) {

‎app/Http/Requests/Resource/StoreResourceRequest.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public function rules(): array
1616
return [
1717
'subject_id' => ['required', 'integer', 'exists:subjects,id'],
1818
'chapter_id' => ['nullable', 'integer', 'exists:chapters,id'],
19-
'node_id' => ['nullable', 'integer', 'exists:chapters,id'],
2019
'resource_type' => ['required', 'string', 'in:note,lecture_sheet,practical,marked_book,other,video'],
2120
'title' => ['required', 'string', 'max:255'],
2221
'description' => ['nullable', 'string'],

‎app/Http/Requests/Resource/UpdateResourceRequest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function rules(): array
1515
{
1616
return [
1717
'subject_id' => ['sometimes', 'nullable', 'integer', 'exists:subjects,id'],
18-
'node_id' => ['sometimes', 'nullable', 'integer', 'exists:nodes,id'],
18+
'chapter_id' => ['sometimes', 'nullable', 'integer', 'exists:chapters,id'],
1919
'title' => ['required', 'string', 'max:255'],
2020
'description' => ['nullable', 'string'],
2121
'resource_type' => ['required', 'string', 'in:note,lecture_sheet,practical,marked_book,other,video'],

‎resources/js/components/forum/AskQuestionModal.vue‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface Subject {
1818
course: 'hsc' | 'ssc';
1919
slug: string;
2020
nodes?: NodeItem[];
21+
chapters?: NodeItem[];
2122
}
2223
2324
const props = withDefaults(
@@ -76,7 +77,7 @@ const filteredNodes = computed(() => {
7677
(s) => s.id === Number(form.subject_id),
7778
);
7879
79-
return subj?.nodes || [];
80+
return subj?.chapters || subj?.nodes || [];
8081
});
8182
8283
watch(

‎resources/js/components/resources/ResourceFormModal.vue‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface SubjectItem {
4747
4848
interface ResourceData {
4949
id: number;
50+
chapter_id?: number | null;
5051
node_id?: number | null;
5152
subject_id?: number | null;
5253
user_id?: number | null;
@@ -350,7 +351,11 @@ const initForm = () => {
350351
props.subject?.id ||
351352
props.node?.subject_id ||
352353
null;
353-
selectedNodeId.value = props.resource.node_id || props.node?.id || null;
354+
selectedNodeId.value =
355+
props.resource.chapter_id ||
356+
props.resource.node_id ||
357+
props.node?.id ||
358+
null;
354359
} else {
355360
form.value = {
356361
title: '',
@@ -832,7 +837,7 @@ const handleSubmit = async () => {
832837
description: form.value.description.trim() || null,
833838
items: itemsPayload,
834839
subject_id: selectedSubjectId.value,
835-
node_id: selectedNodeId.value || null,
840+
chapter_id: selectedNodeId.value || null,
836841
};
837842
838843
const errorFallback = isEditing.value

‎resources/js/pages/Notes/Index.vue‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface SubjectItem {
3737
slug: string;
3838
group?: string;
3939
nodes?: NodeItem[];
40+
chapters?: NodeItem[];
4041
}
4142
4243
interface ResourceItem {
@@ -206,7 +207,7 @@ const availableChapters = computed(() => {
206207
207208
const subj = props.subjects.find((s) => s.id === selectedSubjectId.value);
208209
209-
return subj?.nodes || [];
210+
return subj?.chapters || subj?.nodes || [];
210211
});
211212
212213
const activeFiltersCount = computed(() => {

0 commit comments

Comments
 (0)