Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions app/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,7 @@ public function store(StoreResourceRequest $request)
$isModerator = $request->user()->can('moderate resources');
$status = $isModerator ? 'approved' : 'pending';

$chapterId = ! empty($validated['chapter_id'])
? (int) $validated['chapter_id']
: (! empty($validated['node_id']) ? (int) $validated['node_id'] : null);
$chapterId = ! empty($validated['chapter_id']) ? (int) $validated['chapter_id'] : null;
$subjectId = $chapterId
? (int) (Chapter::where('id', $chapterId)->value('subject_id') ?? $validated['subject_id'])
: (int) $validated['subject_id'];
Expand Down Expand Up @@ -381,9 +379,8 @@ public function update(UpdateResourceRequest $request, Resource $resource)
'items' => $validated['items'],
];

$inputChapterId = $validated['chapter_id'] ?? $validated['node_id'] ?? null;
if (array_key_exists('chapter_id', $validated) || array_key_exists('node_id', $validated)) {
$chapterId = ! empty($inputChapterId) ? (int) $inputChapterId : null;
if (array_key_exists('chapter_id', $validated)) {
$chapterId = ! empty($validated['chapter_id']) ? (int) $validated['chapter_id'] : null;
$updateData['chapter_id'] = $chapterId;

if ($chapterId) {
Expand Down
1 change: 0 additions & 1 deletion app/Http/Requests/Resource/StoreResourceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public function rules(): array
return [
'subject_id' => ['required', 'integer', 'exists:subjects,id'],
'chapter_id' => ['nullable', 'integer', 'exists:chapters,id'],
'node_id' => ['nullable', 'integer', 'exists:chapters,id'],
'resource_type' => ['required', 'string', 'in:note,lecture_sheet,practical,marked_book,other,video'],
'title' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string'],
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Resource/UpdateResourceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function rules(): array
{
return [
'subject_id' => ['sometimes', 'nullable', 'integer', 'exists:subjects,id'],
'node_id' => ['sometimes', 'nullable', 'integer', 'exists:nodes,id'],
'chapter_id' => ['sometimes', 'nullable', 'integer', 'exists:chapters,id'],
'title' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string'],
'resource_type' => ['required', 'string', 'in:note,lecture_sheet,practical,marked_book,other,video'],
Expand Down
3 changes: 2 additions & 1 deletion resources/js/components/forum/AskQuestionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Subject {
course: 'hsc' | 'ssc';
slug: string;
nodes?: NodeItem[];
chapters?: NodeItem[];
}

const props = withDefaults(
Expand Down Expand Up @@ -76,7 +77,7 @@ const filteredNodes = computed(() => {
(s) => s.id === Number(form.subject_id),
);

return subj?.nodes || [];
return subj?.chapters || subj?.nodes || [];
});

watch(
Expand Down
9 changes: 7 additions & 2 deletions resources/js/components/resources/ResourceFormModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface SubjectItem {

interface ResourceData {
id: number;
chapter_id?: number | null;
node_id?: number | null;
subject_id?: number | null;
user_id?: number | null;
Expand Down Expand Up @@ -350,7 +351,11 @@ const initForm = () => {
props.subject?.id ||
props.node?.subject_id ||
null;
selectedNodeId.value = props.resource.node_id || props.node?.id || null;
selectedNodeId.value =
props.resource.chapter_id ||
props.resource.node_id ||
props.node?.id ||
null;
} else {
form.value = {
title: '',
Expand Down Expand Up @@ -832,7 +837,7 @@ const handleSubmit = async () => {
description: form.value.description.trim() || null,
items: itemsPayload,
subject_id: selectedSubjectId.value,
node_id: selectedNodeId.value || null,
chapter_id: selectedNodeId.value || null,
};

const errorFallback = isEditing.value
Expand Down
3 changes: 2 additions & 1 deletion resources/js/pages/Notes/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface SubjectItem {
slug: string;
group?: string;
nodes?: NodeItem[];
chapters?: NodeItem[];
}

interface ResourceItem {
Expand Down Expand Up @@ -206,7 +207,7 @@ const availableChapters = computed(() => {

const subj = props.subjects.find((s) => s.id === selectedSubjectId.value);

return subj?.nodes || [];
return subj?.chapters || subj?.nodes || [];
});

const activeFiltersCount = computed(() => {
Expand Down
Loading