a
This commit is contained in:
parent
386c948798
commit
826cdbe77b
@ -60,7 +60,6 @@ const generateControllers = (service, extraControllers = {}, options = {}) => {
|
|||||||
count: (config) => {
|
count: (config) => {
|
||||||
return async(req, res, next) => {
|
return async(req, res, next) => {
|
||||||
const params = extractParamsFromRequest(req, res, _options.params.count);
|
const params = extractParamsFromRequest(req, res, _options.params.count);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await service.count(params, buildContext(req, config));
|
const result = await service.count(params, buildContext(req, config));
|
||||||
return handleResultResponse(result, null, params, res);
|
return handleResultResponse(result, null, params, res);
|
||||||
|
|||||||
@ -127,12 +127,12 @@ function extractParamsFromRequest(req, res, extraParams = {}) {
|
|||||||
function handleErrorResponse(controllerName, methodName, error, res) {
|
function handleErrorResponse(controllerName, methodName, error, res) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const jsonResultFailed = buildErrorResponse(controllerName, methodName, error);
|
const jsonResultFailed = buildErrorResponse(controllerName, methodName, error);
|
||||||
res.status(jsonResultFailed.statusCode).send(jsonResultFailed);
|
res.send(jsonResultFailed.statusCode).send(jsonResultFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleResultResponse(result, totalCount = null, params, res, statusCode = httpStatus.OK) {
|
function handleResultResponse(result, totalCount = null, params, res, statusCode = httpStatus.OK) {
|
||||||
setPaginationInfo((totalCount) ? totalCount : getTotalCount(result), res);
|
setPaginationInfo((totalCount) ? totalCount : getTotalCount(result), res);
|
||||||
res.status(statusCode).send(result);
|
res.send(statusCode).send(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -30,9 +30,9 @@ const extraControllers = {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await eventReservationService._getReservaByCode(eventId, registrationCode);
|
const result = await eventReservationService._getReservaByCode(eventId, registrationCode);
|
||||||
handleResultResponse(!!result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
|
return handleResultResponse(!!result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
handleErrorResponse(MODULE_NAME, 'checkReservationCode', error, res)
|
return handleErrorResponse(MODULE_NAME, 'checkReservationCode', error, res)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -52,20 +52,33 @@ const extraControllers = {
|
|||||||
if (eventId) {
|
if (eventId) {
|
||||||
try {
|
try {
|
||||||
const result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
|
const result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
|
||||||
handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
|
return handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
|
return handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
try {
|
try {
|
||||||
const result = await eventInscriptionService._getInscriptionsUser(userId);
|
const result = await eventInscriptionService._getInscriptionsUser(userId);
|
||||||
handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
|
return handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
|
return handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getInscriptionsOfNextEventsCount: async (req, res, next) => {
|
||||||
|
const params = extractParamsFromRequest(req, res, {});
|
||||||
|
const userId = req.user.id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await eventInscriptionService._getInscriptionsOfNextEventsUser(userId);
|
||||||
|
console.log('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb');
|
||||||
|
return handleResultResponse(result, null, params, res, httpStatus.OK);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
|
||||||
|
return handleErrorResponse(MODULE_NAME, 'getInscriptionsOfNextEventsCount', error, res)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getInscription: async (req, res, next) => {
|
getInscription: async (req, res, next) => {
|
||||||
|
|||||||
@ -137,6 +137,17 @@ routes.get('/events/:id/inscriptions',
|
|||||||
eventController.getInscriptions,
|
eventController.getInscriptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Esto da todas las inscripciones de un usuario
|
||||||
|
routes.get('/me/inscriptions/count',
|
||||||
|
isLoggedUser,
|
||||||
|
/*(req, res, next) => {
|
||||||
|
req.apicacheGroup = req.user.id;
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
cacheSuccesses('1 hour'),*/
|
||||||
|
eventController.getInscriptionsOfNextEventsCount,
|
||||||
|
);
|
||||||
|
|
||||||
// Esto da todas las inscripciones de un usuario
|
// Esto da todas las inscripciones de un usuario
|
||||||
routes.get('/me/inscriptions',
|
routes.get('/me/inscriptions',
|
||||||
isLoggedUser,
|
isLoggedUser,
|
||||||
|
|||||||
@ -81,7 +81,8 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
include: [{
|
include: [{
|
||||||
model: sequelize.models.Event,
|
model: sequelize.models.Event,
|
||||||
as: 'event',
|
as: 'event',
|
||||||
attributes: ['id', 'name', 'description', 'campaign_text', 'init_date'],
|
attributes: ['id', 'name', 'description', 'campaign_text', 'init_date', 'end_date', 'init_available_date',
|
||||||
|
'end_available_date', 'stateCode', 'stateText'],
|
||||||
include: [{
|
include: [{
|
||||||
model: sequelize.models.Venue,
|
model: sequelize.models.Venue,
|
||||||
as: 'venue',
|
as: 'venue',
|
||||||
|
|||||||
@ -6,6 +6,9 @@ const moment = require('moment');
|
|||||||
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
||||||
const models = require('../../core/models');
|
const models = require('../../core/models');
|
||||||
const marketing = require('../../helpers/mailchimp.helper')
|
const marketing = require('../../helpers/mailchimp.helper')
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
moment.locale('es');
|
||||||
|
|
||||||
|
|
||||||
const extraMethods = {
|
const extraMethods = {
|
||||||
|
|
||||||
@ -37,6 +40,18 @@ const extraMethods = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getInscriptionsOfNextEventsUser: (userId) => {
|
||||||
|
return models.EventInscription.count({
|
||||||
|
include: [{ model: models.Event,
|
||||||
|
as: 'event',
|
||||||
|
where: {
|
||||||
|
end_date: {[Sequelize.Op.gte]: moment().utc()},
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
where: { userId: userId },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
//Nos devuelve el número de inscripciones confirmadas para ese evento sin tener en cuenta reservas
|
//Nos devuelve el número de inscripciones confirmadas para ese evento sin tener en cuenta reservas
|
||||||
_getCountInscriptionsWithoutReservationAndOverflow: (eventId) => {
|
_getCountInscriptionsWithoutReservationAndOverflow: (eventId) => {
|
||||||
return models.EventInscription.count({
|
return models.EventInscription.count({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user