Files
classroomio/apps/dashboard/src/lib/components/Courses/api.js
T

48 lines
1.1 KiB
JavaScript
Raw Normal View History

import { supabase } from '$lib/utils/functions/supabase';
2024-05-22 05:49:10 +01:00
import { get } from 'svelte/store';
import { isOrgAdmin } from '$lib/utils/store/org';
2021-08-21 13:26:43 +03:00
export async function fetchCourses(profileId, orgId) {
if (!orgId || !profileId) return;
2021-08-21 13:26:43 +03:00
2024-05-22 05:49:10 +01:00
const match = {};
// Filter by profile_id if role isn't admin within organization
if (!get(isOrgAdmin)) {
match.member_profile_id = profileId;
2024-05-22 05:49:10 +01:00
}
// Gets courses for a particular organisation where the current logged in user is a groupmember
2021-08-21 13:26:43 +03:00
const { data: allCourses } = await supabase
.rpc('get_courses', {
org_id_arg: orgId,
profile_id_arg: profileId
})
2024-05-22 05:49:10 +01:00
.match(match);
2021-08-21 13:26:43 +03:00
2021-08-24 18:20:07 +03:00
console.log(`allCourses`, allCourses);
if (!Array.isArray(allCourses)) {
return {
allCourses: []
};
}
2021-08-24 18:20:07 +03:00
return { allCourses };
2021-08-21 13:26:43 +03:00
}
export async function fetchExploreCourses(profileId, orgId) {
if (!orgId || !profileId) return;
const { data: allCourses } = await supabase.rpc('get_explore_courses', {
org_id_arg: orgId,
profile_id_arg: profileId
});
if (!Array.isArray(allCourses)) {
return {
allCourses: []
};
}
return { allCourses };
}