feat: admin can get all courses within org
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
import { profile } from '$lib/utils/store/user';
|
||||
import { Search, Dropdown } from 'carbon-components-svelte';
|
||||
import { t } from '$lib/utils/functions/translations';
|
||||
import { courses } from '$lib/components/Courses/store';
|
||||
|
||||
export let isLMS = false;
|
||||
|
||||
@@ -26,8 +27,12 @@
|
||||
if (!orgId || !profileId) return;
|
||||
isLoading = true;
|
||||
|
||||
const courseResult = (await fetchCourses(profileId, orgId)) || { allCourses: [] };
|
||||
allCourses = courseResult.allCourses;
|
||||
if ($courses.length) {
|
||||
allCourses = [...$courses];
|
||||
} else {
|
||||
const courseResult = (await fetchCourses(profileId, orgId)) || { allCourses: [] };
|
||||
allCourses = courseResult.allCourses;
|
||||
}
|
||||
|
||||
const courseIds = allCourses.map((course) => course.id);
|
||||
const courseIdsFilter = `(${courseIds.join(',')})`;
|
||||
|
||||
@@ -14,7 +14,7 @@ export const defaultCurrentOrgState: CurrentOrg = {
|
||||
siteName: '',
|
||||
avatar_url: '',
|
||||
memberId: '',
|
||||
role_id: '',
|
||||
role_id: 3,
|
||||
landingpage: {},
|
||||
customization: {
|
||||
apps: { poll: true, comments: true },
|
||||
@@ -29,10 +29,8 @@ export const orgs = writable<CurrentOrg[]>([]);
|
||||
export const currentOrg: Writable<CurrentOrg> = writable(defaultCurrentOrgState);
|
||||
export const orgAudience = writable<OrgAudience[]>([]);
|
||||
export const orgTeam = writable<OrgTeamMember[]>([]);
|
||||
export const isOrgAdmin = derived(
|
||||
currentOrg,
|
||||
($currentOrg) => parseInt($currentOrg.role_id) === ROLE.ADMIN
|
||||
);
|
||||
export const isOrgAdmin = derived(currentOrg, ($currentOrg) => $currentOrg.role_id === ROLE.ADMIN);
|
||||
|
||||
export const currentOrgPlan = derived(currentOrg, ($currentOrg) =>
|
||||
$currentOrg.organization_plan.find((p) => p.is_active)
|
||||
);
|
||||
|
||||
@@ -22,7 +22,7 @@ export interface CurrentOrg {
|
||||
siteName: string;
|
||||
avatar_url: string;
|
||||
memberId: string;
|
||||
role_id: string;
|
||||
role_id: number;
|
||||
landingpage: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user