PHP Classes

File: frontend/js/componentes/models/reservationModel.js

Recommend this page to a friend!
  Classes of Rodrigo Faustino   Livraria   frontend/js/componentes/models/reservationModel.js   Download  
File: frontend/js/componentes/models/reservationModel.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Livraria
Manage a bookstore using micro-services
Author: By
Last change:
Date: 3 months ago
Size: 2,115 bytes
 

Contents

Class file image Download
import config from '../utils/config.js'; export async function fetchReservations() { try { const response = await fetch(`${config.baseURL}/admin/reservations`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem('token') } }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.message || 'Erro desconhecido'); } return await response.json(); } catch (error) { console.error('Error fetching reservations:', error); throw error; } } export async function updateReservation(id, status) { try { const response = await fetch(`${config.baseURL}/admin/update-status`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem('token') }, body: JSON.stringify({ id, status }) }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.message || 'Erro desconhecido'); } return await response.json(); } catch (error) { console.error('Error updating reservation status:', error); throw error; } } export async function deleteReservation(id) { try { const response = await fetch(`${config.baseURL}/admin/remove-reservation`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem('token') }, body: JSON.stringify({ id }) }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.message || 'Erro desconhecido'); } return await response.json(); } catch (error) { console.error('Error deleting reservation:', error); throw error; } }