diff --git a/taskncoffee-app/src/api/users.service.js b/taskncoffee-app/src/api/users.service.js new file mode 100644 index 0000000..f64dfd9 --- /dev/null +++ b/taskncoffee-app/src/api/users.service.js @@ -0,0 +1,44 @@ +import client from './client'; +import { API_ENDPOINTS } from './ApiSources'; + + +/** + * Get all users + * @returns {Promise} All users data + */ +export const getUsers = async () => { + try { + responce = await client.get(API_ENDPOINTS.USERS.LIST); + return responce.data; + } catch (error) { + throw error.response?.data || error.message; + } +}; + +/** + * Get user by id + * @param {number} id - User id + * @returns {Promise} User data + */ +export const getUserById = async (id) => { + try { + const response = await client.get(API_ENDPOINTS.USERS.BY_ID(id)); + return response.data; + } catch (error) { + throw error.response?.data || error.message; + } +}; + +/** + * Get all user tasks + * @param {number} id - User id + * @returns {Promise} All user tasks data + */ +export const getUserTasks = async (id) => { + try { + const response = await client.get(API_ENDPOINTS.USERS.TASKS(id)); + return response.data; + } catch (error) { + throw error.response?.data || error.message; + } +}; \ No newline at end of file