feat: admin can get all courses within org

This commit is contained in:
Rotimi Best
2024-05-22 05:49:10 +01:00
parent 6690b6bf34
commit 0536463ec9
15 changed files with 68 additions and 28 deletions
@@ -25,7 +25,7 @@
import type { GroupPerson, Lesson } from '$lib/utils/types/index';
import { browser } from '$app/environment';
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;
@@ -26,7 +26,7 @@
import { course, group } from '$lib/components/Course/store';
import DateField from '$lib/components/Form/Date.svelte';
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 { COURSE_TYPE } from '$lib/utils/types';
@@ -36,7 +36,7 @@
import type { LessonCompletion } from '$lib/utils/types';
import { profile } from '$lib/utils/store/user';
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';
export let data;
@@ -30,7 +30,7 @@
import { snackbar } from '$lib/components/Snackbar/store';
import Avatar from '$lib/components/Avatar/index.svelte';
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 { goto } from '$app/navigation';
@@ -25,7 +25,7 @@
} from '$lib/utils/services/notification/notification';
import { currentOrg, currentOrgDomain } from '$lib/utils/store/org';
import { browser } from '$app/environment';
import { t } from '$lib/utils/functions/translations.js';
import { t } from '$lib/utils/functions/translations';
type items = {
id: number;
@@ -23,8 +23,10 @@
import TextEditor from '$lib/components/TextEditor/index.svelte';
import { calDateDiff } from '$lib/utils/functions/date';
import { browser } from '$app/environment';
import { fetchCourses } from '$lib/components/Courses/api.js';
import { t } from '$lib/utils/functions/translations.js';
import { fetchCourses } from '$lib/components/Courses/api';
import { t } from '$lib/utils/functions/translations';
import { courses } from '$lib/components/Courses/store';
import type { Course } from '$lib/utils/types';
export let data;
const { slug } = data;
@@ -86,7 +88,7 @@
};
let editorInstance = false;
let fetchedCourses = [];
let fetchedCourses: Course[] = [];
function mapResToQuestion(data): Question {
return {
@@ -115,8 +117,13 @@
}
async function getCourses(userId: string | null, orgId: string) {
if ($courses.length) {
fetchedCourses = [...$courses];
return;
}
const coursesResults = await fetchCourses(userId, orgId);
fetchedCourses = coursesResults.allCourses;
fetchedCourses = coursesResults?.allCourses || [];
}
async function fetchCommunityQuestion(slug: string) {
@@ -13,6 +13,8 @@
import { profile } from '$lib/utils/store/user';
import { fetchCourses } from '$lib/components/Courses/api';
import { t } from '$lib/utils/functions/translations';
import { courses } from '$lib/components/Courses/store';
import type { Course } from '$lib/utils/types';
let errors: {
title?: string;
@@ -24,11 +26,16 @@
courseId: ''
};
let fetchedCourses = [];
let fetchedCourses: Course[] = [];
async function getCourses(userId: string | null, orgId: string) {
if ($courses.length) {
fetchedCourses = [...$courses];
return;
}
const coursesResults = await fetchCourses(userId, orgId);
fetchedCourses = coursesResults.allCourses;
fetchedCourses = coursesResults?.allCourses || [];
}
async function handleSave() {
@@ -20,7 +20,7 @@
import VisitOrgSiteButton from '$lib/components/Buttons/VisitOrgSite.svelte';
import { getGreeting } from '$lib/utils/functions/date';
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;
@@ -23,8 +23,10 @@
import TextEditor from '$lib/components/TextEditor/index.svelte';
import { calDateDiff } from '$lib/utils/functions/date';
import { browser } from '$app/environment';
import { fetchCourses } from '$lib/components/Courses/api.js';
import { t } from '$lib/utils/functions/translations.js';
import { fetchCourses } from '$lib/components/Courses/api';
import { t } from '$lib/utils/functions/translations';
import { courses } from '$lib/components/Courses/store';
import type { Course } from '$lib/utils/types';
export let data;
const { slug } = data;
@@ -85,7 +87,7 @@
};
let editorInstance = false;
let fetchedCourses = [];
let fetchedCourses: Course[] = [];
function mapResToQuestion(data): Question {
return {
@@ -114,8 +116,13 @@
}
async function getCourses(userId: string | null, orgId: string) {
if ($courses.length) {
fetchedCourses = [...$courses];
return;
}
const coursesResults = await fetchCourses(userId, orgId);
fetchedCourses = coursesResults.allCourses;
fetchedCourses = coursesResults?.allCourses || [];
}
async function fetchCommunityQuestion(slug: string) {
@@ -13,7 +13,9 @@
import TextField from '$lib/components/Form/TextField.svelte';
import { profile } from '$lib/utils/store/user';
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: {
title?: string;
@@ -25,9 +27,14 @@
courseId: ''
};
let fetchedCourses: any[] = [];
let fetchedCourses: Course[] = [];
async function getCourses(userId: string | null, orgId: string) {
if ($courses.length) {
fetchedCourses = [...$courses];
return;
}
const coursesResults = await fetchCourses(userId, orgId);
if (!coursesResults) return;
@@ -12,7 +12,7 @@
import { isOrgAdmin } from '$lib/utils/store/org';
import type { Course } from '$lib/utils/types';
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 IconButton from '$lib/components/IconButton/index.svelte';
import Grid from 'carbon-icons-svelte/lib/Grid.svelte';
@@ -29,6 +29,7 @@
let hasFetched = false;
async function getCourses(userId: string | undefined, orgId: string) {
console.log({ org: $currentOrg });
if (cantFetch && typeof cantFetch === 'boolean' && orgId && !hasFetched) {
// only show is loading when fetching for the first time
if (!$courses.length) {