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.
Created responses for contacts, events and users. Handled multiple ob…
…jects. b00tc4mp#252
- Loading branch information
Showing
5 changed files
with
92 additions
and
38 deletions.
There are no files selected for viewing
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
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
21 changes: 21 additions & 0 deletions
21
staff/borja-garcia/project/appProjectApi/responses/contactResponse.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,21 @@ | ||
export const contactResponse = (...contacts) => { | ||
// Verifica si se ha pasado más de un usuario (es decir, un arreglo) | ||
if (Array.isArray(contacts[0])) { | ||
// Si es un arreglo, formatea cada usuario | ||
return contacts[0].map((contact) => ({ | ||
contactName: contact.contactName, | ||
phone: contact.phone, | ||
relationship: contact.relationship, | ||
contactId: contact.id | ||
})); | ||
} | ||
|
||
// Si no es un arreglo, formatea solo un usuario | ||
const [contact] = contacts; | ||
return { | ||
contactName: contact.contactName, | ||
phone: contact.phone, | ||
relationship: contact.relationship, | ||
contactId: contact.id | ||
}; | ||
}; |
25 changes: 25 additions & 0 deletions
25
staff/borja-garcia/project/appProjectApi/responses/eventResponse.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,25 @@ | ||
export const eventResponse = (...events) => { | ||
// Verifica si se ha pasado más de un usuario (es decir, un arreglo) | ||
if (Array.isArray(events[0])) { | ||
// Si es un arreglo, formatea cada usuario | ||
return events[0].map((event) => ({ | ||
eventName: event.eventName, | ||
startDateTime: event.startDateTime, | ||
duration: event.duration, | ||
color: event.color, | ||
category: event.category, | ||
eventId: event.id | ||
})); | ||
} | ||
|
||
// Si no es un arreglo, formatea solo un usuario | ||
const [event] = events; | ||
return { | ||
eventName: event.eventName, | ||
startDateTime: event.startDateTime, | ||
duration: event.duration, | ||
color: event.color, | ||
category: event.category, | ||
eventId: event.id | ||
}; | ||
}; |
29 changes: 15 additions & 14 deletions
29
staff/borja-garcia/project/appProjectApi/responses/userResponse.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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
export const userResponse = (...users) => { | ||
// Verifica si se ha pasado más de un usuario (es decir, un arreglo) | ||
if (Array.isArray(users[0])) { | ||
// Si es un arreglo, formatea cada usuario | ||
return users[0].map(user => ({ | ||
email: user.email, | ||
username: user.username, | ||
})); | ||
} | ||
|
||
// Si no es un arreglo, formatea solo un usuario | ||
const [user] = users; | ||
return { | ||
// Verifica si se ha pasado más de un usuario (es decir, un arreglo) | ||
if (Array.isArray(users[0])) { | ||
// Si es un arreglo, formatea cada usuario | ||
return users[0].map((user) => ({ | ||
email: user.email, | ||
username: user.username, | ||
}; | ||
userId: user.id | ||
})); | ||
} | ||
|
||
// Si no es un arreglo, formatea solo un usuario | ||
const [user] = users; | ||
return { | ||
email: user.email, | ||
username: user.username, | ||
userId: user.id | ||
}; | ||
}; |