2023-08-02 19:35:27 +01:00
|
|
|
import { supabase } from '$lib/utils/functions/supabase';
|
2023-10-19 08:31:57 +00:00
|
|
|
import type { ExerciseSubmissions } from '$lib/utils/types';
|
2021-08-18 19:47:02 +03:00
|
|
|
|
|
|
|
|
export function fetchSubmissionStatus() {
|
|
|
|
|
return supabase.from('submissionstatus').select(`*`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 08:31:57 +00:00
|
|
|
export function fetchSubmissions(course_id: string) {
|
2021-08-18 19:47:02 +03:00
|
|
|
return supabase
|
|
|
|
|
.from('submission')
|
|
|
|
|
.select(
|
|
|
|
|
`
|
|
|
|
|
id,
|
2021-09-24 13:20:40 +03:00
|
|
|
created_at,
|
2021-08-18 19:47:02 +03:00
|
|
|
answers:question_answer(*),
|
|
|
|
|
exercise:exercise_id(
|
2021-09-24 13:20:40 +03:00
|
|
|
id, title, due_by,
|
2021-08-18 19:47:02 +03:00
|
|
|
lesson:lesson_id(id, title),
|
|
|
|
|
questions:question(
|
|
|
|
|
*,
|
|
|
|
|
options:option(*),
|
|
|
|
|
question_type:question_type_id(id, label)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
status_id,
|
2024-05-13 19:35:06 +01:00
|
|
|
feedback,
|
2021-08-18 19:47:02 +03:00
|
|
|
course:course_id(*),
|
|
|
|
|
groupmember:submitted_by(
|
|
|
|
|
profile(*)
|
|
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
)
|
|
|
|
|
.match({
|
2023-10-18 08:09:52 +00:00
|
|
|
course_id
|
2021-08-18 19:47:02 +03:00
|
|
|
});
|
|
|
|
|
}
|
2021-09-04 22:27:00 +03:00
|
|
|
|
2023-10-19 08:31:57 +00:00
|
|
|
export async function fetchSubmission({
|
|
|
|
|
courseId,
|
|
|
|
|
exerciseId,
|
|
|
|
|
submittedBy
|
|
|
|
|
}: {
|
|
|
|
|
exerciseId: string;
|
|
|
|
|
courseId?: string;
|
|
|
|
|
submittedBy?: string;
|
|
|
|
|
}) {
|
|
|
|
|
const query: {
|
|
|
|
|
exercise_id: string;
|
|
|
|
|
course_id?: string;
|
|
|
|
|
submitted_by?: string;
|
|
|
|
|
} = {
|
|
|
|
|
exercise_id: exerciseId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (courseId) {
|
|
|
|
|
query.course_id = courseId;
|
|
|
|
|
}
|
|
|
|
|
if (submittedBy) {
|
|
|
|
|
query.submitted_by = submittedBy;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-04 22:27:00 +03:00
|
|
|
return supabase
|
|
|
|
|
.from('submission')
|
|
|
|
|
.select(
|
|
|
|
|
`
|
|
|
|
|
id,
|
|
|
|
|
answers:question_answer(*),
|
2023-10-19 08:31:57 +00:00
|
|
|
status_id,
|
2024-05-13 19:35:06 +01:00
|
|
|
feedback,
|
2023-10-19 08:31:57 +00:00
|
|
|
submitted_by:groupmember!inner(
|
|
|
|
|
profile!inner(
|
|
|
|
|
id,
|
|
|
|
|
fullname,
|
|
|
|
|
avatar_url
|
|
|
|
|
)
|
|
|
|
|
)
|
2021-09-04 22:27:00 +03:00
|
|
|
`
|
|
|
|
|
)
|
2023-10-19 08:31:57 +00:00
|
|
|
.match(query)
|
|
|
|
|
.returns<ExerciseSubmissions[]>();
|
2021-09-04 22:27:00 +03:00
|
|
|
}
|
|
|
|
|
|
2023-10-18 08:09:52 +00:00
|
|
|
export async function updateSubmission(
|
2024-05-13 19:35:06 +01:00
|
|
|
{
|
|
|
|
|
id,
|
|
|
|
|
status_id,
|
|
|
|
|
total,
|
|
|
|
|
feedback
|
2024-08-03 20:58:07 +01:00
|
|
|
}: { id: string; status_id?: number; total?: number; feedback?: string },
|
|
|
|
|
otherArgs?: Record<string, string>
|
2023-10-18 08:09:52 +00:00
|
|
|
) {
|
2023-10-19 08:31:57 +00:00
|
|
|
const toUpdate: {
|
|
|
|
|
status_id?: number;
|
|
|
|
|
total?: number;
|
2024-05-13 19:35:06 +01:00
|
|
|
feedback?: string;
|
2023-10-19 08:31:57 +00:00
|
|
|
} = {
|
2024-05-13 19:35:06 +01:00
|
|
|
status_id,
|
|
|
|
|
feedback
|
2021-09-04 22:27:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (typeof total === 'number') {
|
|
|
|
|
toUpdate.total = total;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-11 19:27:11 +03:00
|
|
|
return supabase.from('submission').update(toUpdate, otherArgs).match({ id });
|
2021-09-04 22:27:00 +03:00
|
|
|
}
|
|
|
|
|
|
2024-08-03 20:58:07 +01:00
|
|
|
export async function deleteSubmission(id: string) {
|
|
|
|
|
return supabase.from('submission').delete().match({ id });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateQuestionAnswer(
|
|
|
|
|
update: Record<string, string>,
|
|
|
|
|
match: Record<string, string>
|
|
|
|
|
) {
|
2021-09-04 22:27:00 +03:00
|
|
|
return supabase.from('question_answer').update(update).match(match);
|
|
|
|
|
}
|