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 front logic (create, delete and getByUser events/contacts b00tc…
- Loading branch information
Showing
13 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
27 changes: 27 additions & 0 deletions
27
staff/borja-garcia/project/appProject/src/logic/createEmergencyContact.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 createEmergencyContact = async (contactName, phone, relationship, userId) => { | ||
try { | ||
const response = await fetch(`/api/emergency-contacts/users/${userId}`, { | ||
method: "POST", | ||
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 createEmergencyContact; |
27 changes: 27 additions & 0 deletions
27
staff/borja-garcia/project/appProject/src/logic/createEvent.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 createEvent = async (eventName, startDateTime, duration, color, userId) => { | ||
try { | ||
const response = await fetch(`/api/events/users/${userId}}`, { | ||
method: "POST", | ||
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 createEvent; |
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions
26
staff/borja-garcia/project/appProject/src/logic/deleteEmergencyContact.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,26 @@ | ||
import * as Errors from "../../errors"; | ||
|
||
const deleteEmergencyContactById = async (contactId) => { | ||
try { | ||
const response = await fetch(`/api/emergency-contacts/${contactId}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-type": "application/json", | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
throw new Errors.ServerError(errorData.error || "Error al crear el usuario"); | ||
} | ||
|
||
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 deleteEmergencyContactById; |
26 changes: 26 additions & 0 deletions
26
staff/borja-garcia/project/appProject/src/logic/deleteEvent.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,26 @@ | ||
import * as Errors from "../../errors"; | ||
|
||
const deleteEventById = async (eventId) => { | ||
try { | ||
const response = await fetch(`/api/events/${eventId}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-type": "application/json", | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
throw new Errors.ServerError(errorData.error || "Error al crear el usuario"); | ||
} | ||
|
||
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 deleteEventById; |
Empty file.
18 changes: 18 additions & 0 deletions
18
staff/borja-garcia/project/appProject/src/logic/getEmergencyContactsByUser.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,18 @@ | ||
import * as Errors from "../../errors"; | ||
|
||
const getEmerContByUser = async (userId) => { | ||
try { | ||
const response = await fetch(`/api/emergency-contacts/user/${userId}`); | ||
if (!response.ok) { | ||
throw new Errors.ApiError("Error fetching emergency contacts", response.status); | ||
} | ||
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 getEmerContByUser; |
18 changes: 18 additions & 0 deletions
18
staff/borja-garcia/project/appProject/src/logic/getEventsByUser.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,18 @@ | ||
import * as Errors from "../../errors"; | ||
|
||
const getEventsByUser = async (userId) => { | ||
try { | ||
const response = await fetch(`/api/events/user/${userId}`); | ||
if (!response.ok) { | ||
throw new Errors.ApiError("Error fetching events", response.status); | ||
} | ||
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 getEventsByUser; |
Empty file.
Empty file.
Empty file.