|
|
@@ -29,6 +29,7 @@ window.addEventListener("load", async function() {
|
|
|
} else {
|
|
|
// modify appointment
|
|
|
// TODO Add a modify appointment function
|
|
|
+ await editAppointment(appointment);
|
|
|
}
|
|
|
})
|
|
|
});
|
|
|
@@ -45,14 +46,14 @@ async function displayAppointment(data) {
|
|
|
async function loadAppointment(appointment) {
|
|
|
let options = {method: 'GET', headers: {'User-Agent': 'insomnia/10.0.0'}};
|
|
|
|
|
|
- const response = await fetch(`/api/schedule?appointmentId=${appointment}`, options)
|
|
|
+ const response = await fetch(`/api/schedule?appointmentId=${appointment}&isUser=true`, options)
|
|
|
.catch(err => console.error('error:' + err));
|
|
|
|
|
|
const js = await parseOrRedirect(response);
|
|
|
await displayAppointment(js);
|
|
|
}
|
|
|
|
|
|
-async function createAppointment() {
|
|
|
+function getParameters() {
|
|
|
const title = titleInput.value;
|
|
|
const description = descriptionInput.value;
|
|
|
const dueDate = dueDateInput.value;
|
|
|
@@ -60,13 +61,28 @@ async function createAppointment() {
|
|
|
const endDate = endDateInput.value;
|
|
|
const place = placeInput.value;
|
|
|
|
|
|
+ return {title, description, dueDate, startDate, endDate, place};
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function editAppointment(appointment) {
|
|
|
+ await setAppointment("modify", appointment);
|
|
|
+}
|
|
|
+
|
|
|
+async function createAppointment() {
|
|
|
+ await setAppointment("create", "");
|
|
|
+}
|
|
|
+
|
|
|
+async function setAppointment(endpoint, appointment) {
|
|
|
+ const { title, description, dueDate, startDate, endDate, place } = getParameters();
|
|
|
+
|
|
|
if (!title || !description || !dueDate || !startDate || !endDate) {
|
|
|
appointmentSuccessParagraph.innerText = "";
|
|
|
appointmentErrorParagraph.innerText = "Not fields filled";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const response = await fetchWithToken('/api/users/create', {
|
|
|
+ const response = await fetchWithToken(`/api/users/${endpoint}`, {
|
|
|
method: 'POST',
|
|
|
body: JSON.stringify({
|
|
|
title: title,
|
|
|
@@ -74,7 +90,8 @@ async function createAppointment() {
|
|
|
dueDate: dueDate,
|
|
|
startDate: startDate,
|
|
|
endDate: endDate,
|
|
|
- place: place
|
|
|
+ place: place,
|
|
|
+ appointmentId: appointment
|
|
|
})
|
|
|
});
|
|
|
const js = await response.json();
|
|
|
@@ -87,6 +104,10 @@ async function createAppointment() {
|
|
|
appointmentErrorParagraph.innerText = "";
|
|
|
appointmentSuccessParagraph.innerText = "Appointment created successfully. The share link " +
|
|
|
"was copied to your clipboard";
|
|
|
+ if (endpoint === "modify") {
|
|
|
+ appointmentSuccessParagraph.innerText = "Appointment edited successfully. The share link " +
|
|
|
+ "was copied to your clipboard";
|
|
|
+ }
|
|
|
await navigator.clipboard.writeText(`${window.location.origin}${path}`);
|
|
|
}
|
|
|
}
|