From 1f11c47484f2e1bf1b0ea5352aa5295fe999f50e Mon Sep 17 00:00:00 2001 From: Rodolfo Ruiz Date: Sat, 30 Aug 2025 11:49:33 -0600 Subject: [PATCH] chore: add class to get users from thalos bff --- src/api/userApi.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/api/userApi.js diff --git a/src/api/userApi.js b/src/api/userApi.js new file mode 100644 index 0000000..ba07e58 --- /dev/null +++ b/src/api/userApi.js @@ -0,0 +1,35 @@ +// src/api/userApi.js +export default class UserApi { + constructor(token) { + this.baseUrl = 'https://thalos-bff.dream-views.com/api/v1/User'; + this.token = token; + } + + // helper for headers + getHeaders() { + return { + 'accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.token}`, + }; + } + + // === GET all users === + async getAllUsers() { + try { + const response = await fetch(`${this.baseUrl}/GetAll`, { + method: 'GET', + headers: this.getHeaders(), + }); + + if (!response.ok) { + throw new Error(`Failed to fetch users: ${response.status}`); + } + + return await response.json(); + } catch (err) { + console.error('Error fetching users:', err); + throw err; + } + } +} \ No newline at end of file