entities mejorado
This commit is contained in:
parent
081fac98ea
commit
8a7f56afed
@ -11,7 +11,11 @@ const controllerOptions = { MODULE_NAME };
|
||||
const extraControllers = {
|
||||
|
||||
findColleges: async (req, res, next) => {
|
||||
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-params');
|
||||
console.log(params);
|
||||
|
||||
try {
|
||||
const result = await entityService.fetch(params, { user: req.user, type: 'college' });
|
||||
return handleResultResponse(result, result.count, params, res);
|
||||
@ -23,7 +27,7 @@ const extraControllers = {
|
||||
findPartners: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
try {
|
||||
const result = await eventService.fetch(params, { user: req.user, type: 'partner' });
|
||||
const result = await entityService.fetch(params, { user: req.user, type: 'partner' });
|
||||
return handleResultResponse(result, result.count, params, res);
|
||||
} catch (error) {
|
||||
handleErrorResponse(MODULE_NAME, 'findNext', error, res);
|
||||
|
||||
@ -12,12 +12,13 @@ const entityController = require('./entity.controller');
|
||||
|
||||
routes.get ('/entities',
|
||||
isLoggedUser,
|
||||
PaginateMiddleware.middleware(),
|
||||
entityController.find);
|
||||
|
||||
routes.get ('/entities/colleges',
|
||||
PaginateMiddleware.middleware(),
|
||||
FieldMiddleware.middleware({
|
||||
invalidFields: ['state', 'createdAt', 'updatedAt', 'EntityTypes.id']
|
||||
invalidFields: ['state', 'createdAt', 'updatedAt']
|
||||
}),
|
||||
SortMiddleware.middleware({ default: "name" }),
|
||||
entityController.findColleges
|
||||
@ -25,7 +26,10 @@ routes.get ('/entities/colleges',
|
||||
|
||||
routes.get ('/entities/partners',
|
||||
PaginateMiddleware.middleware(),
|
||||
SortMiddleware.middleware({ default: "name" }),
|
||||
FieldMiddleware.middleware({
|
||||
invalidFields: ['state', 'createdAt', 'updatedAt']
|
||||
}),
|
||||
SortMiddleware.middleware({ default: "name" }),
|
||||
entityController.findPartners
|
||||
);
|
||||
|
||||
|
||||
@ -11,51 +11,17 @@ const extraMethods = {
|
||||
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'],
|
||||
model: models.EntityType, where: { alias: type }, attributes: [],
|
||||
});
|
||||
// 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);
|
||||
return await models.Entity.findAndCountAll(findOptions);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user