Merge branch 'main' of https://github.com/classroomio/classroomio into feat/release-v2
This commit is contained in:
@@ -10,6 +10,7 @@ import type {
|
||||
ProfileCourseProgress
|
||||
} from '$lib/utils/types';
|
||||
import type { PostgrestError, PostgrestSingleResponse } from '@supabase/supabase-js';
|
||||
import { getAccessToken, supabase } from '$lib/utils/functions/supabase';
|
||||
|
||||
import { GenericUploader } from './presign';
|
||||
import { QUESTION_TYPE } from '$lib/components/Question/constants';
|
||||
@@ -18,7 +19,6 @@ import { STATUS } from '$lib/utils/constants/course';
|
||||
import { get } from 'svelte/store';
|
||||
import { isOrgAdmin } from '$lib/utils/store/org';
|
||||
import { isUUID } from '$lib/utils/functions/isUUID';
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
import { uploadImage } from '$lib/utils/services/upload';
|
||||
|
||||
export async function fetchCourses(profileId, orgId) {
|
||||
@@ -155,6 +155,33 @@ export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchCourseFromAPI(courseId: Course['id']) {
|
||||
try {
|
||||
const accessToken = await getAccessToken();
|
||||
|
||||
const response = await fetch('/api/courses/data', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: accessToken
|
||||
},
|
||||
body: JSON.stringify({ courseId })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!result.success) {
|
||||
console.error('fetchCourseFromAPI error:', result.message);
|
||||
return { data: null, error: result.error || result.message };
|
||||
}
|
||||
|
||||
return { data: result.data, error: null };
|
||||
} catch (error) {
|
||||
console.error('fetchCourseFromAPI error:', error);
|
||||
return { data: null, error };
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchExploreCourses(profileId, orgId) {
|
||||
if (!orgId || !profileId) return;
|
||||
|
||||
@@ -345,8 +372,29 @@ export function createExercise(exercise: any) {
|
||||
return supabase.from('exercise').insert(exercise).select();
|
||||
}
|
||||
|
||||
export function fetchExercisesByMarks(courseId: Course['id']) {
|
||||
return supabase.rpc('get_exercises').eq('course_id', courseId);
|
||||
export async function fetchExercisesByMarks(courseId: Course['id']) {
|
||||
try {
|
||||
const accessToken = await getAccessToken();
|
||||
|
||||
const response = await fetch('/api/courses/exercises', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: accessToken
|
||||
},
|
||||
body: JSON.stringify({ courseId })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!result.success) {
|
||||
return { data: null, error: result.message };
|
||||
}
|
||||
|
||||
return { data: result.data, error: null };
|
||||
} catch (error) {
|
||||
return { data: null, error };
|
||||
}
|
||||
}
|
||||
|
||||
function isNew(item: any) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Course } from '$lib/utils/types';
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
import { supabase, getAccessToken } from '$lib/utils/functions/supabase';
|
||||
import type { Reaction, FeedApi, Feed } from '$lib/utils/types/feed';
|
||||
|
||||
export async function fetchNewsFeedReaction(feedId: Feed['id']) {
|
||||
@@ -7,38 +7,34 @@ export async function fetchNewsFeedReaction(feedId: Feed['id']) {
|
||||
}
|
||||
|
||||
export async function fetchNewsFeeds(courseId?: Course['id']) {
|
||||
const response = await supabase
|
||||
.from('course_newsfeed')
|
||||
.select(
|
||||
`
|
||||
id,
|
||||
created_at,
|
||||
content,
|
||||
course_id,
|
||||
author:groupmember(
|
||||
profile(
|
||||
id,
|
||||
fullname,
|
||||
avatar_url
|
||||
)
|
||||
),
|
||||
reaction,
|
||||
is_pinned,
|
||||
comment:course_newsfeed_comment(
|
||||
id,
|
||||
created_at,
|
||||
author:groupmember( profile(id, fullname, avatar_url) ),
|
||||
content,
|
||||
course_newsfeed_id)
|
||||
`
|
||||
)
|
||||
.match({ course_id: courseId })
|
||||
.order('created_at', { ascending: false })
|
||||
.returns<FeedApi[]>();
|
||||
const accessToken = await getAccessToken();
|
||||
|
||||
const { data, error } = response;
|
||||
const response = await fetch(`/api/courses/newsfeed?courseId=${courseId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: accessToken
|
||||
}
|
||||
});
|
||||
|
||||
return { data, error };
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
return {
|
||||
data: null,
|
||||
error: { message: error }
|
||||
};
|
||||
}
|
||||
|
||||
const { success, data, message } = await response.json();
|
||||
|
||||
if (!success) {
|
||||
return {
|
||||
data: null,
|
||||
error: { message }
|
||||
};
|
||||
}
|
||||
|
||||
return { data, error: null };
|
||||
}
|
||||
|
||||
export async function createNewFeed(post: {
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
import { supabase, getAccessToken } from '$lib/utils/functions/supabase';
|
||||
import type { ExerciseSubmissions } from '$lib/utils/types';
|
||||
|
||||
export function fetchSubmissionStatus() {
|
||||
return supabase.from('submissionstatus').select(`*`);
|
||||
}
|
||||
|
||||
export function fetchSubmissions(course_id: string) {
|
||||
return supabase
|
||||
.from('submission')
|
||||
.select(
|
||||
`
|
||||
id,
|
||||
created_at,
|
||||
answers:question_answer(*),
|
||||
exercise:exercise_id(
|
||||
id, title, due_by,
|
||||
lesson:lesson_id(id, title),
|
||||
questions:question(
|
||||
*,
|
||||
options:option(*),
|
||||
question_type:question_type_id(id, label)
|
||||
)
|
||||
),
|
||||
status_id,
|
||||
feedback,
|
||||
course:course_id(*),
|
||||
groupmember:submitted_by(
|
||||
profile(*)
|
||||
)
|
||||
`
|
||||
)
|
||||
.match({
|
||||
course_id
|
||||
});
|
||||
export async function fetchSubmissions(course_id: string) {
|
||||
const accessToken = await getAccessToken();
|
||||
|
||||
const response = await fetch(`/api/courses/submissions?courseId=${course_id}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: accessToken
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
return {
|
||||
data: null,
|
||||
error: { message: error }
|
||||
};
|
||||
}
|
||||
|
||||
const { success, data, message } = await response.json();
|
||||
|
||||
if (!success) {
|
||||
return {
|
||||
data: null,
|
||||
error: { message }
|
||||
};
|
||||
}
|
||||
|
||||
return { data, error: null };
|
||||
}
|
||||
|
||||
export async function fetchSubmission({
|
||||
@@ -44,40 +45,38 @@ export async function fetchSubmission({
|
||||
courseId?: string;
|
||||
submittedBy?: string;
|
||||
}) {
|
||||
const query: {
|
||||
exercise_id: string;
|
||||
course_id?: string;
|
||||
submitted_by?: string;
|
||||
} = {
|
||||
exercise_id: exerciseId
|
||||
};
|
||||
const accessToken = await getAccessToken();
|
||||
|
||||
if (courseId) {
|
||||
query.course_id = courseId;
|
||||
}
|
||||
if (submittedBy) {
|
||||
query.submitted_by = submittedBy;
|
||||
const params = new URLSearchParams({ exerciseId });
|
||||
if (courseId) params.append('courseId', courseId);
|
||||
if (submittedBy) params.append('submittedBy', submittedBy);
|
||||
|
||||
const response = await fetch(`/api/courses/submission?${params.toString()}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: accessToken
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
return {
|
||||
data: null,
|
||||
error: { message: error }
|
||||
};
|
||||
}
|
||||
|
||||
return supabase
|
||||
.from('submission')
|
||||
.select(
|
||||
`
|
||||
id,
|
||||
answers:question_answer(*),
|
||||
status_id,
|
||||
feedback,
|
||||
submitted_by:groupmember!inner(
|
||||
profile!inner(
|
||||
id,
|
||||
fullname,
|
||||
avatar_url
|
||||
)
|
||||
)
|
||||
`
|
||||
)
|
||||
.match(query)
|
||||
.returns<ExerciseSubmissions[]>();
|
||||
const { success, data, message } = await response.json();
|
||||
|
||||
if (!success) {
|
||||
return {
|
||||
data: null,
|
||||
error: { message }
|
||||
};
|
||||
}
|
||||
|
||||
return { data, error: null };
|
||||
}
|
||||
|
||||
export async function updateSubmission(
|
||||
|
||||
Reference in New Issue
Block a user