a
This commit is contained in:
parent
6e539efb99
commit
631cded9b6
@ -1,63 +1,76 @@
|
||||
'use strict';
|
||||
const cdnHelper = require('./cdn.helper');
|
||||
|
||||
const valuesComposer = (values) => values.map(value => ({
|
||||
id: value.id,
|
||||
name: value.name,
|
||||
}));
|
||||
const valuesComposer = (values) => (values) ? values.map(value => ({id: value.id, name: value.name,})): values;
|
||||
|
||||
const commentsComposer = (comments) => comments.map(comment => ({
|
||||
...comment,
|
||||
userId: undefined,
|
||||
user: {
|
||||
...comment.user,
|
||||
profile_picture: cdnHelper.getCDNMediaUrl(comment.user.profile_picture)
|
||||
|
||||
const commentsComposer = (comments) => {
|
||||
if (comments) {
|
||||
return comments.map(comment => ({
|
||||
...comment,
|
||||
userId: undefined,
|
||||
user: {
|
||||
...comment.user,
|
||||
profile_picture: cdnHelper.getCDNMediaUrl(comment.user.profile_picture)
|
||||
}
|
||||
}));
|
||||
}
|
||||
}))
|
||||
else return comments;
|
||||
};
|
||||
|
||||
|
||||
const multimediaComposer = (multimedias) => multimedias.map(multimedia => ({
|
||||
...multimedia,
|
||||
...multimedia.multimediaFile,
|
||||
type: multimedia.type,
|
||||
media_type: multimedia.multimediaFile.type,
|
||||
multimediaFile: undefined,
|
||||
createdAt: undefined,
|
||||
updatedAt: undefined,
|
||||
userId: undefined,
|
||||
url: (multimedia.multimediaFile.provider === 'cdn') ? cdnHelper.getCDNMediaUrl(multimedia.multimediaFile.url) : multimedia.multimediaFile.url,
|
||||
}));
|
||||
const multimediaComposer = (multimedias) => {
|
||||
if(multimedias) {
|
||||
return multimedias.map(multimedia => ({
|
||||
...multimedia,
|
||||
...multimedia.multimediaFile,
|
||||
type: multimedia.type,
|
||||
media_type: multimedia.multimediaFile.type,
|
||||
multimediaFile: undefined,
|
||||
createdAt: undefined,
|
||||
updatedAt: undefined,
|
||||
userId: undefined,
|
||||
url: (multimedia.multimediaFile.provider === 'cdn') ? cdnHelper.getCDNMediaUrl(multimedia.multimediaFile.url) : multimedia.multimediaFile.url,
|
||||
}));
|
||||
}
|
||||
else
|
||||
return multimedias;
|
||||
};
|
||||
|
||||
|
||||
const socialNetworksComposer = (speaker, context) => {
|
||||
return {
|
||||
rrss: {
|
||||
twitter: speaker.twitter ? speaker.twitter : null,
|
||||
facebook: speaker.facebook ? speaker.facebook : null,
|
||||
youtube: speaker.youtube ? speaker.youtube : null,
|
||||
linkedin: speaker.linkedin ? speaker.linkedin : null,
|
||||
instagram: speaker.instagram ? speaker.instagram : null,
|
||||
web: speaker.web ? speaker.web : null
|
||||
},
|
||||
twitter: undefined,
|
||||
facebook: undefined,
|
||||
youtube: undefined,
|
||||
linkedin: undefined,
|
||||
instagram: undefined,
|
||||
web: undefined
|
||||
};
|
||||
const socialNetworksComposer = (speaker) => {
|
||||
if (speaker) {
|
||||
return {
|
||||
rrss: {
|
||||
twitter: speaker.twitter ? speaker.twitter : null,
|
||||
facebook: speaker.facebook ? speaker.facebook : null,
|
||||
youtube: speaker.youtube ? speaker.youtube : null,
|
||||
linkedin: speaker.linkedin ? speaker.linkedin : null,
|
||||
instagram: speaker.instagram ? speaker.instagram : null,
|
||||
web: speaker.web ? speaker.web : null
|
||||
},
|
||||
twitter: undefined,
|
||||
facebook: undefined,
|
||||
youtube: undefined,
|
||||
linkedin: undefined,
|
||||
instagram: undefined,
|
||||
web: undefined
|
||||
};
|
||||
}
|
||||
else
|
||||
return speaker;
|
||||
};
|
||||
|
||||
|
||||
const speakerComposer = (speaker, context) => {
|
||||
|
||||
let multimedias = [];
|
||||
if (context.scopes.includes('includeMultimedias')) {
|
||||
if ((context.scopes) && (context.scopes.includes('includeMultimedias'))) {
|
||||
multimedias = multimediaComposer(speaker.multimedias);
|
||||
};
|
||||
|
||||
let comments = [];
|
||||
if (context.scopes.includes('includeComments')) {
|
||||
if ((context.scopes) && (context.scopes.includes('includeComments'))) {
|
||||
comments = commentsComposer(speaker.comments);
|
||||
};
|
||||
|
||||
@ -79,22 +92,22 @@ const speakerComposer = (speaker, context) => {
|
||||
|
||||
const eventComposer = (event, context) => {
|
||||
|
||||
if (context.scopes.includes('includeVenue')) {
|
||||
if ((context.scopes) && (context.scopes.includes('includeVenue'))){
|
||||
delete event.venue.updatedAt;
|
||||
delete event.venue.createdAt;
|
||||
event.venue.image_url = cdnHelper.getCDNCityMediaUrl(event.venue.city);
|
||||
};
|
||||
|
||||
let multimedias = []
|
||||
if (context.scopes.includes('includeMultimedias')) {
|
||||
if ((context.scopes) && (context.scopes.includes('includeMultimedias'))) {
|
||||
multimedias = multimediaComposer(event.multimedias)
|
||||
};
|
||||
|
||||
let speakers = []
|
||||
if (context.scopes.includes('includeSpeakers')) {
|
||||
if ((context.scopes) && (context.scopes.includes('includeSpeakers'))) {
|
||||
speakers = event.details.map((detail) => ({
|
||||
order: detail.order,
|
||||
...speakerComposer(detail.speaker),
|
||||
...speakerComposer(detail.speaker, context),
|
||||
}))
|
||||
};
|
||||
|
||||
|
||||
@ -121,6 +121,12 @@ routes.get('/events/:id/inscriptions',
|
||||
eventController.getInscription,
|
||||
);
|
||||
|
||||
// Esto da las inscripciones (1) de un usuario pero si el usuario fuera el administrador podría todas las inscripciones de un evento
|
||||
routes.get('/inscriptions/:id/inscriptions',
|
||||
isLoggedUser,
|
||||
eventController.getInscription,
|
||||
);
|
||||
|
||||
// Hacer una inscripción
|
||||
routes.post('/events/:id/inscriptions',
|
||||
isLoggedUser,
|
||||
|
||||
@ -25,7 +25,6 @@ const extraMethods = {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
afterFetchOne: (result, params, context) => {
|
||||
if (result)
|
||||
result = result.toJSON();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user