Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: offer course template #951

Merged
merged 9 commits into from
Jan 23, 2024

Conversation

LucasFalkowsky
Copy link
Contributor

@LucasFalkowsky LucasFalkowsky commented Jan 16, 2024

What was done:

  • new metrics for offer course achievement
  • new templates for offer course achievement
  • connections to mutations

@realmayus realmayus temporarily deployed to backend-feat-offer-cour-wa8xqa January 16, 2024 08:26 Inactive
@LomyW LomyW assigned LomyW and LucasFalkowsky and unassigned LomyW Jan 16, 2024
@realmayus realmayus temporarily deployed to backend-feat-offer-cour-wa8xqa January 16, 2024 08:34 Inactive
@realmayus realmayus temporarily deployed to backend-feat-offer-cour-wa8xqa January 16, 2024 09:11 Inactive
@realmayus realmayus temporarily deployed to backend-feat-offer-cour-wa8xqa January 16, 2024 09:31 Inactive
@realmayus realmayus temporarily deployed to backend-feat-offer-cour-wa8xqa January 16, 2024 13:30 Inactive
@LucasFalkowsky LucasFalkowsky requested a review from LomyW January 17, 2024 15:10
graphql/subcourse/mutations.ts Outdated Show resolved Hide resolved
await createAchievement(awardedAchievement.template, userAchievement.userId, event.context);
const newAchievement = await createAchievement(awardedAchievement.template, userAchievement.userId, event.context);
if (newAchievement) {
await checkUserAchievement(newAchievement, event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has great potential for an endless loop 😅
How did you notice that we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we create a new achievement we want to directly evaluate if it was already achieved, so we could generate the subsequent achievement.

This could only loop if we had endless acheivements in a group, which is not the case. the createAchievement function only works, if there are subsequent achievements in our currently checked achievement group.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But can't the context change between these achievements? Every metric has it's own set of actions, which has it's own context.
This means that event A coming from action A will have a different context then event B coming from action B.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a point here. We included a check for a sequential achievement being the last in the group to determine, whether to directly set its achievedAt value to the current Date or not.

common/achievement/util.ts Show resolved Hide resolved
return null;
}
const transformedJson: AchievementContextType = {
user: user,
match: json['match'] ? json['match'] : undefined,
subcourse: json['subcourse'] ? json['subcourse'] : undefined,
};
keys.forEach((key) => {
if (key !== 'match' && key !== 'subcourse') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just copy all the keys and remove line 103 + 104? They are basically doing the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would then require us to change the AchievementContextType. I set match and subcourse to optional values.

@@ -76,6 +77,15 @@ export async function allowCourse(course: Course, screeningComment: string | nul
await publishSubcourse(subcourse);
}
}

const subcourse = await prisma.subcourse.findFirst({ where: { courseId: course.id } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use the subcourses from line 74?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I destructured the first element from the subcourses array.

graphql/course/mutations.ts Outdated Show resolved Hide resolved
const subcourse = await prisma.subcourse.findFirst({ where: { courseId: courseId } });
const instructors = await prisma.subcourse_instructors_student.findMany({ where: { subcourseId: subcourse.id }, select: { student: true } });
const { context: contextData } = await prisma.user_achievement.findFirst({
where: { group: 'student_offer_course', context: { path: ['relation'], equals: `subcourse/${subcourse.id}` } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the group here? Maybe it's enough to filter by relation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This group selector is necessary. If we were not filtering for the specific group, every achievement that had subcourse/{{id}} as a relation would be added a courseName, even if it had no use for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An other issue could be that the wrong contextData was fetched and data will be saved to the other achievement of an other group, missing essential information, previously existent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This group selector is necessary. If we were not filtering for the specific group, every achievement that had subcourse/{{id}} as a relation would be added a courseName, even if it had no use for it.

The downside of referencing specific groups is that it might break completely over time if someone decides to rename the group. I guess having extra unnecessary data in the context doesn't hurt.

An other issue could be that the wrong contextData was fetched and data will be saved to the other achievement of an other group, missing essential information, previously existent.

This could be solved by iterating over the achievements instead of updateMany

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, we should try to not hardcode information that will be set dynamically in the database. The groups are used for grouping and not identification right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright I fixed this part and removed the group from the filters.

graphql/course/mutations.ts Outdated Show resolved Hide resolved
graphql/course/mutations.ts Outdated Show resolved Hide resolved
where: { group: 'student_offer_course', context: { path: ['relation'], equals: `subcourse/${subcourse.id}` } },
});
contextData['courseName'] = result.name;
await prisma.user_achievement.updateMany({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that all the user achievements will have the same context? Maybe we should iterate of the list and update each individually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we are sure, because we selected the achievements of the same group. Achievements of the same group always share the same context.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we are sure, because we selected the achievements of the same group. Achievements of the same group always share the same context.

🤔 is this actually true? I thought that the achievement will get the context of the event, which might be different. I think I'm missing something. Can you please elaborate more on where/how this is happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did update this part, because I think you have a point here and I then was not satisfied the way I initially built it.
I'd appreciate you having another look at it.

@realmayus realmayus temporarily deployed to backend-feat-offer-cour-wa8xqa January 19, 2024 10:27 Inactive
@realmayus realmayus temporarily deployed to backend-feat-offer-cour-wa8xqa January 22, 2024 08:15 Inactive
Comment on lines +117 to +118
match?: ContextMatch[];
subcourse?: ContextSubcourse[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these optional now? 🤔

@realmayus realmayus temporarily deployed to backend-feat-offer-cour-wa8xqa January 23, 2024 08:25 Inactive
@LucasFalkowsky LucasFalkowsky merged commit 41392ec into feat/achievements Jan 23, 2024
1 of 2 checks passed
@LucasFalkowsky LucasFalkowsky deleted the feat/offer-course-template branch January 23, 2024 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants