This commit is contained in:
David Arranz 2019-07-11 20:05:06 +02:00
parent 8a7f56afed
commit 9b68ad3304
11 changed files with 29 additions and 14 deletions

View File

@ -92,11 +92,14 @@ passport.use('local-phone', new LocalStrategy(localPhoneOptions, async (phone, f
// JWT
passport.use('jwt', new CustomStrategy(async (req, done) => {
const token = ((req && req.headers && req.headers['x-access-token']) ? req.headers['x-access-token'] : null);
console.log(token);
console.log(req.headers);
if (!token) {
return done(null, false, { message: 'Unauthorized'});
}
if (securityHelper.verify(token)) {
console.log('VERIFICAAAAAAAAAAAAAAAAAAAAAAAAADO');
}
return done(null, securityHelper.verify(token));
}));

View File

@ -11,7 +11,8 @@ const RegisterInputType = Joi.object().keys({
fbuid: Joi.string().required(),
name: Joi.string().required(),
surname: Joi.string(),
entityid: Joi.string()
entityid: Joi.string().allow(null),
profile_picture: Joi.string().allow(null),
});
const LoginOutputType = Joi.object().keys({

View File

@ -60,10 +60,11 @@ module.exports = function (sequelize, DataTypes) {
User.associate = function (models) {
User.Roles = User.belongsToMany(models.Rol, {
through: models.UserRoles,
through: models.UserRoles,
foreignKey: 'userId'
});
User.Entity = User.belongsTo(models.Entity, { foreignKey: 'entityId' });
User.EventsCreates = User.hasMany(models.Event, { foreignKey: 'userId' });
User.Devices = User.hasMany(models.UserDevice, { foreignKey: 'userId' });
User.Comments = User.hasMany(models.Comment, { foreignKey: 'userId' });
User.EventsReservations = User.hasMany(models.EventReservation, { foreignKey: 'userId' });

View File

@ -25,7 +25,7 @@ module.exports = function (sequelize, DataTypes) {
through: models.EntityEntitiesTypes,
foreignKey: 'entityId'
});
Entity.Users = Entity.hasMany(models.User, { foreignKey: 'entityId' });
Entity.User = Entity.hasMany(models.User, { foreignKey: 'entityId' });
Entity.EventsReservations = Entity.hasMany(models.EventReservation, { foreignKey: 'entityId' });
};
return Entity;

View File

@ -16,7 +16,7 @@ routes.get ('/entities',
entityController.find);
routes.get ('/entities/colleges',
PaginateMiddleware.middleware(),
// PaginateMiddleware.middleware(),
FieldMiddleware.middleware({
invalidFields: ['state', 'createdAt', 'updatedAt']
}),
@ -25,7 +25,7 @@ routes.get ('/entities/colleges',
);
routes.get ('/entities/partners',
PaginateMiddleware.middleware(),
// PaginateMiddleware.middleware(),
FieldMiddleware.middleware({
invalidFields: ['state', 'createdAt', 'updatedAt']
}),

View File

@ -21,7 +21,7 @@ const extraMethods = {
});
try {
return await models.Entity.findAndCountAll(findOptions);
return await models.Entity.findAll(findOptions);
} catch (error) {
throw error;
}

View File

@ -12,7 +12,7 @@ const controllerOptions = { MODULE_NAME };
const extraControllers = {
findNext: async (req, res, next) => {
const params = extractParamsFromRequest(req, res, {});
const params = extractParamsFromRequest(req, res, { includeAll: false });
try {
const result = await eventService.fetch(params, { user: req.user, lapse: 'next' });
return handleResultResponse(result, result.count, params, res);

View File

@ -80,6 +80,11 @@ module.exports = function (sequelize, DataTypes) {
marketingList: {
type: DataTypes.STRING,
},
userId: {
type: DataTypes.UUID,
foreignKey: true,
},
}, {
tableName: 'events',
freezeTableName: true,

View File

@ -22,9 +22,9 @@ routes.get('/events',
routes.get('/events/next',
isLoggedUser,
/*FieldMiddleware.middleware({
invalidFields: ['user', 'createdAt']
}), */
FieldMiddleware.middleware({
invalidFields: ['userId', 'createdAt', 'updatedAt']
}),
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "init_available_date" }),
eventController.findNext

View File

@ -42,18 +42,22 @@ const extraMethods = {
break;
}
// Incluir
findOptions.include.push({
model: models.EventSchedule,
model: models.EventSchedule, include: {model: models.Speaker, attributes: ['id', 'name', 'description']}
});
findOptions.include.push({
model: models.EventType,
model: models.EventType, attributes: ['name', 'tittle'],
});
findOptions.include.push({
model: models.Venue,
});
// findOptions.include.push({
// model: models.Multimedia, //where: { alias: type }, attributes: [],
// });
findOptions.where = Object.assign({},
findOptions.where, {

View File

@ -33,6 +33,7 @@ module.exports = function (sequelize, DataTypes) {
EventSchedule.associate = function (models) {
EventSchedule.Event = EventSchedule.belongsTo(models.Event, { foreignKey: 'eventId' });
EventSchedule.Speaker = EventSchedule.belongsTo(models.Speaker, {foreignKey: 'speakerId'});
};