CLASSROOMIO-T-31: Add audience page

Co-authored-by: Rotimi Best <[email protected]>

Merge-request: CLASSROOMIO-MR-6
Merged-by: Digdippa Team <[email protected]>
This commit is contained in:
Rotimi Best
2023-04-23 22:28:18 +00:00
committed by Space Cloud
co-authored by Rotimi Best
parent ae8f9ca222
commit 01a1f0f907
10 changed files with 227 additions and 5 deletions
+40 -1
View File
@@ -1,5 +1,5 @@
import { supabase } from '../../functions/supabase';
import { orgs, currentOrg } from '../../store/org';
import { orgs, currentOrg, orgAudience } from '../../store/org';
export async function getOrganizations(userId) {
const { data, error } = await supabase
@@ -39,3 +39,42 @@ export async function getOrganizations(userId) {
error,
};
}
export async function getOrgAudience(orgId) {
// get all students who are participants in any course belonging to an org
const { data, error } = await supabase
.from('profile')
.select(
`
id,
fullname,
email,
avatar_url,
created_at,
groupmember!inner(
role_id,
group!inner(
organization!inner(id)
)
)
`
)
.eq('groupmember.group.organization.id', orgId)
.eq('groupmember.role_id', 3); // is a student, tutor is 2 and admin is 1
console.log('data', data);
const audience = (data || []).map((profile) => ({
id: profile.id,
name: profile.fullname,
email: profile.email,
avatar_url: profile.avatar_url,
date_joined: new Date(profile.created_at).toDateString(),
}));
orgAudience.set(audience);
return {
audience: audience,
error,
};
}
+1
View File
@@ -7,3 +7,4 @@ export const currentOrg = writable({
shortName: '',
siteName: '',
});
export const orgAudience = writable([]);