-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
453 additions
and
101 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { type AxiosResponse, AxiosError } from 'axios' | ||
import request from '../apiClient' | ||
|
||
const API_NAME = 'Blueprint Backend API' | ||
const BASE = '/team/' | ||
|
||
export const getAllTeams = async (): Promise<AxiosResponse> => { | ||
try { | ||
const response = await request('GET', BASE + 'all') | ||
return response | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
console.error(`${API_NAME} Error: ${error.message}`, error.response?.data) | ||
throw new Error(`${API_NAME} Error: ${error.response?.status} ${error.response?.data?.error}`) | ||
} | ||
throw new Error('Unknown Error') | ||
} | ||
} | ||
|
||
export const getTeam = async (teamId: string): Promise<AxiosResponse> => { | ||
try { | ||
const response = await request('GET', BASE + `user?userId=${teamId}`) | ||
return response | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
console.error( | ||
`${API_NAME} Error: ${error.message}`, | ||
error.response?.data | ||
) | ||
throw new Error( | ||
`${API_NAME} Error: ${error.response?.status} ${error.response?.data?.error}` | ||
) | ||
} | ||
throw new Error('Unknown Error') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,96 @@ | ||
import { type AxiosResponse } from 'axios' | ||
import { type AxiosResponse, AxiosError } from 'axios' | ||
import request from '../apiClient' | ||
import type { User } from '../../types/index' | ||
|
||
const API_NAME = 'Blueprint Backend API' | ||
const BASE = '/user/' | ||
|
||
export const getAllUsers = async (): Promise<AxiosResponse> => { | ||
return await request('GET', '/v1/users/all') | ||
try { | ||
const response = await request('GET', BASE + 'all') | ||
return response | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
console.error( | ||
`${API_NAME} Error: ${error.message}`, | ||
error.response?.data | ||
) | ||
throw new Error( | ||
`${API_NAME} Error: ${error.response?.status} ${error.response?.data?.error}` | ||
) | ||
} | ||
throw new Error('Unknown Error') | ||
} | ||
} | ||
|
||
export const getUser = async (username: string): Promise<AxiosResponse> => { | ||
return await request('GET', `/v1/users/user?username=${username}`) | ||
export const getUser = async (userId: string): Promise<AxiosResponse> => { | ||
try { | ||
const response = await request('GET', BASE + `user?userId=${userId}`) | ||
return response | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
console.error( | ||
`${API_NAME} Error: ${error.message}`, | ||
error.response?.data | ||
) | ||
throw new Error( | ||
`${API_NAME} Error: ${error.response?.status} ${error.response?.data?.error}` | ||
) | ||
} | ||
throw new Error('Unknown Error') | ||
} | ||
} | ||
|
||
export const addUser = async (user: User): Promise<AxiosResponse> => { | ||
return await request('POST', '/v1/users/user', JSON.stringify(user)) | ||
} | ||
|
||
export const updateUser = async (username: string, user: User): Promise<AxiosResponse> => { | ||
return await request('PUT', `/v1/users/user?username=${username}`, JSON.stringify(user)) | ||
try { | ||
const response = await request('POST', BASE + 'user', JSON.stringify(user)) | ||
return response | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
console.error( | ||
`${API_NAME} Error: ${error.message}`, | ||
error.response?.data | ||
) | ||
throw new Error( | ||
`${API_NAME} Error: ${error.response?.status} ${error.response?.data?.error}` | ||
) | ||
} | ||
throw new Error('Unknown Error') | ||
} | ||
} | ||
|
||
export const deleteUser = async (username: string): Promise<AxiosResponse> => { | ||
return await request('DELETE', `/v1/users/user?username=${username}`) | ||
export const updateUser = async (user: User): Promise<AxiosResponse> => { | ||
try { | ||
const response = await request('PUT', BASE + 'user', JSON.stringify(user)) | ||
return response | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
console.error( | ||
`${API_NAME} Error: ${error.message}`, | ||
error.response?.data | ||
) | ||
throw new Error( | ||
`${API_NAME} Error: ${error.response?.status} ${error.response?.data?.error}` | ||
) | ||
} | ||
throw new Error('Unknown Error') | ||
} | ||
} | ||
|
||
export const getMemberSizeWeeklyChange = async (): Promise<AxiosResponse> => { | ||
return await request('GET', '/v1/users/member-size-weekly-change') | ||
export const deleteUser = async (userId: string): Promise<AxiosResponse> => { | ||
try { | ||
const response = await request('DELETE', BASE + `userId?=${userId}`) | ||
return response | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
console.error( | ||
`${API_NAME} Error: ${error.message}`, | ||
error.response?.data | ||
) | ||
throw new Error( | ||
`${API_NAME} Error: ${error.response?.status} ${error.response?.data?.error}` | ||
) | ||
} | ||
throw new Error('Unknown Error') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.