Skip to content

Commit

Permalink
added update event/emergency-contact front logic b00tc4mp#252
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmePo committed Jan 4, 2025
1 parent 1321a15 commit d990a90
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as Errors from "../../errors";

const updateEmergencyContact = async (contactName, phone, relationship, contactId) => {
try {
const response = await fetch(`/api/emergency-contacts/${contactId}`, {
method: "PUT",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify({ contactName, phone, relationship }),
});

if (!response.ok) {
const errorData = await response.json();
throw new Errors.ApiError(errorData.message);
}

return await response.json(); // Devuelve la respuesta JSON si fue exitosa
} catch (err) {
if (err instanceof TypeError) {
throw new Errors.ServerError("Server is not connected");
}
throw new Errors.UnexpectedError(err.message || "Unexpected error occurred");
}
};

export default updateEmergencyContact;
27 changes: 27 additions & 0 deletions staff/borja-garcia/project/appProject/src/logic/updateEventById.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as Errors from "../../errors";

const updateEventById = async (eventName, startDateTime, duration, color, eventId) => {
try {
const response = await fetch(`/api/events/${eventId}}`, {
method: "PUT",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify({ eventName, startDateTime, duration, color }),
});

if (!response.ok) {
const errorData = await response.json();
throw new Errors.ApiError(errorData.message);
}

return await response.json(); // Devuelve la respuesta JSON si fue exitosa
} catch (err) {
if (err instanceof TypeError) {
throw new Errors.ServerError("Server is not connected");
}
throw new Errors.UnexpectedError(err.message || "Unexpected error occurred");
}
};

export default updateEventById;
Empty file.

0 comments on commit d990a90

Please sign in to comment.