From 47b81928ccf4b12cb63ee6bb3d730bbec10e01eb Mon Sep 17 00:00:00 2001
From: rotimi-best
Date: Tue, 24 Aug 2021 18:20:07 +0300
Subject: [PATCH] Get courses by members data
---
package.json | 4 ++--
src/components/Courses/api.js | 17 +++++++----------
src/components/Navigation/index.svelte | 6 +++---
src/routes/_layout.svelte | 1 -
src/routes/courses.svelte | 13 ++++++-------
src/routes/courses/[id]/index.svelte | 12 +++++++-----
src/routes/courses/[id]/people.svelte | 9 +++++++--
src/routes/profile/[id].svelte | 4 ++--
src/utils/services/courses/index.js | 1 +
9 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/package.json b/package.json
index c4666656..7686a793 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "sapper dev",
"build": "sapper build --legacy",
- "export": "sapper export --legacy --entry \"/ api auth login signup courses dashboard discussions people timetable profile discussions\"",
+ "export": "sapper export --legacy --entry \"/ login signup courses dashboard discussions people timetable profile discussions\"",
"start": "node __sapper__/build"
},
"dependencies": {
@@ -58,4 +58,4 @@
"tslib": "^2.3.1",
"typescript": "^4.1.3"
}
-}
+}
\ No newline at end of file
diff --git a/src/components/Courses/api.js b/src/components/Courses/api.js
index 5dfacca3..8a99c133 100644
--- a/src/components/Courses/api.js
+++ b/src/components/Courses/api.js
@@ -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 };
}
diff --git a/src/components/Navigation/index.svelte b/src/components/Navigation/index.svelte
index 3748f9f4..e4193e2b 100644
--- a/src/components/Navigation/index.svelte
+++ b/src/components/Navigation/index.svelte
@@ -28,7 +28,7 @@
{#if $user.isLoggedIn}
-
+
-
+
-
+
export function preload(page, { config }) {
- console.log(`page`, page);
return { config, isMvpUser: !!page.query.mvp };
}
diff --git a/src/routes/courses.svelte b/src/routes/courses.svelte
index b7e1d16d..16192d54 100644
--- a/src/routes/courses.svelte
+++ b/src/routes/courses.svelte
@@ -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,
};
}
@@ -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);
});
diff --git a/src/routes/courses/[id]/index.svelte b/src/routes/courses/[id]/index.svelte
index a04966f2..20283d7f 100644
--- a/src/routes/courses/[id]/index.svelte
+++ b/src/routes/courses/[id]/index.svelte
@@ -5,21 +5,23 @@
diff --git a/src/routes/courses/[id]/people.svelte b/src/routes/courses/[id]/people.svelte
index 0d42ff5c..49f0e4b3 100644
--- a/src/routes/courses/[id]/people.svelte
+++ b/src/routes/courses/[id]/people.svelte
@@ -75,10 +75,15 @@
- Pending confirmation
+ Pending Invite
{/if}
- {person.email}
+
+ {person.email}
+
{ROLE_LABEL[person.role_id]}
{/each}
diff --git a/src/routes/profile/[id].svelte b/src/routes/profile/[id].svelte
index d74bd07b..bce6a96f 100644
--- a/src/routes/profile/[id].svelte
+++ b/src/routes/profile/[id].svelte
@@ -135,7 +135,7 @@
This are the organizations you work at
-
-