|
|
@@ -1,6 +1,20 @@
|
|
|
"use strict";
|
|
|
|
|
|
+let appointment;
|
|
|
+const errorParagraph = document.getElementById('appointment-error');
|
|
|
+const successParagraph = document.getElementById('appointment-success');
|
|
|
+
|
|
|
+
|
|
|
window.onload = async function () {
|
|
|
+ document.getElementById("attend-btn").addEventListener("click", async () => {
|
|
|
+ await attendEvent();
|
|
|
+ })
|
|
|
+ const urlParams = new URLSearchParams(window.location.search);
|
|
|
+ appointment = urlParams.get('appointment');
|
|
|
+ if (!appointment) {
|
|
|
+ window.location.replace("/html/404.html");
|
|
|
+ }
|
|
|
+
|
|
|
await getAppointment();
|
|
|
}
|
|
|
|
|
|
@@ -19,12 +33,6 @@ function getTimeSpan(start, end) {
|
|
|
}
|
|
|
|
|
|
async function getAppointment() {
|
|
|
- const urlParams = new URLSearchParams(window.location.search);
|
|
|
- const appointment = urlParams.get('appointment');
|
|
|
- if (!appointment) {
|
|
|
- window.location.replace("/html/404.html");
|
|
|
- }
|
|
|
-
|
|
|
let options = {method: 'GET', headers: {'User-Agent': 'insomnia/10.0.0'}};
|
|
|
|
|
|
const response = await fetch(`/api/schedule?appointmentId=${appointment}`, options)
|
|
|
@@ -65,3 +73,37 @@ function displayAppointmentDetails(appointment) {
|
|
|
// Set place
|
|
|
document.getElementById('place').innerText = appointment.place;
|
|
|
}
|
|
|
+
|
|
|
+async function attendEvent() {
|
|
|
+ const email = document.getElementById('email').value;
|
|
|
+ const firstname = document.getElementById('firstname').value;
|
|
|
+ const lastname = document.getElementById('lastname').value;
|
|
|
+
|
|
|
+ if (!email || !firstname || !lastname) {
|
|
|
+ errorParagraph.innerText = "Fill in all fields.";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const response = await fetch("/api/schedule/create",
|
|
|
+ {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {'Content-Type': 'application/json'},
|
|
|
+ body: JSON.stringify({
|
|
|
+ appointment: appointment,
|
|
|
+ email: email,
|
|
|
+ firstname: firstname,
|
|
|
+ lastname: lastname
|
|
|
+ })
|
|
|
+ });
|
|
|
+ const js = await response.json();
|
|
|
+
|
|
|
+ if (response.status !== 200) {
|
|
|
+ errorParagraph.innerText = js["message"];
|
|
|
+ successParagraph.innerText = "";
|
|
|
+ } else {
|
|
|
+ errorParagraph.innerText = "";
|
|
|
+ successParagraph.innerText = "Registered successfully.";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|