a
This commit is contained in:
parent
e3976cb516
commit
0c59d2a2fc
@ -40,21 +40,22 @@ const extraControllers = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
//Funcion que devuelve:
|
//Funcion que devuelve:
|
||||||
//1. Todas las inscripciones de un evento, cuando el usuario es administrador (SIN HACER)
|
//1. Todas las inscripciones de un evento, cuando el usuario es administrador
|
||||||
//2. Todas las inscripciones de un usuario, cuando no nos llega ningun param con id
|
//2. Todas las inscripciones de un usuario, cuando no nos llega ningun param con id
|
||||||
getInscriptions: async (req, res, next) => {
|
getInscriptions: async (req, res, next) => {
|
||||||
|
|
||||||
const params = extractParamsFromRequest(req, res, {});
|
const params = extractParamsFromRequest(req, res, {});
|
||||||
const eventId = params.params.id;
|
const eventId = params.params.id;
|
||||||
const userId = req.user.id;
|
const userId = req.user.id;
|
||||||
|
var result = null;
|
||||||
|
|
||||||
//req.user.rol Administrador ......
|
console.log(params);
|
||||||
|
|
||||||
//req.user.rol normal ......
|
|
||||||
|
|
||||||
if (eventId) {
|
if (eventId) {
|
||||||
try {
|
try {
|
||||||
const result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
|
if (req.user.level = 8)
|
||||||
|
result = await eventInscriptionService._getInscriptionByEvent(eventId)
|
||||||
|
else
|
||||||
|
result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
|
||||||
return 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) {
|
||||||
return handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
|
return handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
|
||||||
@ -62,7 +63,7 @@ const extraControllers = {
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
try {
|
try {
|
||||||
const result = await eventInscriptionService._getInscriptionsUser(userId);
|
result = await eventInscriptionService._getInscriptionsUser(userId);
|
||||||
return 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) {
|
||||||
return handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
|
return handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
|
||||||
@ -464,10 +465,10 @@ console.log(mailOptions);
|
|||||||
getReservationsExcel: async (req, res, next) => {
|
getReservationsExcel: async (req, res, next) => {
|
||||||
console.log('exxxxxxxxxxxxxxxcel');
|
console.log('exxxxxxxxxxxxxxxcel');
|
||||||
const params = extractParamsFromRequest(req, res, {});
|
const params = extractParamsFromRequest(req, res, {});
|
||||||
const inscriptionId = params.params.id;
|
const eventId = params.params.id;
|
||||||
const userId = req.user.id;
|
const userId = req.user.id;
|
||||||
|
|
||||||
const inscription = await eventReservationService._getReservationsExcel(req.user, params.params.id, null, function(result, status){
|
const inscription = await eventReservationService._getReservationsExcel(req.user, eventId, null, function(result, status){
|
||||||
if (result.messenger.code == "S99001") {
|
if (result.messenger.code == "S99001") {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||||
|
|||||||
@ -196,11 +196,13 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Event.associate = function (models) {
|
Event.associate = function (models) {
|
||||||
// Event.OverflowEvent = Event.belongsTo(models.Event, {
|
|
||||||
// as: 'overflowEvent',
|
Event.OverflowEvent = Event.belongsTo(models.Event, {
|
||||||
// foreignKey: 'overflow_eventId',
|
as: 'overflowEvent',
|
||||||
// required: false });
|
foreignKey: 'overflow_eventId',
|
||||||
Event.Type = Event.belongsTo(models.EventType, { foreignKey: 'typeId', as: "type" });
|
required: false });
|
||||||
|
|
||||||
|
Event.Type = Event.belongsTo(models.EventType, { foreignKey: 'typeId', as: "type" });
|
||||||
Event.UserCreate = Event.belongsTo(models.User, { foreignKey: 'userId', as: "user" });
|
Event.UserCreate = Event.belongsTo(models.User, { foreignKey: 'userId', as: "user" });
|
||||||
Event.Venue = Event.belongsTo(models.Venue, { foreignKey: 'venueId', as: "venue",
|
Event.Venue = Event.belongsTo(models.Venue, { foreignKey: 'venueId', as: "venue",
|
||||||
required: false,
|
required: false,
|
||||||
@ -270,6 +272,13 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Event.addScope('includeOverflowEvent', () => {
|
||||||
|
return {
|
||||||
|
include: [
|
||||||
|
{ model: sequelize.models.Event, as: 'overflowEvent', required: false}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Event.addScope('includeDetails', () => {
|
Event.addScope('includeDetails', () => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -134,14 +134,14 @@ routes.get('/events/:id/multimedias',
|
|||||||
eventController.find,
|
eventController.find,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Inscripciones
|
// Inscripciones
|
||||||
// Esto da las inscripciones (1) de un usuario pero si el usuario fuera el administrador podría todas las inscripciones de un evento
|
// Esto da las inscripciones de un usuario
|
||||||
routes.get('/events/:id/inscriptions',
|
routes.get('/events/:id/inscriptions',
|
||||||
isLoggedUser,
|
isLoggedUser,
|
||||||
eventController.getInscriptions,
|
eventController.getInscriptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Esto da todas las inscripciones de un usuario
|
// Esto da todas las inscripciones de un usuario
|
||||||
routes.get('/me/inscriptions/count',
|
routes.get('/me/inscriptions/count',
|
||||||
isLoggedUser,
|
isLoggedUser,
|
||||||
@ -262,6 +262,13 @@ routes.get('/tickets/:id/',
|
|||||||
* ADMINISTRACIÓN
|
* ADMINISTRACIÓN
|
||||||
*********************************************************************************************************
|
*********************************************************************************************************
|
||||||
*/
|
*/
|
||||||
|
// Inscripciones
|
||||||
|
// Esto da las inscripciones de un evento
|
||||||
|
routes.get('/admin/events/:id/inscriptions',
|
||||||
|
isAdministratorUser,
|
||||||
|
PaginateMiddleware.middleware(),
|
||||||
|
eventController.getInscriptions,
|
||||||
|
);
|
||||||
|
|
||||||
// Todos los ponentes
|
// Todos los ponentes
|
||||||
routes.get('/admin/events',
|
routes.get('/admin/events',
|
||||||
@ -311,7 +318,7 @@ routes.get('/admin/events/:id',
|
|||||||
isAdministratorUser,
|
isAdministratorUser,
|
||||||
(req, res, next) => {
|
(req, res, next) => {
|
||||||
return eventController.findOne({
|
return eventController.findOne({
|
||||||
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeDetails']
|
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeOverflowEvent', 'includeDetails']
|
||||||
})(req, res, next)
|
})(req, res, next)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -362,15 +369,4 @@ routes.delete('/admin/reservations/:id',
|
|||||||
eventReservationController.delete()
|
eventReservationController.delete()
|
||||||
);
|
);
|
||||||
|
|
||||||
routes.get('/inscriptions',
|
|
||||||
isAdministratorUser,
|
|
||||||
//SchemaValidator(eventValidation.ReservationInputType, true),
|
|
||||||
(req, res, next) => {
|
|
||||||
return eventInscriptionController.find({
|
|
||||||
scopes: ['defaultScope']
|
|
||||||
})(req, res, next)
|
|
||||||
},
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = routes;
|
module.exports = routes;
|
||||||
@ -51,6 +51,14 @@ const extraMethods = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getInscriptionByEvent: (eventId) => {
|
||||||
|
return models.EventInscription.scope('defaultScope').findAll({
|
||||||
|
where: {
|
||||||
|
eventId: eventId,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
_getInscriptionsUser: (userId) => {
|
_getInscriptionsUser: (userId) => {
|
||||||
return models.EventInscription.scope('includeEventAndVenue').findAll({
|
return models.EventInscription.scope('includeEventAndVenue').findAll({
|
||||||
attributes: {
|
attributes: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user