Skip to content

Commit a8d9e89

Browse files
authored
Merge pull request #52 from MEITREX/fopro-uml-assessment
Fopro uml assessment
2 parents c3cb40a + ce96ab0 commit a8d9e89

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

additionalResolvers/content.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,66 @@ const resolvers: Resolvers = {
353353
`,
354354
});
355355

356+
return content;
357+
}
358+
},
359+
createUMLAssessment: {
360+
async resolve(root, _args, context, info) {
361+
// find out in which course the chapter this assessment should be created in is
362+
let chapters = await context.CourseService.Query._internal_noauth_chaptersByIds({
363+
root,
364+
args: {
365+
ids: [_args.assessmentInput.metadata.chapterId]
366+
},
367+
selectionSet: `
368+
{
369+
course {
370+
id
371+
}
372+
}
373+
`,
374+
});
375+
376+
if (chapters.length !== 1) {
377+
throw new Error("Chapter with given id does not exist.");
378+
}
379+
380+
let courseId = chapters[0].course.id;
381+
382+
// check that the user is an admin in the course the assessment should be created in
383+
if (!context.currentUser.courseMemberships.some((membership) => {
384+
return membership.courseId === courseId && membership.role === "ADMINISTRATOR";
385+
})) {
386+
throw new Error("User is not enrolled and/or an admin in the course the assessment should be created in.");
387+
}
388+
389+
// create the assessment
390+
let content = await context.ContentService.Mutation._internal_createAssessment({
391+
root,
392+
args: {
393+
courseId: courseId,
394+
input: _args.assessmentInput
395+
},
396+
context,
397+
info
398+
});
399+
400+
await context.AssignmentService.Mutation._internal_noauth_createUmlExercise({
401+
root,
402+
args: {
403+
courseId: courseId,
404+
assessmentId: content.id,
405+
input: _args.createUmlExerciseInput
406+
},
407+
// we need to define a selection set manually here, otherwise it thinks we don't need any data
408+
// from this mutation and it won't actually be executed
409+
selectionSet: `
410+
{
411+
assessmentId
412+
}
413+
`,
414+
});
415+
356416
return content;
357417
}
358418
},

additionalResolvers/lib.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum AssessmentItemType {
66
QuizAssessment = "QuizAssessment",
77
FlashcardAssessment = "FlashcardAssessment",
88
SubmissionAssessment = "SubmissionAssessment",
9+
UmlAssessment = "UmlAssessment",
910
}
1011

1112
class Logger {
@@ -38,13 +39,19 @@ type SubmissionAssessmentMutation = {
3839
assessmentType: AssessmentItemType.SubmissionAssessment;
3940
type: null
4041
};
42+
type UmlAssessmentMutation = {
43+
assessmentType: AssessmentItemType.UmlAssessment;
44+
type: null
45+
};
4146

4247
type AssessmentMutationHandlerArgs<T extends AssessmentItemType> = (T extends AssessmentItemType.FlashcardAssessment
4348
? FlashcardAssessmentMutation
4449
: T extends AssessmentItemType.QuizAssessment
4550
? QuizAssessmentMutation
4651
: T extends AssessmentItemType.SubmissionAssessment
4752
? SubmissionAssessmentMutation
53+
: T extends AssessmentItemType.UmlAssessment
54+
? UmlAssessmentMutation
4855
: never) & {
4956
mutationName: string;
5057
callback: CallbackAfterAssessmentMutation<T>;
@@ -136,6 +143,9 @@ export const handleAssessmentMutationThenCallback = async <T extends AssessmentI
136143
case AssessmentItemType.SubmissionAssessment:
137144
inputType = "submissionInput";
138145
break;
146+
case AssessmentItemType.UmlAssessment:
147+
inputType = "umlInput";
148+
break;
139149
default:
140150
throw new Error(`Unsupported assessment type: ${assessmentType}`);
141151
}
@@ -188,6 +198,9 @@ const fetchAssessmentFromContentService = async (assessmentType, root, context,
188198
case AssessmentItemType.SubmissionAssessment:
189199
assessmentMutationString = "SubmissionAssessment";
190200
break;
201+
case AssessmentItemType.UmlAssessment:
202+
assessmentMutationString = "UmlAssessment";
203+
break;
191204
default:
192205
throw new Error(`Unsupported assessment type: ${assessmentType}`);
193206
}

additionalTypeDefs/content.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,9 @@ extend type Mutation {
289289
"""
290290
createAssignmentAssessment(assessmentInput: CreateAssessmentInput!, assignmentInput: CreateAssignmentInput!): AssignmentAssessment! # resolved in content.ts
291291

292+
"""
293+
Creates a new UML Assessment and the corresponding UML Exercise.
294+
"""
295+
createUMLAssessment(assessmentInput: CreateAssessmentInput!, createUmlExerciseInput: CreateUmlExerciseInput!): Assessment! # resolved in content.ts
296+
292297
}

0 commit comments

Comments
 (0)