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

AssignmentManager => Fix getByUrl function

parent 3bac2432
No related branches found
No related tags found
No related merge requests found
Pipeline #30660 passed
......@@ -19,19 +19,33 @@ class AssignmentManager {
return await db.assignment.findUnique({
where : {
name: name
}, include: include
},
include: include
}) as unknown as Assignment ?? undefined;
}
getByGitlabLink(gitlabLink: string, include: Prisma.AssignmentInclude | undefined = undefined): Promise<Assignment | undefined> {
const name = gitlabLink.replace('.git', '').split('/').pop()!;
async getByGitlabLink(gitlabLink: string, include: Prisma.AssignmentInclude | undefined = undefined): Promise<Assignment | undefined> {
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> {
// 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);
} else {
return this.getByName(nameOrUrl, include);
}
}
}
......
......@@ -15,13 +15,13 @@ class ExerciseManager {
}) as unknown as Exercise ?? undefined;
}
async getFromAssignment(assignmentName: string, include: Prisma.ExerciseInclude | undefined = undefined): Promise<Array<Exercise> | undefined> {
return await db.exercise.findMany({
getFromAssignment(assignmentName: string, include: Prisma.ExerciseInclude | undefined = undefined): Promise<Array<Exercise>> {
return db.exercise.findMany({
where : {
assignmentName: assignmentName
},
include: include
}) as Array<Exercise> ?? undefined;
}) as Promise<Array<Exercise>>;
}
}
......
......@@ -88,9 +88,9 @@ class ExerciseRoutes implements RoutesManager {
}
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> = [];
if ( exercises ) {
if ( exercises.length > 0 ) {
for ( const member of members ) {
const exerciseCount: number = exercises.filter(exercise => exercise.members.findIndex(exerciseMember => exerciseMember.id === member.id) !== -1).length;
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