CLASSROOMIO-T-108: Attendance improvement + complete lms exercise
This commit is contained in:
@@ -10,6 +10,7 @@ import type {
|
||||
LessonCompletion
|
||||
} from '$lib/utils/types';
|
||||
import { STATUS } from '$lib/utils/constants/course';
|
||||
import type { PostgrestError, PostgrestSingleResponse } from '@supabase/supabase-js';
|
||||
|
||||
export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']) {
|
||||
let match: { slug?: string; id?: string; status?: string } = {};
|
||||
@@ -22,7 +23,7 @@ export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']
|
||||
|
||||
match.status = STATUS[STATUS.ACTIVE];
|
||||
|
||||
const { data, error } = await supabase
|
||||
const response: PostgrestSingleResponse<Course | null> = await supabase
|
||||
.from('course')
|
||||
.select(
|
||||
`
|
||||
@@ -53,6 +54,9 @@ export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']
|
||||
)
|
||||
.match(match)
|
||||
.single();
|
||||
|
||||
const { data, error } = response;
|
||||
|
||||
console.log(`error`, error);
|
||||
if (!data || error) {
|
||||
console.log(`data`, data);
|
||||
@@ -185,7 +189,6 @@ function isNew(item: any) {
|
||||
return isNaN(item);
|
||||
}
|
||||
|
||||
// TODO: Add questionnaire type
|
||||
export async function upsertExercise(questionnaire: any, exerciseId: Exercise['id']) {
|
||||
const {
|
||||
questions,
|
||||
@@ -214,7 +217,7 @@ export async function upsertExercise(questionnaire: any, exerciseId: Exercise['i
|
||||
const { title, id, name, question_type, options, deleted_at, order, points, is_dirty } =
|
||||
question;
|
||||
|
||||
// DELETE /delete/:questionId - Don't delete if answer already given
|
||||
// "DELETE" /delete/:questionId - Don't delete if answer already given
|
||||
if (deleted_at) {
|
||||
// Delete from server only if this question exists in the database
|
||||
if (!isNew(id)) {
|
||||
@@ -232,7 +235,7 @@ export async function upsertExercise(questionnaire: any, exerciseId: Exercise['i
|
||||
continue;
|
||||
}
|
||||
|
||||
// INSERT or UPDATE /update/:questionId or /insert/:questionId
|
||||
// "INSERT" or "UPDATE" /update/:questionId or /insert/:questionId
|
||||
const newQuestion = {
|
||||
id: isNew(id) ? undefined : id,
|
||||
name: isNew(id) ? undefined : name,
|
||||
@@ -274,7 +277,7 @@ export async function upsertExercise(questionnaire: any, exerciseId: Exercise['i
|
||||
for (const option of options) {
|
||||
const { deleted_at, is_dirty } = option;
|
||||
|
||||
// DELETE /delete/:optionId
|
||||
// "DELETE" /delete/:optionId
|
||||
if (deleted_at) {
|
||||
// if this option exists in the database
|
||||
if (!isNew(option.id)) {
|
||||
@@ -285,7 +288,7 @@ export async function upsertExercise(questionnaire: any, exerciseId: Exercise['i
|
||||
continue;
|
||||
}
|
||||
|
||||
// INSERT and UPDATE
|
||||
// "INSERT" and "UPDATE"
|
||||
const newOption = {
|
||||
...option,
|
||||
is_dirty: undefined,
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
import type { PostgrestError } from '@supabase/supabase-js';
|
||||
|
||||
export interface LMSExercise {
|
||||
id: string;
|
||||
title: string;
|
||||
updated_at: string;
|
||||
submission: {
|
||||
status_id: number;
|
||||
updated_at: string;
|
||||
groupmember: {
|
||||
id: string;
|
||||
profile: {
|
||||
id: string;
|
||||
}[];
|
||||
}[];
|
||||
}[];
|
||||
lesson: {
|
||||
id: string;
|
||||
title: string;
|
||||
order: number;
|
||||
course: {
|
||||
id: string;
|
||||
title: string;
|
||||
group: {
|
||||
organisation: {
|
||||
id: string;
|
||||
}[];
|
||||
}[];
|
||||
groupmember: {
|
||||
id: string;
|
||||
profile: {
|
||||
id: string;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
interface FetchLMSExercisesResponse {
|
||||
exercises: LMSExercise[] | null;
|
||||
error: PostgrestError | null;
|
||||
}
|
||||
|
||||
export async function fetchLMSExercises(
|
||||
profileId: string,
|
||||
orgId: string
|
||||
): Promise<FetchLMSExercisesResponse> {
|
||||
const { data, error } = await supabase
|
||||
.from('exercise')
|
||||
.select(
|
||||
`
|
||||
id,
|
||||
title,
|
||||
updated_at,
|
||||
submission (
|
||||
status_id,
|
||||
updated_at,
|
||||
groupmember:submitted_by!inner (
|
||||
id,
|
||||
profile!inner (
|
||||
id
|
||||
)
|
||||
)
|
||||
),
|
||||
lesson!inner (
|
||||
id,
|
||||
title,
|
||||
order,
|
||||
course!inner (
|
||||
id,
|
||||
title,
|
||||
group:group_id!inner (
|
||||
organisation:organization_id!inner (
|
||||
id
|
||||
)
|
||||
),
|
||||
groupmember:group_id!inner(
|
||||
id,
|
||||
profile!inner (
|
||||
id
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
`
|
||||
)
|
||||
.eq('lesson.course.group.organisation.id', orgId)
|
||||
.eq('lesson.course.groupmember.profile.id', profileId)
|
||||
.eq('submission.groupmember.profile.id', profileId);
|
||||
|
||||
return {
|
||||
exercises: data,
|
||||
error
|
||||
};
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const attendance = writable({});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const attendance = writable<{
|
||||
[key: string]: {
|
||||
[key: string]: {
|
||||
is_present: boolean;
|
||||
id: number;
|
||||
};
|
||||
};
|
||||
}>({});
|
||||
@@ -1,6 +1,19 @@
|
||||
export * from './config';
|
||||
export * from './dashboard';
|
||||
|
||||
//===============Custom Type===============
|
||||
export interface GroupPerson {
|
||||
assigned_student_id: number | null;
|
||||
created_at: string;
|
||||
email: string | null;
|
||||
group_id: string;
|
||||
id: string;
|
||||
profile: Profile;
|
||||
profile_id: string;
|
||||
role_id: Role['id'];
|
||||
}
|
||||
//===========================================
|
||||
|
||||
interface CourseMetadata {
|
||||
requirements: string;
|
||||
description: string;
|
||||
@@ -109,6 +122,12 @@ export interface Course {
|
||||
is_published?: boolean;
|
||||
progress_rate?: number;
|
||||
total_lessons?: number;
|
||||
attendance: {
|
||||
student_id: string;
|
||||
lesson_id: string;
|
||||
is_present: boolean;
|
||||
id: number;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface Groupmember {
|
||||
|
||||
Reference in New Issue
Block a user