forked from b00tc4mp/isdi-parttime-202406
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added update event/emergency-contact front logic b00tc4mp#252
- Loading branch information
Showing
5 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
27 changes: 27 additions & 0 deletions
27
staff/borja-garcia/project/appProject/src/logic/updateEmergencyContact.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
staff/borja-garcia/project/appProject/src/logic/updateEventById.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.