Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update API endpoints to match naming convention #123

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ui/src/lib/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const isSoleOwner = async (uhIdentifier: string, groupingPath: string): P
* @returns True if the uhIdentifier is an owner of a grouping
*/
export const isOwner = async (uhIdentifier: string): Promise<boolean> => {
const endpoint = `${baseUrl}/owners`;
const endpoint = `${baseUrl}/members/${uhIdentifier}/is-owner`;
return getRequest<boolean>(endpoint, uhIdentifier);
};

Expand All @@ -198,6 +198,6 @@ export const isOwner = async (uhIdentifier: string): Promise<boolean> => {
* @returns True if the uhIdentifier is an admin
*/
export const isAdmin = async (uhIdentifier: string): Promise<boolean> => {
const endpoint = `${baseUrl}/admins`;
const endpoint = `${baseUrl}/members/${uhIdentifier}/is-admin`;
return getRequest<boolean>(endpoint, uhIdentifier);
};
8 changes: 4 additions & 4 deletions ui/src/lib/http-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {sendStackTrace} from './actions';
import {getUser} from '@/lib/access/user';
import { sendStackTrace } from './actions';
import { getUser } from '@/lib/access/user';

const baseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string;

Expand Down Expand Up @@ -33,7 +33,7 @@ const delay = async (ms = 5000) => new Promise((res) => setTimeout(res, ms));
*/
const poll = async <T>(jobId: number): Promise<T> => {
const currentUser = await getUser();
return await fetch(`${baseUrl}/jobs/${jobId}`, {headers: {current_user: currentUser.uid}})
return await fetch(`${baseUrl}/jobs/${jobId}`, { headers: { current_user: currentUser.uid } })
.then((res) => handleFetch(res, HTTPMethod.GET))
.then(async (res) => {
if (res.status === Status.COMPLETED) {
Expand All @@ -54,7 +54,7 @@ const poll = async <T>(jobId: number): Promise<T> => {
* @returns The promise of type T
*/
export const getRequest = async <T>(endpoint: string, currentUserKey: string = ''): Promise<T> =>
await fetch(endpoint, {headers: {current_user: currentUserKey}})
await fetch(endpoint, { headers: { current_user: currentUserKey } })
.then((res) => handleFetch(res, HTTPMethod.GET))
.catch((err) => err);

Expand Down
8 changes: 4 additions & 4 deletions ui/tests/lib/fetchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ describe('fetchers', () => {
describe('isOwner', () => {
it('should make a GET request at the correct endpoint', async () => {
await isOwner(uhIdentifier);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/owners`, {
headers: { current_user: currentUser.uid }
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/${uhIdentifier}/is-owner`, {
headers: { current_user: uhIdentifier }
});
});

Expand All @@ -333,8 +333,8 @@ describe('fetchers', () => {
describe('isAdmin', () => {
it('should make a GET request at the correct endpoint', async () => {
await isAdmin(uhIdentifier);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/admins`, {
headers: { current_user: currentUser.uid }
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/${uhIdentifier}/is-admin`, {
headers: { current_user: uhIdentifier }
});
});

Expand Down