CLASSROOMIO-T-100: Select only courses belonging to current org and current user is a member

CLASSROOMIO-T-100: Update condition for fetchCourses

CLASSROOMIO-T-100: Select only courses belonging to current org and current user is a member


Co-authored-by: Rotimi Best <rotimiibitoyeemma@gmail.com>


Merge-request: CLASSROOMIO-MR-35
Merged-by: Best Admin <best@digdippa.com>
This commit is contained in:
Rotimi Best
2023-08-07 06:18:30 +00:00
committed by Space Cloud
co-authored by Rotimi Best
parent 92878ad0bd
commit a9c8fbb1fd
4 changed files with 22 additions and 31 deletions
+7 -4
View File
@@ -1,16 +1,19 @@
import { supabase } from '$lib/utils/functions/supabase';
export async function fetchCourses(profileId) {
if (!profileId) return;
export async function fetchCourses(profileId, orgId) {
if (!orgId || !profileId) return;
// Gets courses for a particular organisation where the current logged in user is a groupmember
const { data: allCourses } = await supabase
.rpc('get_courses')
.rpc('get_courses', {
org_id_arg: orgId
})
.eq('profile_id', profileId);
console.log(`allCourses`, allCourses);
if (!Array.isArray(allCourses)) {
return {
allCourses: [],
allCourses: []
};
}
@@ -12,12 +12,11 @@
import { currentOrg } from '$lib/utils/store/org';
let errors = {
emails: '',
emails: ''
};
async function createCourse(e) {
const { hasError, fieldErrors, students, tutors } =
validateForm($createCourseModal);
const { hasError, fieldErrors, students, tutors } = validateForm($createCourseModal);
errors = fieldErrors;
if (hasError) return;
@@ -38,7 +37,7 @@
.insert({
title,
description,
group_id,
group_id
})
.select();
console.log(`newCourse`, newCourse);
@@ -52,7 +51,7 @@
profile_id: $profile.id,
email: $profile.email,
group_id,
role_id: ROLE.TUTOR,
role_id: ROLE.TUTOR
});
let membersStack = [];
@@ -62,7 +61,7 @@
membersStack.push({
email: student,
group_id,
role_id: ROLE.STUDENT,
role_id: ROLE.STUDENT
});
}
@@ -70,7 +69,7 @@
membersStack.push({
email: tutor,
group_id,
role_id: ROLE.TUTOR,
role_id: ROLE.TUTOR
});
}
@@ -95,7 +94,7 @@
<TextField
label="Course name"
bind:value={$createCourseModal.title}
autofocus={true}
autoFocus={true}
placeholder="Your course name"
className="mb-4"
isRequired={true}