fix: joining course error
This commit is contained in:
@@ -6,7 +6,7 @@ export const getStudentInviteLink = (_course: Course, orgSiteName: string, origi
|
|||||||
const hash = encodeURIComponent(
|
const hash = encodeURIComponent(
|
||||||
btoa(
|
btoa(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
groupId: _course.group?.id,
|
id: _course.id,
|
||||||
name: _course.title,
|
name: _course.title,
|
||||||
description: _course.description,
|
description: _course.description,
|
||||||
orgSiteName
|
orgSiteName
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ export const load = async ({ params = { hash: '' } }) => {
|
|||||||
const courseHashData = atob(decodeURIComponent(params.hash));
|
const courseHashData = atob(decodeURIComponent(params.hash));
|
||||||
console.log('courseHashData', courseHashData);
|
console.log('courseHashData', courseHashData);
|
||||||
|
|
||||||
const { groupId, name, description, orgSiteName } = JSON.parse(courseHashData);
|
const { id, name, description, orgSiteName } = JSON.parse(courseHashData);
|
||||||
|
|
||||||
if (!groupId || !name || !description || !orgSiteName) {
|
if (!id || !name || !description || !orgSiteName) {
|
||||||
throw 'Validation failed';
|
throw 'Validation failed';
|
||||||
}
|
}
|
||||||
const currentOrg = await getCurrentOrg(orgSiteName, true);
|
const currentOrg = await getCurrentOrg(orgSiteName, true);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
groupId,
|
id,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
currentOrg
|
currentOrg
|
||||||
|
|||||||
@@ -34,16 +34,28 @@
|
|||||||
return goto(`/signup?redirect=${$page.url?.pathname || ''}`);
|
return goto(`/signup?redirect=${$page.url?.pathname || ''}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { data: courseData, error } = await supabase
|
||||||
|
.from('course')
|
||||||
|
.select('group_id')
|
||||||
|
.eq('id', data.id)
|
||||||
|
.single();
|
||||||
|
|
||||||
|
console.log({ courseData });
|
||||||
|
if (!courseData?.group_id) {
|
||||||
|
console.error('error getting group', error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const member = {
|
const member = {
|
||||||
profile_id: $profile.id,
|
profile_id: $profile.id,
|
||||||
group_id: data.groupId,
|
group_id: courseData.group_id,
|
||||||
role_id: ROLE.STUDENT
|
role_id: ROLE.STUDENT
|
||||||
};
|
};
|
||||||
|
|
||||||
const teacherMembers = await supabase
|
const teacherMembers = await supabase
|
||||||
.from('groupmember')
|
.from('groupmember')
|
||||||
.select('id, profile(email)')
|
.select('id, profile(email)')
|
||||||
.eq('group_id', data.groupId)
|
.eq('group_id', courseData.group_id)
|
||||||
.eq('role_id', ROLE.TUTOR)
|
.eq('role_id', ROLE.TUTOR)
|
||||||
.returns<
|
.returns<
|
||||||
{
|
{
|
||||||
@@ -62,7 +74,7 @@
|
|||||||
addGroupMember(member).then((addedMember) => {
|
addGroupMember(member).then((addedMember) => {
|
||||||
loading = false;
|
loading = false;
|
||||||
if (addedMember.error) {
|
if (addedMember.error) {
|
||||||
console.error('Error adding student to group', data.groupId, addedMember.error);
|
console.error('Error adding student to group', courseData.group_id, addedMember.error);
|
||||||
snackbar.error('snackbar.invite.failed_join');
|
snackbar.error('snackbar.invite.failed_join');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user