feat: admin can get all courses within org

This commit is contained in:
Rotimi Best
2024-05-22 05:49:10 +01:00
parent 6690b6bf34
commit 0536463ec9
15 changed files with 68 additions and 28 deletions
@@ -1,15 +1,23 @@
import { supabase } from '$lib/utils/functions/supabase';
import { get } from 'svelte/store';
import { isOrgAdmin } from '$lib/utils/store/org';
export async function fetchCourses(profileId, orgId) {
if (!orgId || !profileId) return;
const match = {};
// Filter by profile_id if role isn't admin within organization
if (!get(isOrgAdmin)) {
match.profile_id = profileId;
}
// Gets courses for a particular organisation where the current logged in user is a groupmember
const { data: allCourses } = await supabase
.rpc('get_courses', {
org_id_arg: orgId,
profile_id_arg: profileId
})
.eq('profile_id', profileId);
.match(match);
console.log(`allCourses`, allCourses);
if (!Array.isArray(allCourses)) {