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 <[email protected]> Merge-request: CLASSROOMIO-MR-35 Merged-by: Best Admin <[email protected]>
This commit is contained in:
committed by
Space Cloud
co-authored by
Rotimi Best
parent
92878ad0bd
commit
a9c8fbb1fd
@@ -1,16 +1,19 @@
|
|||||||
import { supabase } from '$lib/utils/functions/supabase';
|
import { supabase } from '$lib/utils/functions/supabase';
|
||||||
|
|
||||||
export async function fetchCourses(profileId) {
|
export async function fetchCourses(profileId, orgId) {
|
||||||
if (!profileId) return;
|
if (!orgId || !profileId) return;
|
||||||
|
|
||||||
|
// Gets courses for a particular organisation where the current logged in user is a groupmember
|
||||||
const { data: allCourses } = await supabase
|
const { data: allCourses } = await supabase
|
||||||
.rpc('get_courses')
|
.rpc('get_courses', {
|
||||||
|
org_id_arg: orgId
|
||||||
|
})
|
||||||
.eq('profile_id', profileId);
|
.eq('profile_id', profileId);
|
||||||
|
|
||||||
console.log(`allCourses`, allCourses);
|
console.log(`allCourses`, allCourses);
|
||||||
if (!Array.isArray(allCourses)) {
|
if (!Array.isArray(allCourses)) {
|
||||||
return {
|
return {
|
||||||
allCourses: [],
|
allCourses: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,11 @@
|
|||||||
import { currentOrg } from '$lib/utils/store/org';
|
import { currentOrg } from '$lib/utils/store/org';
|
||||||
|
|
||||||
let errors = {
|
let errors = {
|
||||||
emails: '',
|
emails: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
async function createCourse(e) {
|
async function createCourse(e) {
|
||||||
const { hasError, fieldErrors, students, tutors } =
|
const { hasError, fieldErrors, students, tutors } = validateForm($createCourseModal);
|
||||||
validateForm($createCourseModal);
|
|
||||||
|
|
||||||
errors = fieldErrors;
|
errors = fieldErrors;
|
||||||
if (hasError) return;
|
if (hasError) return;
|
||||||
@@ -38,7 +37,7 @@
|
|||||||
.insert({
|
.insert({
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
group_id,
|
group_id
|
||||||
})
|
})
|
||||||
.select();
|
.select();
|
||||||
console.log(`newCourse`, newCourse);
|
console.log(`newCourse`, newCourse);
|
||||||
@@ -52,7 +51,7 @@
|
|||||||
profile_id: $profile.id,
|
profile_id: $profile.id,
|
||||||
email: $profile.email,
|
email: $profile.email,
|
||||||
group_id,
|
group_id,
|
||||||
role_id: ROLE.TUTOR,
|
role_id: ROLE.TUTOR
|
||||||
});
|
});
|
||||||
|
|
||||||
let membersStack = [];
|
let membersStack = [];
|
||||||
@@ -62,7 +61,7 @@
|
|||||||
membersStack.push({
|
membersStack.push({
|
||||||
email: student,
|
email: student,
|
||||||
group_id,
|
group_id,
|
||||||
role_id: ROLE.STUDENT,
|
role_id: ROLE.STUDENT
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +69,7 @@
|
|||||||
membersStack.push({
|
membersStack.push({
|
||||||
email: tutor,
|
email: tutor,
|
||||||
group_id,
|
group_id,
|
||||||
role_id: ROLE.TUTOR,
|
role_id: ROLE.TUTOR
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +94,7 @@
|
|||||||
<TextField
|
<TextField
|
||||||
label="Course name"
|
label="Course name"
|
||||||
bind:value={$createCourseModal.title}
|
bind:value={$createCourseModal.title}
|
||||||
autofocus={true}
|
autoFocus={true}
|
||||||
placeholder="Your course name"
|
placeholder="Your course name"
|
||||||
className="mb-4"
|
className="mb-4"
|
||||||
isRequired={true}
|
isRequired={true}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect } from '@sveltejs/kit';
|
||||||
|
|
||||||
export const load = ({ url }) => {
|
export const load = ({ url }) => {
|
||||||
console.log('url', url.hostname);
|
|
||||||
|
|
||||||
if (url.hostname === 'classroomio.com') {
|
if (url.hostname === 'classroomio.com') {
|
||||||
throw redirect(301, 'https://about.classroomio.com');
|
throw redirect(301, 'https://about.classroomio.com');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,9 @@
|
|||||||
import Courses from '$lib/components/Courses/index.svelte';
|
import Courses from '$lib/components/Courses/index.svelte';
|
||||||
import NewCourseModal from '$lib/components/Courses/components/NewCourseModal/index.svelte';
|
import NewCourseModal from '$lib/components/Courses/components/NewCourseModal/index.svelte';
|
||||||
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
||||||
import {
|
import { courses, createCourseModal, courseMetaDeta } from '$lib/components/Courses/store';
|
||||||
courses,
|
|
||||||
createCourseModal,
|
|
||||||
courseMetaDeta,
|
|
||||||
} from '$lib/components/Courses/store';
|
|
||||||
import { setProfileIdOfGroupMember } from '$lib/utils/services/courses';
|
import { setProfileIdOfGroupMember } from '$lib/utils/services/courses';
|
||||||
|
import { currentOrg } from '$lib/utils/store/org.js';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
let { allCourses, cantFetch } = data;
|
let { allCourses, cantFetch } = data;
|
||||||
@@ -22,16 +19,13 @@
|
|||||||
$createCourseModal.open = true;
|
$createCourseModal.open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCourses(userId) {
|
async function getCourses(userId, orgId) {
|
||||||
if (cantFetch && typeof cantFetch === 'boolean' && !allCourses.length) {
|
if (cantFetch && typeof cantFetch === 'boolean' && !allCourses.length && orgId) {
|
||||||
$courseMetaDeta.isLoading = true;
|
$courseMetaDeta.isLoading = true;
|
||||||
|
|
||||||
const updatedProfile = await setProfileIdOfGroupMember(
|
const updatedProfile = await setProfileIdOfGroupMember($profile.email, userId);
|
||||||
$profile.email,
|
|
||||||
userId
|
|
||||||
);
|
|
||||||
console.log(`updatedProfile`, updatedProfile);
|
console.log(`updatedProfile`, updatedProfile);
|
||||||
const coursesResult = await fetchCourses(userId);
|
const coursesResult = await fetchCourses(userId, orgId);
|
||||||
console.log(`coursesResult`, coursesResult);
|
console.log(`coursesResult`, coursesResult);
|
||||||
|
|
||||||
$courseMetaDeta.isLoading = false;
|
$courseMetaDeta.isLoading = false;
|
||||||
@@ -46,7 +40,7 @@
|
|||||||
courses.set(allCourses);
|
courses.set(allCourses);
|
||||||
});
|
});
|
||||||
|
|
||||||
$: getCourses($profile.id);
|
$: getCourses($profile.id, $currentOrg.id);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -57,10 +51,7 @@
|
|||||||
<div class="py-10 px-5">
|
<div class="py-10 px-5">
|
||||||
<div class="flex items-center justify-between mb-10">
|
<div class="flex items-center justify-between mb-10">
|
||||||
<h1 class="dark:text-white text-3xl font-bold">Courses</h1>
|
<h1 class="dark:text-white text-3xl font-bold">Courses</h1>
|
||||||
<PrimaryButton
|
<PrimaryButton label="Create Course" onClick={() => ($createCourseModal.open = true)} />
|
||||||
label="Create Course"
|
|
||||||
onClick={() => ($createCourseModal.open = true)}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<NewCourseModal />
|
<NewCourseModal />
|
||||||
|
|||||||
Reference in New Issue
Block a user