chore: add class to get users from thalos bff

This commit is contained in:
Rodolfo Ruiz
2025-08-30 11:49:33 -06:00
parent 2116e134a9
commit 1f11c47484

35
src/api/userApi.js Normal file
View File

@@ -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;
}
}
}