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
@@ -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() {