* working on the fetch explore course * working on the showing the right course * finished the explore courses page * finished the explore courses page * updated the getcourseurl * updated the migration file * text and spacing improvements * update translations --------- Co-authored-by: Rotimi Best <best@classroomio.com>
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
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.member_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
|
|
})
|
|
.match(match);
|
|
|
|
console.log(`allCourses`, allCourses);
|
|
if (!Array.isArray(allCourses)) {
|
|
return {
|
|
allCourses: []
|
|
};
|
|
}
|
|
|
|
return { allCourses };
|
|
}
|
|
|
|
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 };
|
|
}
|