Skip to content
Snippets Groups Projects
Commit 26d51c85 authored by michael.minelli's avatar michael.minelli
Browse files

Merge branch 'resolve-get-assignment-by-url-issue' into v3.6.0

parents 3bac2432 444a89ce
No related branches found
No related tags found
No related merge requests found
Pipeline #30678 passed
...@@ -19,19 +19,33 @@ class AssignmentManager { ...@@ -19,19 +19,33 @@ class AssignmentManager {
return await db.assignment.findUnique({ return await db.assignment.findUnique({
where : { where : {
name: name name: name
}, include: include },
include: include
}) as unknown as Assignment ?? undefined; }) as unknown as Assignment ?? undefined;
} }
getByGitlabLink(gitlabLink: string, include: Prisma.AssignmentInclude | undefined = undefined): Promise<Assignment | undefined> { async getByGitlabLink(gitlabLink: string, include: Prisma.AssignmentInclude | undefined = undefined): Promise<Assignment | undefined> {
const name = gitlabLink.replace('.git', '').split('/').pop()!; const nameInUrl = gitlabLink.replace('.git', '').split('/').pop()!;
return this.getByName(name, include); const result = await db.assignment.findMany({
where : {
gitlabLink: {
endsWith: `/${ nameInUrl }`
}
},
include: include
}) as Array<Assignment>;
return result.length > 0 ? result[0] : undefined;
} }
get(nameOrUrl: string, include: Prisma.AssignmentInclude | undefined = undefined): Promise<Assignment | undefined> { get(nameOrUrl: string, include: Prisma.AssignmentInclude | undefined = undefined): Promise<Assignment | undefined> {
// We can use the same function for both name and url because the name is the last part of the url and the name extraction from the url doesn't corrupt the name if ( nameOrUrl.includes('://') ) {
return this.getByGitlabLink(nameOrUrl, include); return this.getByGitlabLink(nameOrUrl, include);
} else {
return this.getByName(nameOrUrl, include);
}
} }
} }
......
...@@ -15,13 +15,13 @@ class ExerciseManager { ...@@ -15,13 +15,13 @@ class ExerciseManager {
}) as unknown as Exercise ?? undefined; }) as unknown as Exercise ?? undefined;
} }
async getFromAssignment(assignmentName: string, include: Prisma.ExerciseInclude | undefined = undefined): Promise<Array<Exercise> | undefined> { getFromAssignment(assignmentName: string, include: Prisma.ExerciseInclude | undefined = undefined): Promise<Array<Exercise>> {
return await db.exercise.findMany({ return db.exercise.findMany({
where : { where : {
assignmentName: assignmentName assignmentName: assignmentName
}, },
include: include include: include
}) as Array<Exercise> ?? undefined; }) as Promise<Array<Exercise>>;
} }
} }
......
...@@ -88,9 +88,9 @@ class ExerciseRoutes implements RoutesManager { ...@@ -88,9 +88,9 @@ class ExerciseRoutes implements RoutesManager {
} }
private async checkExerciseLimit(assignment: Assignment, members: Array<GitlabUser>): Promise<Array<GitlabUser>> { private async checkExerciseLimit(assignment: Assignment, members: Array<GitlabUser>): Promise<Array<GitlabUser>> {
const exercises: Array<Exercise> | undefined = await ExerciseManager.getFromAssignment(assignment.name, { members: true }); const exercises: Array<Exercise> = await ExerciseManager.getFromAssignment(assignment.name, { members: true });
const reachedLimitUsers: Array<GitlabUser> = []; const reachedLimitUsers: Array<GitlabUser> = [];
if ( exercises ) { if ( exercises.length > 0 ) {
for ( const member of members ) { for ( const member of members ) {
const exerciseCount: number = exercises.filter(exercise => exercise.members.findIndex(exerciseMember => exerciseMember.id === member.id) !== -1).length; const exerciseCount: number = exercises.filter(exercise => exercise.members.findIndex(exerciseMember => exerciseMember.id === member.id) !== -1).length;
if ( exerciseCount >= Config.exercise.maxPerAssignment ) { if ( exerciseCount >= Config.exercise.maxPerAssignment ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment