From 0d74662d04d047b7a287d2a4d6b8b72d6ae6c2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <michael@minelli.me> Date: Mon, 28 Aug 2023 20:08:01 +0200 Subject: [PATCH] GitlabManager => Correct get user by id for the new gitlab api specs --- ExpressAPI/src/managers/GitlabManager.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ExpressAPI/src/managers/GitlabManager.ts b/ExpressAPI/src/managers/GitlabManager.ts index 53b6ee3..d5db3a5 100644 --- a/ExpressAPI/src/managers/GitlabManager.ts +++ b/ExpressAPI/src/managers/GitlabManager.ts @@ -18,22 +18,27 @@ class GitlabManager { return `${ Config.gitlab.apiURL }${ route }`; } - private async getGitlabUser(paramToSearch: string | number, paramName: string): Promise<GitlabUser | undefined> { + public async getUserById(id: number): Promise<GitlabUser | undefined> { try { const params: any = {}; - params[paramName] = paramToSearch; - return (await axios.get<Array<GitlabUser>>(this.getApiUrl(GitlabRoute.USERS_GET), { params: params })).data[0]; + const user = (await axios.get<GitlabUser>(`${ this.getApiUrl(GitlabRoute.USERS_GET) }/${ String(id) }`, { params: params })).data; + + return user.id === id ? user : undefined; } catch ( e ) { } return undefined; } - public async getUserById(id: number): Promise<GitlabUser | undefined> { - return await this.getGitlabUser(id, 'id'); - } - public async getUserByUsername(username: string): Promise<GitlabUser | undefined> { - return await this.getGitlabUser(username, 'search'); + try { + const params: any = {}; + params['search'] = username; + const user = (await axios.get<Array<GitlabUser>>(this.getApiUrl(GitlabRoute.USERS_GET), { params: params })).data[0]; + + return user.username === username ? user : undefined; + } catch ( e ) { } + + return undefined; } async getRepository(idOrNamespace: string): Promise<GitlabRepository> { -- GitLab