diff --git a/ExpressAPI/src/managers/AssignmentManager.ts b/ExpressAPI/src/managers/AssignmentManager.ts index 0f2bc54dcf9c68fb267628d2dc32a1e201bb6284..ff16f6b1b60250b8729ea4a13811c6637654bd62 100644 --- a/ExpressAPI/src/managers/AssignmentManager.ts +++ b/ExpressAPI/src/managers/AssignmentManager.ts @@ -23,15 +23,27 @@ class AssignmentManager { }) as unknown as Assignment ?? undefined; } - getByGitlabLink(gitlabLink: string, include: Prisma.AssignmentInclude | undefined = undefined): Promise<Assignment | undefined> { - const name = gitlabLink.replace('.git', '').split('/').pop()!; - - return this.getByName(name, include); + async getByGitlabLink(gitlabLink: string, include: Prisma.AssignmentInclude | undefined = undefined): Promise<Assignment | undefined> { + const nameInUrl = gitlabLink.replace('.git', '').split('/').pop()!; + + 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 - return this.getByGitlabLink(nameOrUrl, include); + if ( nameOrUrl.includes('://') ) { + return this.getByGitlabLink(nameOrUrl, include); + } else { + return this.getByName(nameOrUrl, include); + } } }