routes de eventos
This commit is contained in:
parent
54b4ff7c56
commit
081fac98ea
@ -5,6 +5,7 @@ const { Strategy: CustomStrategy } = require('passport-custom');
|
||||
|
||||
const models = require('./models');
|
||||
const securityHelper = require('../helpers/security.helper');
|
||||
const authService = require('../modules/auth/auth.service');
|
||||
|
||||
/**
|
||||
* Validación sobre firebase
|
||||
@ -39,7 +40,6 @@ const localEmailOptions = {
|
||||
passport.use('local-email', new LocalStrategy(localEmailOptions, async (email, password, done) => {
|
||||
try {
|
||||
const user = await authService.extraMethods.findUser({ email });
|
||||
|
||||
if (_.isNull(user)) {
|
||||
return done(null, false, { message: 'User not found' })
|
||||
} else {
|
||||
|
||||
@ -76,6 +76,8 @@ function setPaginationInfo(totalCount, res) {
|
||||
});
|
||||
|
||||
const params = extractParamsFromRequest(null, res);
|
||||
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>>> params antes de setPaginationInfo');
|
||||
console.log(params);
|
||||
if (params.paginate) {
|
||||
const
|
||||
|
||||
@ -149,6 +149,8 @@ const generateService = (model, extraMethods = {}, options = defaultOptions) =>
|
||||
return defaultService.fetchAssociation(params, context)
|
||||
} else {
|
||||
const findOptions = parseParamsToFindOptions(params);
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
|
||||
console.log(findOptions);
|
||||
const result = await model.findAndCountAll(findOptions);
|
||||
console.log(result);
|
||||
return result;
|
||||
|
||||
@ -2,13 +2,35 @@
|
||||
|
||||
const generateControllers = require('../../core/controllers');
|
||||
const entityService = require('./entity.service');
|
||||
|
||||
const { extractParamsFromRequest, handleErrorResponse, handleResultResponse } = require('../../helpers/controller.helper');
|
||||
|
||||
// Module Name
|
||||
const MODULE_NAME = '[entity.controller]';
|
||||
|
||||
const controllerOptions = { MODULE_NAME };
|
||||
const extraControllers = {};
|
||||
const extraControllers = {
|
||||
|
||||
findColleges: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
try {
|
||||
const result = await entityService.fetch(params, { user: req.user, type: 'college' });
|
||||
return handleResultResponse(result, result.count, params, res);
|
||||
} catch (error) {
|
||||
handleErrorResponse(MODULE_NAME, 'findNext', error, res);
|
||||
}
|
||||
},
|
||||
|
||||
findPartners: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
try {
|
||||
const result = await eventService.fetch(params, { user: req.user, type: 'partner' });
|
||||
return handleResultResponse(result, result.count, params, res);
|
||||
} catch (error) {
|
||||
handleErrorResponse(MODULE_NAME, 'findNext', error, res);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
module.exports = generateControllers(entityService, extraControllers, controllerOptions);
|
||||
|
||||
|
||||
@ -9,6 +9,11 @@ module.exports = function (sequelize, DataTypes) {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
state: {
|
||||
type: DataTypes.STRING(45),
|
||||
allowNull: false,
|
||||
default: 'draft',
|
||||
}
|
||||
}, {
|
||||
tableName: 'entities',
|
||||
freezeTableName: true,
|
||||
|
||||
@ -3,19 +3,32 @@ const routes = require('express').Router();
|
||||
const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
|
||||
const SchemaValidator = require('../../middlewares/schemaValidator');
|
||||
|
||||
/*const PaginateMiddleware = require('../../middlewares/paginate');
|
||||
const FieldMiddleware = require('../../middlewares/fields');*/
|
||||
//const SortMiddleware = require('../../middlewares/sort');
|
||||
const PaginateMiddleware = require('../../middlewares/paginate');
|
||||
const FieldMiddleware = require('../../middlewares/fields');
|
||||
const SortMiddleware = require('../../middlewares/sort');
|
||||
|
||||
//const entityValidation = require('./entity.validations');
|
||||
const entityController = require('./entity.controller');
|
||||
|
||||
routes.get('/entities', entityController.find);
|
||||
//routes.get('/venues', isLoggedUser, SortMiddleware.middleware({ default: "name" }), venueController.find);
|
||||
//routes.get('/venues/:id', isLoggedUser, venueController.findOne);
|
||||
routes.get ('/entities',
|
||||
isLoggedUser,
|
||||
entityController.find);
|
||||
|
||||
routes.get ('/entities/colleges',
|
||||
PaginateMiddleware.middleware(),
|
||||
FieldMiddleware.middleware({
|
||||
invalidFields: ['state', 'createdAt', 'updatedAt', 'EntityTypes.id']
|
||||
}),
|
||||
SortMiddleware.middleware({ default: "name" }),
|
||||
entityController.findColleges
|
||||
);
|
||||
|
||||
routes.get ('/entities/partners',
|
||||
PaginateMiddleware.middleware(),
|
||||
SortMiddleware.middleware({ default: "name" }),
|
||||
entityController.findPartners
|
||||
);
|
||||
|
||||
|
||||
//routes.post('/entity/', SchemaValidator(VenueValidation.VenueInputType, true), venueController.create);
|
||||
//routes.put('/venues/:id', isAdministratorUser, venueController.update);
|
||||
//routes.delete('/venues/:id', isAdministratorUser, venueController.delete);
|
||||
|
||||
module.exports = routes;
|
||||
@ -5,6 +5,64 @@ const _ = require('lodash');
|
||||
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
||||
const models = require('../../core/models');
|
||||
|
||||
const extraMethods = {};
|
||||
const extraMethods = {
|
||||
|
||||
fetch: async (params, context) => {
|
||||
const type = context.type;
|
||||
const findOptions = parseParamsToFindOptions(params);
|
||||
|
||||
console.log('ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZz');
|
||||
console.log(findOptions);
|
||||
// findOptions.where = { 'name': '(Colegio Cristo Rey)'};
|
||||
|
||||
switch (type) {
|
||||
case 'college':
|
||||
// findOptions.where = Object.assign({},
|
||||
// findOptions.where, {
|
||||
// 'EntityType.alias' : 'college'
|
||||
// });
|
||||
break;
|
||||
case 'partner':
|
||||
// findOptions.where = Object.assign({},
|
||||
// findOptions.where, {
|
||||
// date: {
|
||||
// [Sequelize.Op.gte]: moment().startOf('day').utc(),
|
||||
// [Sequelize.Op.lt]: moment().add(1, 'days').startOf('day').utc(),
|
||||
// }
|
||||
// });
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Incluir
|
||||
findOptions.include.push({
|
||||
model: models.EntityType, where: { alias: 'college' }, attributes: ['name'],
|
||||
});
|
||||
// findOptions.include.push({
|
||||
// model: models.EventType,
|
||||
// });
|
||||
// findOptions.include.push({
|
||||
// model: models.Venue,
|
||||
// });
|
||||
|
||||
|
||||
findOptions.where = Object.assign({},
|
||||
findOptions.where, {
|
||||
state: 'publish'
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
return await models.Entity.findAll(findOptions);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = generateService(models.Entity, extraMethods);
|
||||
@ -9,6 +9,10 @@ module.exports = function (sequelize, DataTypes) {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
alias: {
|
||||
type: DataTypes.STRING(45),
|
||||
allowNull: false
|
||||
},
|
||||
}, {
|
||||
tableName: 'entities_types',
|
||||
freezeTableName: true,
|
||||
|
||||
@ -14,7 +14,27 @@ const extraControllers = {
|
||||
findNext: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
try {
|
||||
const result = await eventService.fetchNext(params, { user: req.user });
|
||||
const result = await eventService.fetch(params, { user: req.user, lapse: 'next' });
|
||||
return handleResultResponse(result, result.count, params, res);
|
||||
} catch (error) {
|
||||
handleErrorResponse(MODULE_NAME, 'findNext', error, res);
|
||||
}
|
||||
},
|
||||
|
||||
findCurrent: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
try {
|
||||
const result = await eventService.fetch(params, { user: req.user, lapse: 'current' });
|
||||
return handleResultResponse(result, result.count, params, res);
|
||||
} catch (error) {
|
||||
handleErrorResponse(MODULE_NAME, 'findNext', error, res);
|
||||
}
|
||||
},
|
||||
|
||||
findPass: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
try {
|
||||
const result = await eventService.fetch(params, { user: req.user, lapse: 'pass' });
|
||||
return handleResultResponse(result, result.count, params, res);
|
||||
} catch (error) {
|
||||
handleErrorResponse(MODULE_NAME, 'findNext', error, res);
|
||||
|
||||
@ -11,7 +11,7 @@ const SortMiddleware = require('../../middlewares/sort');
|
||||
const eventController = require('./event.controller');
|
||||
|
||||
routes.get('/events',
|
||||
//isLoggedUser,
|
||||
isLoggedUser,
|
||||
/*FieldMiddleware.middleware({
|
||||
invalidFields: ['user', 'createdAt']
|
||||
}),*/
|
||||
@ -21,7 +21,7 @@ routes.get('/events',
|
||||
);
|
||||
|
||||
routes.get('/events/next',
|
||||
//isLoggedUser,
|
||||
isLoggedUser,
|
||||
/*FieldMiddleware.middleware({
|
||||
invalidFields: ['user', 'createdAt']
|
||||
}), */
|
||||
@ -31,22 +31,22 @@ routes.get('/events/next',
|
||||
);
|
||||
|
||||
routes.get('/events/pass',
|
||||
//isLoggedUser,
|
||||
isLoggedUser,
|
||||
PaginateMiddleware.middleware(),
|
||||
SortMiddleware.middleware({ default: "-date" }),
|
||||
eventController.find
|
||||
eventController.findPass
|
||||
);
|
||||
|
||||
routes.get('/events/current',
|
||||
//isLoggedUser,
|
||||
isLoggedUser,
|
||||
PaginateMiddleware.middleware(),
|
||||
SortMiddleware.middleware({ default: "init_available_date" }),
|
||||
eventController.find
|
||||
eventController.findCurrent
|
||||
);
|
||||
|
||||
|
||||
routes.get('/events/:id',
|
||||
//isLoggedUser,
|
||||
isLoggedUser,
|
||||
FieldMiddleware.middleware({
|
||||
invalidFields: ['createdAt']
|
||||
}),
|
||||
|
||||
@ -8,16 +8,40 @@ const Sequelize = require('sequelize');
|
||||
const models = require('../../core/models');
|
||||
|
||||
const extraMethods = {
|
||||
fetchNext: async (params, context) => {
|
||||
fetch: async (params, context) => {
|
||||
const lapse = context.lapse;
|
||||
const findOptions = parseParamsToFindOptions(params);
|
||||
|
||||
findOptions.where = Object.assign({},
|
||||
findOptions.where, {
|
||||
date: {
|
||||
[Sequelize.Op.gte]: moment().add(1, 'days').startOf('day').utc()
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
switch (lapse) {
|
||||
case 'next':
|
||||
findOptions.where = Object.assign({},
|
||||
findOptions.where, {
|
||||
date: {
|
||||
[Sequelize.Op.gte]: moment().add(1, 'days').startOf('day').utc()
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'current':
|
||||
findOptions.where = Object.assign({},
|
||||
findOptions.where, {
|
||||
date: {
|
||||
[Sequelize.Op.gte]: moment().startOf('day').utc(),
|
||||
[Sequelize.Op.lt]: moment().add(1, 'days').startOf('day').utc(),
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'past':
|
||||
findOptions.where = Object.assign ({},
|
||||
findOptions.where, {
|
||||
date: {
|
||||
[Sequelize.Op.lt]: moment().startOf('day').utc()
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Incluir
|
||||
findOptions.include.push({
|
||||
@ -37,8 +61,6 @@ const extraMethods = {
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
return await models.Event.findAll(findOptions);
|
||||
} catch(error) {
|
||||
|
||||
81
script-carga-bd-entidades-estructura.sql
Normal file
81
script-carga-bd-entidades-estructura.sql
Normal file
@ -0,0 +1,81 @@
|
||||
-- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64)
|
||||
--
|
||||
-- Host: localhost Database: lqdvi_v2
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 5.7.26-0ubuntu0.16.04.1
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Table structure for table `entities`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `entities`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `entities` (
|
||||
`id` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`state` varchar(45) NOT NULL,
|
||||
`createdAt` datetime NOT NULL,
|
||||
`updatedAt` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `entities_entities_types`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `entities_entities_types`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `entities_entities_types` (
|
||||
`entityId` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
||||
`typeId` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
||||
`createdAt` datetime NOT NULL,
|
||||
`updatedAt` datetime NOT NULL,
|
||||
PRIMARY KEY (`entityId`,`typeId`),
|
||||
UNIQUE KEY `entities_entities_types_entityId_typeId_unique` (`entityId`,`typeId`),
|
||||
KEY `typeId` (`typeId`),
|
||||
CONSTRAINT `entities_entities_types_ibfk_1` FOREIGN KEY (`entityId`) REFERENCES `entities` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `entities_entities_types_ibfk_2` FOREIGN KEY (`typeId`) REFERENCES `entities_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `entities_types`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `entities_types`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `entities_types` (
|
||||
`id` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`alias` varchar(45) NOT NULL,
|
||||
`createdAt` datetime NOT NULL,
|
||||
`updatedAt` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2019-07-10 13:14:45
|
||||
37
script-carga-bd-entities.sql
Normal file
37
script-carga-bd-entities.sql
Normal file
File diff suppressed because one or more lines are too long
37
script-carga-bd-entities_entities_types.sql
Normal file
37
script-carga-bd-entities_entities_types.sql
Normal file
File diff suppressed because one or more lines are too long
37
script-carga-bd-entities_types.sql
Normal file
37
script-carga-bd-entities_types.sql
Normal file
@ -0,0 +1,37 @@
|
||||
-- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64)
|
||||
--
|
||||
-- Host: localhost Database: lqdvi_v2
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 5.7.26-0ubuntu0.16.04.1
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `entities_types`
|
||||
--
|
||||
|
||||
LOCK TABLES `entities_types` WRITE;
|
||||
/*!40000 ALTER TABLE `entities_types` DISABLE KEYS */;
|
||||
INSERT INTO `entities_types` VALUES ('2617e44a-a303-11e9-94b5-000c295f0f58','ENTIDADES PATROCINADORAS Y COLABORADORAS','2019-07-02 12:00:00','2019-07-02 12:00:00','partner'),('76b17163-a167-11e9-a57c-000c295f0f58','ENTIDADES EDUCATIVAS COLABORADORAS','2019-07-08 12:02:15','2019-07-08 12:02:15','college');
|
||||
/*!40000 ALTER TABLE `entities_types` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2019-07-10 13:10:42
|
||||
Loading…
Reference in New Issue
Block a user