Skip to content

Instantly share code, notes, and snippets.

Last active Jul 5, 2019
What would you like to do?
type: () => TopicEnrolmentModel,
description: `creates a new enrolment if retries are allowed`
async reEnrol(
@Context ctx: UserSessionModel
) {
const tv = await this.$relatedQuery('currentTopicVersion')
if (tv.allow_retry) {
const enrolment = await this.createEnrolment(ctx.user, tv)
return enrolment
} else {
return null
async selfEnrol(user: UserModel) {
const tv = await this.$relatedQuery('currentTopicVersion')
if (!tv) {
throw new InvalidOperation(`topic ${} is not published`) // no user can self enrol to an unpublished topic
const enrolment = await this.createEnrolment(user, tv)
return enrolment
private async createEnrolment(user: UserModel, topicVersion: TopicVersionModel) {
const enrolment = await this.$relatedQuery<TopicEnrolmentModel>(
topic_version_id: this.production_topic_version_id,
start_date: new Date(),
shared_by: null,
available_points: topicVersion.number_quizzes,
pass_mark: topicVersion.pass_mark,
is_assigned: false
return enrolment
Copy link

edtsech commented Jul 5, 2019

TopicModel or TopicModelAsStudent ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment