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

AssignmentManager => Fix getByGitlabLink function

parent b2205111
Branches
No related tags found
No related merge requests found
Pipeline #30661 passed
...@@ -23,15 +23,27 @@ class AssignmentManager { ...@@ -23,15 +23,27 @@ class AssignmentManager {
}) 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);
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment