chore: add class to get users from thalos bff
This commit is contained in:
		
							
								
								
									
										35
									
								
								src/api/userApi.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/api/userApi.js
									
									
									
									
									
										Normal 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; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 Rodolfo Ruiz
					Rodolfo Ruiz