Get courses by members data
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
import { supabase } from '../../utils/functions/supabase';
|
||||
|
||||
export async function fetchCourses(userId) {
|
||||
const { data: orgMember } = await supabase
|
||||
.from('organizationmember')
|
||||
.select(`organization_id`)
|
||||
.eq('profile_id', userId)
|
||||
.single();
|
||||
export async function fetchCourses(profileId) {
|
||||
if (!profileId) return;
|
||||
|
||||
const { data: allCourses } = await supabase
|
||||
.from('course')
|
||||
.select(`id, title, description`)
|
||||
.eq('organization_id', orgMember.organization_id);
|
||||
.rpc('get_courses')
|
||||
.eq('profile_id', profileId);
|
||||
|
||||
return { allCourses, organizationId: orgMember.organization_id };
|
||||
console.log(`allCourses`, allCourses);
|
||||
|
||||
return { allCourses };
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</div>
|
||||
|
||||
{#if $user.isLoggedIn}
|
||||
<li>
|
||||
<li class="hidden">
|
||||
<a
|
||||
class="block"
|
||||
aria-current={segment === undefined || segment === 'dashboard'
|
||||
@@ -50,7 +50,7 @@
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<li class="hidden">
|
||||
<a
|
||||
class="block"
|
||||
aria-current={segment === 'discussions' || segment === 'discussion'
|
||||
@@ -62,7 +62,7 @@
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<li class="hidden">
|
||||
<a
|
||||
class="block"
|
||||
aria-current={segment === 'people' ? 'page' : undefined}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script context="module">
|
||||
export function preload(page, { config }) {
|
||||
console.log(`page`, page);
|
||||
return { config, isMvpUser: !!page.query.mvp };
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
export async function preload(page, params) {
|
||||
const parsedUser = JSON.parse(params.user);
|
||||
|
||||
if (parsedUser && parsedUser.id) {
|
||||
return fetchCourses(parsedUser.id);
|
||||
}
|
||||
// if (parsedUser && parsedUser.id) {
|
||||
// return fetchCourses(parsedUser.id);
|
||||
// }
|
||||
|
||||
return {
|
||||
allCourses: [],
|
||||
organizationId: null,
|
||||
cantFetch: !parsedUser,
|
||||
cantFetch: true,
|
||||
};
|
||||
}
|
||||
</script>
|
||||
@@ -64,7 +64,7 @@
|
||||
title,
|
||||
description,
|
||||
group_id,
|
||||
organization_id: organizationId,
|
||||
// organization_id: organizationId,
|
||||
});
|
||||
|
||||
// Get profile of author and add as member
|
||||
@@ -100,7 +100,7 @@
|
||||
}
|
||||
|
||||
async function getCourses(userId) {
|
||||
console.log(`getCourses process.browser`, process.browser);
|
||||
console.log(`getCourses process.browser`, process.browser, cantFetch);
|
||||
if (process.browser) {
|
||||
if (cantFetch && typeof cantFetch === 'boolean' && !allCourses.length) {
|
||||
const coursesResult = await fetchCourses(userId);
|
||||
@@ -113,7 +113,6 @@
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
console.log(`onMount cantFetch`, cantFetch);
|
||||
courses.set(allCourses);
|
||||
});
|
||||
|
||||
|
||||
@@ -5,21 +5,23 @@
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import Overview from '../../../components/Course/index.svelte';
|
||||
import CourseContainer from '../../../components/CourseContainer/index.svelte';
|
||||
import { setCourseData, course } from '../../../components/Course/store';
|
||||
import { setCourseData } from '../../../components/Course/store';
|
||||
import { fetchCourse } from '../../../utils/services/courses';
|
||||
|
||||
export let courseId;
|
||||
|
||||
onMount(async () => {
|
||||
async function onCourseIdChange(courseId) {
|
||||
if (!courseId) return;
|
||||
console.log(`overview courseId`, courseId);
|
||||
if ($course.id) return;
|
||||
|
||||
const { data } = await fetchCourse(courseId);
|
||||
|
||||
setCourseData(data);
|
||||
});
|
||||
}
|
||||
|
||||
$: onCourseIdChange(courseId);
|
||||
</script>
|
||||
|
||||
<CourseContainer>
|
||||
|
||||
@@ -75,10 +75,15 @@
|
||||
<p
|
||||
class="bg-yellow-500 w-1/4 text-sm text-center rounded-xl text-white"
|
||||
>
|
||||
Pending confirmation
|
||||
Pending Invite
|
||||
</p>
|
||||
{/if}
|
||||
<p class="text-lg w-1/4 break-all">{person.email}</p>
|
||||
<a
|
||||
href="mailto:{person.email}"
|
||||
class="text-md w-1/4 mx-2 text-blue-600"
|
||||
>
|
||||
{person.email}
|
||||
</a>
|
||||
<p class="text-lg w-1/4 ">{ROLE_LABEL[person.role_id]}</p>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
This are the organizations you work at
|
||||
</p>
|
||||
|
||||
<div class="my-3 py-2 px-4 border shadow-sm rounded-md">
|
||||
<div class="hidden my-3 py-2 px-4 border shadow-sm rounded-md">
|
||||
<h4 class="m-0 font-normal">
|
||||
<a class="text-blue-700 font-bold" href="/courses"> CitiBim </a>
|
||||
</h4>
|
||||
@@ -156,7 +156,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="my-2 py-2 px-4 border shadow-sm rounded-md">
|
||||
<div class="hidden my-2 py-2 px-4 border shadow-sm rounded-md">
|
||||
<h4 class="m-0 font-normal">
|
||||
<a class="text-blue-700 font-bold" href="/courses">
|
||||
Climate Change Group
|
||||
|
||||
@@ -3,6 +3,7 @@ import { isUUID } from '../../functions/isUUID';
|
||||
import { QUESTION_TYPE } from '../../../components/Question/constants';
|
||||
|
||||
export async function fetchCourse(courseId, session) {
|
||||
console.log(`courseId`, courseId);
|
||||
let jsonUser;
|
||||
|
||||
if (!process.browser) {
|
||||
|
||||
Reference in New Issue
Block a user