| [09e02d7] | 1 | const API_BASE_URL =
|
|---|
| 2 | import.meta.env.VITE_API_BASE_URL || "http://localhost:8080/api";
|
|---|
| 3 |
|
|---|
| 4 | async function request(path, options = {}) {
|
|---|
| 5 | const response = await fetch(`${API_BASE_URL}${path}`, {
|
|---|
| 6 | headers: {
|
|---|
| 7 | "Content-Type": "application/json",
|
|---|
| 8 | ...(options.headers || {}),
|
|---|
| 9 | },
|
|---|
| 10 | ...options,
|
|---|
| 11 | });
|
|---|
| 12 |
|
|---|
| 13 | if (!response.ok) {
|
|---|
| 14 | let message = `Request failed with status ${response.status}`;
|
|---|
| 15 |
|
|---|
| 16 | try {
|
|---|
| 17 | const data = await response.json();
|
|---|
| 18 | message = data.message || message;
|
|---|
| 19 | } catch {
|
|---|
| 20 | try {
|
|---|
| 21 | const text = await response.text();
|
|---|
| 22 | if (text) {
|
|---|
| 23 | message = text;
|
|---|
| 24 | }
|
|---|
| 25 | } catch {
|
|---|
| 26 | // ignore
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | throw new Error(message);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | if (response.status === 204) {
|
|---|
| 34 | return null;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | return response.json();
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | export function getHealth() {
|
|---|
| 41 | return request("/health");
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | export function getDashboardStats() {
|
|---|
| 45 | return request("/dashboard");
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | export function getUsers() {
|
|---|
| 49 | return request("/users");
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | export function getApprovers() {
|
|---|
| 53 | return request("/approvers");
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | export function getEquipment() {
|
|---|
| 57 | return request("/equipment");
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | export function getRooms() {
|
|---|
| 61 | return request("/rooms");
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | export function searchRooms(payload) {
|
|---|
| 65 | return request("/rooms/search", {
|
|---|
| 66 | method: "POST",
|
|---|
| 67 | body: JSON.stringify(payload),
|
|---|
| 68 | });
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | export function createReservation(payload) {
|
|---|
| 72 | return request("/reservations", {
|
|---|
| 73 | method: "POST",
|
|---|
| 74 | body: JSON.stringify(payload),
|
|---|
| 75 | });
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | export function loginUser(payload) {
|
|---|
| 79 | return request("/auth/login", {
|
|---|
| 80 | method: "POST",
|
|---|
| 81 | body: JSON.stringify(payload),
|
|---|
| 82 | });
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | export function registerUser(payload) {
|
|---|
| 86 | return request("/auth/register", {
|
|---|
| 87 | method: "POST",
|
|---|
| 88 | body: JSON.stringify(payload),
|
|---|
| 89 | });
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | export function getReservation(id) {
|
|---|
| 93 | return request(`/reservations/${id}`);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | export function getPendingReservations() {
|
|---|
| 97 | return request("/reservations/pending");
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | export function approveReservation(payload) {
|
|---|
| 101 | return request("/approvals", {
|
|---|
| 102 | method: "POST",
|
|---|
| 103 | body: JSON.stringify(payload),
|
|---|
| 104 | });
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | export function getRoomUtilizationReport() {
|
|---|
| 108 | return request("/reports/room-utilization");
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | export function getEquipmentDemandReport() {
|
|---|
| 112 | return request("/reports/equipment-demand");
|
|---|
| 113 | } |
|---|