|
|
@@ -1,4 +1,4 @@
|
|
|
-import { fetchWithToken } from "./utils.js";
|
|
|
+import {fetchWithToken, getTimeSpan, parseOrRedirect} from "./utils.js";
|
|
|
"use strict";
|
|
|
|
|
|
window.addEventListener("load", async function () {
|
|
|
@@ -59,24 +59,13 @@ function displayAppointmentDetails(appointmentData) {
|
|
|
appointmentInfo.appendChild(timeSpan);
|
|
|
}
|
|
|
|
|
|
-// Helper function to format the time span
|
|
|
-function getTimeSpan(startDate, endDate) {
|
|
|
- const start = new Date(startDate).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
|
- const end = new Date(endDate).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
|
- return `${start} to ${end}`;
|
|
|
-}
|
|
|
-
|
|
|
async function getAppointment(appointment) {
|
|
|
const options = {method: 'GET', headers: {'User-Agent': 'insomnia/10.0.0'}};
|
|
|
|
|
|
const response = await fetch(`/api/schedule?isUser=true&appointmentId=${appointment}`, options)
|
|
|
.catch(err => console.error('error:' + err));
|
|
|
|
|
|
- if (response.status === 404) {
|
|
|
- window.location.replace("/html/404.html");
|
|
|
- }
|
|
|
-
|
|
|
- const js = await response.json();
|
|
|
+ const js = await parseOrRedirect(response);
|
|
|
displayAppointmentDetails(js);
|
|
|
}
|
|
|
|
|
|
@@ -112,14 +101,6 @@ function renderBookings(data) {
|
|
|
|
|
|
async function fetchBookings(appointmentId) {
|
|
|
const response = await fetchWithToken(`/api/users/bookings?appointmentId=${appointmentId}`);
|
|
|
- if (response.status === 401) {
|
|
|
- window.location.replace("/html/auth.html");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const js = await response.json();
|
|
|
- if (!response.ok) {
|
|
|
- window.location.replace("/html/404.html");
|
|
|
- }
|
|
|
+ const js = await parseOrRedirect(response);
|
|
|
renderBookings(js);
|
|
|
}
|