From c6db40c0956f72acf52133ac9b7b30288f077208 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 28 Sep 2022 19:50:05 +0200 Subject: [PATCH] Rellenar el color verde en entradas normales --- modules/events/event.controller.js | 19 +++++---------- .../events/events_inscriptions.controller.js | 5 +++- modules/events/events_inscriptions.service.js | 23 +++++++++++++++++++ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/modules/events/event.controller.js b/modules/events/event.controller.js index cfde731..7f6a5b5 100644 --- a/modules/events/event.controller.js +++ b/modules/events/event.controller.js @@ -31,19 +31,7 @@ const MODULE_NAME = "[event.controller]"; const controllerOptions = { MODULE_NAME, - findOneCallback: (result) => { - // Si hay inscripciones normales, ponerles el color por defecto 'verde'. - - result.inscriptions = result.inscriptions.map((inscription) => { - const isVirtual = inscription.type === "online" || inscription.type === "online group"; - if ((inscription.reservationId === null) && (!isVirtual)) { - // Inscripción normal - inscription.color = 'green'; - } - return inscription; - }); - return result; - } + findOneCallback: eventInscriptionService._fillInscriptionsColor }; function generateMemberInscription(user, inscription, reservation) { @@ -135,6 +123,8 @@ const extraControllers = { const userId = req.user.id; var result = null; + + console.log(params, req.user.level); if (eventId) { try { @@ -148,6 +138,9 @@ const extraControllers = { } else { try { result = await eventInscriptionService._getInscriptionsUser(userId); + result = result.map(row => row.toJSON()); + // Asigno colores a las entradas normales + result = eventInscriptionService._fillInscriptionsColor(result); return handleResultResponse(result, null, params, res, result === null ? httpStatus.NOT_FOUND : httpStatus.OK); } catch (error) { return handleErrorResponse(MODULE_NAME, "getInscriptions", error, res); diff --git a/modules/events/events_inscriptions.controller.js b/modules/events/events_inscriptions.controller.js index 048723b..022ff94 100644 --- a/modules/events/events_inscriptions.controller.js +++ b/modules/events/events_inscriptions.controller.js @@ -231,11 +231,14 @@ const extraControllers = { if (inscription.reservation === null) { console.log('asigno green'); + inscription.color = 'green'; + + /* parche */ inscription.reservation = { color: 'green', description: 'Entrada', }; - }; + } console.log(">>>>>>>voy a dar inscription", inscription); return handleResultResponse(inscription, null, params, res, httpStatus.OK); diff --git a/modules/events/events_inscriptions.service.js b/modules/events/events_inscriptions.service.js index 21e0e44..5da2e04 100644 --- a/modules/events/events_inscriptions.service.js +++ b/modules/events/events_inscriptions.service.js @@ -34,6 +34,26 @@ function generateNewCodeTicket() { } const extraMethods = { + _fillInscriptionColor: (inscription) => { + if (inscription && inscription.type) { + const isVirtual = inscription.type === "online" || inscription.type === "online group"; + if ((inscription.reservationId === null) && (!isVirtual)) { + // Inscripción normal + inscription.color = 'green'; + } + } + + return inscription; + }, + + _fillInscriptionsColor: (inscriptions) => { + if (inscriptions && inscriptions.length) { + return inscriptions.map(extraMethods._fillInscriptionColor); + } else { + return inscriptions; + } + }, + _getInscriptionById: (id) => { return models.EventInscription.scope(["includeEventAndVenue", "includeReservation", "defaultScope"]).findOne({ where: { @@ -361,4 +381,7 @@ const extraMethods = { }; + + + module.exports = generateService(models.EventInscription, extraMethods);