This commit is contained in:
David Arranz 2019-07-09 22:20:59 +02:00
parent 37e1eb1af7
commit f1ba77c848
3 changed files with 29 additions and 17 deletions

View File

@ -125,19 +125,22 @@ const generateService = (model, extraMethods = {}, options = defaultOptions) =>
const defaultService = {
fetchAssociation: async(params, context) => {
const associationName = hasAssociation(params);
console.log('associationName => ', associationName);
delete params.params.association;
const associationInfo = foundModelAssociation(model, associationName);
if (associationInfo) {
const master = await defaultService.fetchOne(params, context);
console.log(master);
const details = {
rows: await master[associationInfo.getFunc](),
count: await master[associationInfo.countFunc]()
}
return details;
} else {
throw new Error('¡fetchAssociation error!');
return {
rows: ["Association not exists"],
count: 0
};
}
},

View File

@ -52,18 +52,6 @@ routes.get('/speakers/:id',
speakerController.findOne
);
// Listar las preguntas hechas a un ponente
routes.get('/speakers/:id/questions',
//isLoggedUser,
/*FieldMiddleware.middleware({
invalidFields: ['createdAt']
}),*/
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "-createdAt" }),
speakerController.find
);
// Dar ponentes similares a uno dado
routes.get('/speakers/:id/similar',
//isLoggedUser,
@ -75,6 +63,19 @@ routes.get('/speakers/:id/similar',
speakerController.find
);
// Listar las preguntas hechas a un ponente
routes.get('/speakers/:id/:association',
//isLoggedUser,
/*FieldMiddleware.middleware({
invalidFields: ['createdAt']
}),*/
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "-createdAt" }),
speakerController.find
);
module.exports = routes;

View File

@ -28,15 +28,23 @@ routes.get('/values/:id',
valueController.findOne
);
routes.get('/values/:id/:association',
routes.get('/values/:id/speakers',
(req, res, next) => {
req.params.association = 'speakers';
next();
},
valueController.find,
);
//routes.get('/values/:id/:association',
//isLoggedUser,
/*FieldMiddleware.middleware({
invalidFields: ['createdAt']
}),*/
//PaginateMiddleware.middleware(),
//SortMiddleware.middleware({ default: "name" }),
valueController.find,
);
//valueController.find,
//);
module.exports = routes;