diff --git a/app/composables/useCurrentStudentProgress.ts b/app/composables/useCurrentStudentProgress.ts index 38b9f65..3e728f1 100644 --- a/app/composables/useCurrentStudentProgress.ts +++ b/app/composables/useCurrentStudentProgress.ts @@ -36,6 +36,7 @@ export const useCurrentStudentProgress = () => { try { const response = await $fetch('/api/formSubmission', { + method: 'GET', query: { student: student.value.id } }) submissions.value = Array.isArray(response) ? response : [] @@ -45,8 +46,7 @@ export const useCurrentStudentProgress = () => { } } - // Log a new form submission to track progress - const logFormSubmission = async (formId: number) => { + const logFormSubmission = async (formId: number, responses: Record) => { if (!student.value?.id) { console.error('Cannot log form submission: No student is currently active.') return null @@ -57,7 +57,11 @@ export const useCurrentStudentProgress = () => { method: 'POST', body: { student: student.value.id, - form: formId + form: formId, + Responses: Object.entries(responses).map(([formComponentId, response]) => ({ + formComponent: Number(formComponentId), + response + })) } }) @@ -70,13 +74,6 @@ export const useCurrentStudentProgress = () => { } } - const logSubmissionResponse = async (submissionID: number, formComponentID: number, response: string) => { - if (!student.value?.id) { - console.error('Cannot log form submission: No student is currently active.') - return null - } - } - return { submissions, completedFormIds, @@ -84,6 +81,5 @@ export const useCurrentStudentProgress = () => { isFormGroupCompleted, loadProgress, logFormSubmission, - logSubmissionResponse } } diff --git a/app/pages/reader/forms.vue b/app/pages/reader/forms.vue index 055f781..db7b4cb 100644 --- a/app/pages/reader/forms.vue +++ b/app/pages/reader/forms.vue @@ -3,7 +3,7 @@ definePageMeta({ ssr: false }) const { student, settings, updateExp, restoreStudent } = useCurrentStudent() const { FormGroup, loadActiveFormGroup } = useCurrentFormGroup() -const { tickets, completedFormIds, logFormSubmission, logSubmissionResponse, loadProgress } = useCurrentStudentProgress() +const { tickets, completedFormIds, logFormSubmission, loadProgress } = useCurrentStudentProgress() const dataLoaded = ref(false) @@ -182,11 +182,13 @@ async function submitChallenge() { const formId = activeForm.value.id // Persist completion and XP - const submission = await logFormSubmission(formId) + const submission = await logFormSubmission(formId, answers.value) + const submissionID = Number(submission?.id) + await updateExp(100) // grab newly posted submission ID - const submissionID = Number(submission?.id) + showRaffleReward.value = true ticketDropped.value = false @@ -440,7 +442,7 @@ function getBadgeClass(type: string) {
- +