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 { supabase } from '$lib/utils/functions/supabase';
|
||||||
|
import { get } from 'svelte/store';
|
||||||
|
import { isOrgAdmin } from '$lib/utils/store/org';
|
||||||
|
|
||||||
export async function fetchCourses(profileId, orgId) {
|
export async function fetchCourses(profileId, orgId) {
|
||||||
if (!orgId || !profileId) return;
|
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
|
// 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,
|
org_id_arg: orgId,
|
||||||
profile_id_arg: profileId
|
profile_id_arg: profileId
|
||||||
})
|
})
|
||||||
.eq('profile_id', profileId);
|
.match(match);
|
||||||
|
|
||||||
console.log(`allCourses`, allCourses);
|
console.log(`allCourses`, allCourses);
|
||||||
if (!Array.isArray(allCourses)) {
|
if (!Array.isArray(allCourses)) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
import { profile } from '$lib/utils/store/user';
|
import { profile } from '$lib/utils/store/user';
|
||||||
import { Search, Dropdown } from 'carbon-components-svelte';
|
import { Search, Dropdown } from 'carbon-components-svelte';
|
||||||
import { t } from '$lib/utils/functions/translations';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
|
import { courses } from '$lib/components/Courses/store';
|
||||||
|
|
||||||
export let isLMS = false;
|
export let isLMS = false;
|
||||||
|
|
||||||
@@ -26,8 +27,12 @@
|
|||||||
if (!orgId || !profileId) return;
|
if (!orgId || !profileId) return;
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
|
|
||||||
const courseResult = (await fetchCourses(profileId, orgId)) || { allCourses: [] };
|
if ($courses.length) {
|
||||||
allCourses = courseResult.allCourses;
|
allCourses = [...$courses];
|
||||||
|
} else {
|
||||||
|
const courseResult = (await fetchCourses(profileId, orgId)) || { allCourses: [] };
|
||||||
|
allCourses = courseResult.allCourses;
|
||||||
|
}
|
||||||
|
|
||||||
const courseIds = allCourses.map((course) => course.id);
|
const courseIds = allCourses.map((course) => course.id);
|
||||||
const courseIdsFilter = `(${courseIds.join(',')})`;
|
const courseIdsFilter = `(${courseIds.join(',')})`;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const defaultCurrentOrgState: CurrentOrg = {
|
|||||||
siteName: '',
|
siteName: '',
|
||||||
avatar_url: '',
|
avatar_url: '',
|
||||||
memberId: '',
|
memberId: '',
|
||||||
role_id: '',
|
role_id: 3,
|
||||||
landingpage: {},
|
landingpage: {},
|
||||||
customization: {
|
customization: {
|
||||||
apps: { poll: true, comments: true },
|
apps: { poll: true, comments: true },
|
||||||
@@ -29,10 +29,8 @@ export const orgs = writable<CurrentOrg[]>([]);
|
|||||||
export const currentOrg: Writable<CurrentOrg> = writable(defaultCurrentOrgState);
|
export const currentOrg: Writable<CurrentOrg> = writable(defaultCurrentOrgState);
|
||||||
export const orgAudience = writable<OrgAudience[]>([]);
|
export const orgAudience = writable<OrgAudience[]>([]);
|
||||||
export const orgTeam = writable<OrgTeamMember[]>([]);
|
export const orgTeam = writable<OrgTeamMember[]>([]);
|
||||||
export const isOrgAdmin = derived(
|
export const isOrgAdmin = derived(currentOrg, ($currentOrg) => $currentOrg.role_id === ROLE.ADMIN);
|
||||||
currentOrg,
|
|
||||||
($currentOrg) => parseInt($currentOrg.role_id) === ROLE.ADMIN
|
|
||||||
);
|
|
||||||
export const currentOrgPlan = derived(currentOrg, ($currentOrg) =>
|
export const currentOrgPlan = derived(currentOrg, ($currentOrg) =>
|
||||||
$currentOrg.organization_plan.find((p) => p.is_active)
|
$currentOrg.organization_plan.find((p) => p.is_active)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export interface CurrentOrg {
|
|||||||
siteName: string;
|
siteName: string;
|
||||||
avatar_url: string;
|
avatar_url: string;
|
||||||
memberId: string;
|
memberId: string;
|
||||||
role_id: string;
|
role_id: number;
|
||||||
landingpage: {
|
landingpage: {
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
import type { GroupPerson, Lesson } from '$lib/utils/types/index';
|
import type { GroupPerson, Lesson } from '$lib/utils/types/index';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { globalStore } from '$lib/utils/store/app';
|
import { globalStore } from '$lib/utils/store/app';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
import { course, group } from '$lib/components/Course/store';
|
import { course, group } from '$lib/components/Course/store';
|
||||||
import DateField from '$lib/components/Form/Date.svelte';
|
import DateField from '$lib/components/Form/Date.svelte';
|
||||||
import type { Course, Lesson } from '$lib/utils/types';
|
import type { Course, Lesson } from '$lib/utils/types';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { COURSE_TYPE } from '$lib/utils/types';
|
import { COURSE_TYPE } from '$lib/utils/types';
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
import type { LessonCompletion } from '$lib/utils/types';
|
import type { LessonCompletion } from '$lib/utils/types';
|
||||||
import { profile } from '$lib/utils/store/user';
|
import { profile } from '$lib/utils/store/user';
|
||||||
import { getIsLessonComplete } from '$lib/components/Course/components/Lesson/functions';
|
import { getIsLessonComplete } from '$lib/components/Course/components/Lesson/functions';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
import { LANGUAGES } from '$lib/utils/constants/translation';
|
import { LANGUAGES } from '$lib/utils/constants/translation';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
import { snackbar } from '$lib/components/Snackbar/store';
|
import { snackbar } from '$lib/components/Snackbar/store';
|
||||||
import Avatar from '$lib/components/Avatar/index.svelte';
|
import Avatar from '$lib/components/Avatar/index.svelte';
|
||||||
import type { GroupPerson } from '$lib/utils/types';
|
import type { GroupPerson } from '$lib/utils/types';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
} from '$lib/utils/services/notification/notification';
|
} from '$lib/utils/services/notification/notification';
|
||||||
import { currentOrg, currentOrgDomain } from '$lib/utils/store/org';
|
import { currentOrg, currentOrgDomain } from '$lib/utils/store/org';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
|
|
||||||
type items = {
|
type items = {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
@@ -23,8 +23,10 @@
|
|||||||
import TextEditor from '$lib/components/TextEditor/index.svelte';
|
import TextEditor from '$lib/components/TextEditor/index.svelte';
|
||||||
import { calDateDiff } from '$lib/utils/functions/date';
|
import { calDateDiff } from '$lib/utils/functions/date';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { fetchCourses } from '$lib/components/Courses/api.js';
|
import { fetchCourses } from '$lib/components/Courses/api';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
|
import { courses } from '$lib/components/Courses/store';
|
||||||
|
import type { Course } from '$lib/utils/types';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
const { slug } = data;
|
const { slug } = data;
|
||||||
@@ -86,7 +88,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
let editorInstance = false;
|
let editorInstance = false;
|
||||||
let fetchedCourses = [];
|
let fetchedCourses: Course[] = [];
|
||||||
|
|
||||||
function mapResToQuestion(data): Question {
|
function mapResToQuestion(data): Question {
|
||||||
return {
|
return {
|
||||||
@@ -115,8 +117,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getCourses(userId: string | null, orgId: string) {
|
async function getCourses(userId: string | null, orgId: string) {
|
||||||
|
if ($courses.length) {
|
||||||
|
fetchedCourses = [...$courses];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const coursesResults = await fetchCourses(userId, orgId);
|
const coursesResults = await fetchCourses(userId, orgId);
|
||||||
fetchedCourses = coursesResults.allCourses;
|
fetchedCourses = coursesResults?.allCourses || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchCommunityQuestion(slug: string) {
|
async function fetchCommunityQuestion(slug: string) {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
import { profile } from '$lib/utils/store/user';
|
import { profile } from '$lib/utils/store/user';
|
||||||
import { fetchCourses } from '$lib/components/Courses/api';
|
import { fetchCourses } from '$lib/components/Courses/api';
|
||||||
import { t } from '$lib/utils/functions/translations';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
|
import { courses } from '$lib/components/Courses/store';
|
||||||
|
import type { Course } from '$lib/utils/types';
|
||||||
|
|
||||||
let errors: {
|
let errors: {
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -24,11 +26,16 @@
|
|||||||
courseId: ''
|
courseId: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
let fetchedCourses = [];
|
let fetchedCourses: Course[] = [];
|
||||||
|
|
||||||
async function getCourses(userId: string | null, orgId: string) {
|
async function getCourses(userId: string | null, orgId: string) {
|
||||||
|
if ($courses.length) {
|
||||||
|
fetchedCourses = [...$courses];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const coursesResults = await fetchCourses(userId, orgId);
|
const coursesResults = await fetchCourses(userId, orgId);
|
||||||
fetchedCourses = coursesResults.allCourses;
|
fetchedCourses = coursesResults?.allCourses || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
import VisitOrgSiteButton from '$lib/components/Buttons/VisitOrgSite.svelte';
|
import VisitOrgSiteButton from '$lib/components/Buttons/VisitOrgSite.svelte';
|
||||||
import { getGreeting } from '$lib/utils/functions/date';
|
import { getGreeting } from '$lib/utils/functions/date';
|
||||||
import { globalStore } from '$lib/utils/store/app';
|
import { globalStore } from '$lib/utils/store/app';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,10 @@
|
|||||||
import TextEditor from '$lib/components/TextEditor/index.svelte';
|
import TextEditor from '$lib/components/TextEditor/index.svelte';
|
||||||
import { calDateDiff } from '$lib/utils/functions/date';
|
import { calDateDiff } from '$lib/utils/functions/date';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { fetchCourses } from '$lib/components/Courses/api.js';
|
import { fetchCourses } from '$lib/components/Courses/api';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
|
import { courses } from '$lib/components/Courses/store';
|
||||||
|
import type { Course } from '$lib/utils/types';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
const { slug } = data;
|
const { slug } = data;
|
||||||
@@ -85,7 +87,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
let editorInstance = false;
|
let editorInstance = false;
|
||||||
let fetchedCourses = [];
|
let fetchedCourses: Course[] = [];
|
||||||
|
|
||||||
function mapResToQuestion(data): Question {
|
function mapResToQuestion(data): Question {
|
||||||
return {
|
return {
|
||||||
@@ -114,8 +116,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getCourses(userId: string | null, orgId: string) {
|
async function getCourses(userId: string | null, orgId: string) {
|
||||||
|
if ($courses.length) {
|
||||||
|
fetchedCourses = [...$courses];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const coursesResults = await fetchCourses(userId, orgId);
|
const coursesResults = await fetchCourses(userId, orgId);
|
||||||
fetchedCourses = coursesResults.allCourses;
|
fetchedCourses = coursesResults?.allCourses || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchCommunityQuestion(slug: string) {
|
async function fetchCommunityQuestion(slug: string) {
|
||||||
|
|||||||
@@ -13,7 +13,9 @@
|
|||||||
import TextField from '$lib/components/Form/TextField.svelte';
|
import TextField from '$lib/components/Form/TextField.svelte';
|
||||||
import { profile } from '$lib/utils/store/user';
|
import { profile } from '$lib/utils/store/user';
|
||||||
import { fetchCourses } from '$lib/components/Courses/api';
|
import { fetchCourses } from '$lib/components/Courses/api';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
|
import { courses } from '$lib/components/Courses/store';
|
||||||
|
import type { Course } from '$lib/utils/types';
|
||||||
|
|
||||||
let errors: {
|
let errors: {
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -25,9 +27,14 @@
|
|||||||
courseId: ''
|
courseId: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
let fetchedCourses: any[] = [];
|
let fetchedCourses: Course[] = [];
|
||||||
|
|
||||||
async function getCourses(userId: string | null, orgId: string) {
|
async function getCourses(userId: string | null, orgId: string) {
|
||||||
|
if ($courses.length) {
|
||||||
|
fetchedCourses = [...$courses];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const coursesResults = await fetchCourses(userId, orgId);
|
const coursesResults = await fetchCourses(userId, orgId);
|
||||||
if (!coursesResults) return;
|
if (!coursesResults) return;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
import { isOrgAdmin } from '$lib/utils/store/org';
|
import { isOrgAdmin } from '$lib/utils/store/org';
|
||||||
import type { Course } from '$lib/utils/types';
|
import type { Course } from '$lib/utils/types';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { t } from '$lib/utils/functions/translations.js';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
|
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
|
||||||
import IconButton from '$lib/components/IconButton/index.svelte';
|
import IconButton from '$lib/components/IconButton/index.svelte';
|
||||||
import Grid from 'carbon-icons-svelte/lib/Grid.svelte';
|
import Grid from 'carbon-icons-svelte/lib/Grid.svelte';
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
let hasFetched = false;
|
let hasFetched = false;
|
||||||
|
|
||||||
async function getCourses(userId: string | undefined, orgId: string) {
|
async function getCourses(userId: string | undefined, orgId: string) {
|
||||||
|
console.log({ org: $currentOrg });
|
||||||
if (cantFetch && typeof cantFetch === 'boolean' && orgId && !hasFetched) {
|
if (cantFetch && typeof cantFetch === 'boolean' && orgId && !hasFetched) {
|
||||||
// only show is loading when fetching for the first time
|
// only show is loading when fetching for the first time
|
||||||
if (!$courses.length) {
|
if (!$courses.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user