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:
committed by
Space Cloud
co-authored by
Rotimi Best
parent
ae8f9ca222
commit
01a1f0f907
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,3 +7,4 @@ export const currentOrg = writable({
|
||||
shortName: '',
|
||||
siteName: '',
|
||||
});
|
||||
export const orgAudience = writable([]);
|
||||
|
||||
Reference in New Issue
Block a user