Delete a course functionality
This commit is contained in:
@@ -2,9 +2,10 @@ import { supabase } from '$lib/utils/functions/supabase';
|
||||
import { isUUID } from '$lib/utils/functions/isUUID';
|
||||
import { QUESTION_TYPE } from '$lib/components/Question/constants';
|
||||
import type { Lesson, Course, Group, Groupmember, Exercise } from '$lib/utils/types';
|
||||
import { STATUS } from '$lib/utils/constants/course';
|
||||
|
||||
export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']) {
|
||||
let match: { slug?: string; id?: string } = {};
|
||||
let match: { slug?: string; id?: string; status?: string } = {};
|
||||
|
||||
if (slug) {
|
||||
match.slug = slug;
|
||||
@@ -12,6 +13,8 @@ export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']
|
||||
match.id = courseId;
|
||||
}
|
||||
|
||||
match.status = STATUS[STATUS.ACTIVE];
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('course')
|
||||
.select(
|
||||
@@ -109,7 +112,7 @@ export async function updateCourse(
|
||||
avatar: string | undefined,
|
||||
course: Course
|
||||
) {
|
||||
if (avatar) {
|
||||
if (avatar && courseId) {
|
||||
const filename = `course/${courseId + Date.now()}.webp`;
|
||||
|
||||
const { data } = await supabase.storage.from('avatars').upload(filename, avatar, {
|
||||
@@ -132,7 +135,7 @@ export async function updateCourse(
|
||||
}
|
||||
|
||||
export async function deleteCourse(courseId: Course['id']) {
|
||||
return await supabase.from('course').delete().match({ id: courseId });
|
||||
return await supabase.from('course').update({ status: 'DELETED' }).match({ id: courseId });
|
||||
}
|
||||
|
||||
export function addGroupMember(member: any) {
|
||||
|
||||
@@ -147,6 +147,7 @@ export async function getCourseBySiteName(siteName) {
|
||||
`
|
||||
)
|
||||
.eq('group.organization.siteName', siteName)
|
||||
.eq('status', 'ACTIVE')
|
||||
.eq('is_published', true);
|
||||
|
||||
if (error) {
|
||||
|
||||
Reference in New Issue
Block a user