Skip to content

Commit

Permalink
feat: subcourse meeting join
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasFalkowsky committed Jan 19, 2024
1 parent 3f506bb commit b3cfa90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions common/notification/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ const _notificationActions = {
student_joined_subcourse_meeting: {
description: 'Student joined subcourse meeting',
sampleContext: {
subcourseId: '1',
relation: 'subcourse/1',
subcourseLecturesCount: '5',
},
},
pupil_joined_match_meeting: {
Expand All @@ -682,7 +683,8 @@ const _notificationActions = {
pupil_joined_subcourse_meeting: {
description: 'Pupil joined subcourse meeting',
sampleContext: {
subcourseId: '1',
relation: 'subcourse/1',
subcourseLecturesCount: '5',
},
},
TEST: {
Expand Down
24 changes: 24 additions & 0 deletions graphql/achievement/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,28 @@ export class MutateAchievementResolver {

return true;
}

@Mutation((returns) => Boolean)
@AuthorizedDeferred(Role.ADMIN, Role.OWNER)
async subcourseMeetingJoin(@Ctx() context: GraphQLContext, @Arg('matchId') subcourseId: number) {
const { user } = context;
const subcourse = await prisma.subcourse.findUnique({ where: { id: subcourseId }, include: { course: true, lecture: true } });
await hasAccess(context, 'Subcourse', subcourse);

if (user.studentId) {
const lecturesCount = subcourse.lecture.reduce((acc, lecture) => acc + (lecture.isCanceled ? 0 : 1), 0);
await Notification.actionTaken(user, 'student_joined_subcourse_meeting', {
relation: `subcourse/${subcourseId}`,
subcourseLecturesCount: lecturesCount.toString(),
});
} else if (user.pupilId) {
const lecturesCount = subcourse.lecture.reduce((acc, lecture) => acc + (lecture.declinedBy.includes(user.userID) ? 0 : 1), 0);
await Notification.actionTaken(user, 'pupil_joined_subcourse_meeting', {
relation: `subcourse/${subcourseId}`,
subcourseLecturesCount: lecturesCount.toString(),
});
}

return true;
}
}

0 comments on commit b3cfa90

Please sign in to comment.