.
This commit is contained in:
parent
37e1eb1af7
commit
f1ba77c848
@ -125,19 +125,22 @@ const generateService = (model, extraMethods = {}, options = defaultOptions) =>
|
|||||||
const defaultService = {
|
const defaultService = {
|
||||||
fetchAssociation: async(params, context) => {
|
fetchAssociation: async(params, context) => {
|
||||||
const associationName = hasAssociation(params);
|
const associationName = hasAssociation(params);
|
||||||
|
console.log('associationName => ', associationName);
|
||||||
delete params.params.association;
|
delete params.params.association;
|
||||||
|
|
||||||
const associationInfo = foundModelAssociation(model, associationName);
|
const associationInfo = foundModelAssociation(model, associationName);
|
||||||
if (associationInfo) {
|
if (associationInfo) {
|
||||||
const master = await defaultService.fetchOne(params, context);
|
const master = await defaultService.fetchOne(params, context);
|
||||||
console.log(master);
|
|
||||||
const details = {
|
const details = {
|
||||||
rows: await master[associationInfo.getFunc](),
|
rows: await master[associationInfo.getFunc](),
|
||||||
count: await master[associationInfo.countFunc]()
|
count: await master[associationInfo.countFunc]()
|
||||||
}
|
}
|
||||||
return details;
|
return details;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('¡fetchAssociation error!');
|
return {
|
||||||
|
rows: ["Association not exists"],
|
||||||
|
count: 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -52,18 +52,6 @@ routes.get('/speakers/:id',
|
|||||||
speakerController.findOne
|
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
|
// Dar ponentes similares a uno dado
|
||||||
routes.get('/speakers/:id/similar',
|
routes.get('/speakers/:id/similar',
|
||||||
//isLoggedUser,
|
//isLoggedUser,
|
||||||
@ -75,6 +63,19 @@ routes.get('/speakers/:id/similar',
|
|||||||
speakerController.find
|
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;
|
module.exports = routes;
|
||||||
@ -28,15 +28,23 @@ routes.get('/values/:id',
|
|||||||
valueController.findOne
|
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,
|
//isLoggedUser,
|
||||||
/*FieldMiddleware.middleware({
|
/*FieldMiddleware.middleware({
|
||||||
invalidFields: ['createdAt']
|
invalidFields: ['createdAt']
|
||||||
}),*/
|
}),*/
|
||||||
//PaginateMiddleware.middleware(),
|
//PaginateMiddleware.middleware(),
|
||||||
//SortMiddleware.middleware({ default: "name" }),
|
//SortMiddleware.middleware({ default: "name" }),
|
||||||
valueController.find,
|
//valueController.find,
|
||||||
);
|
//);
|
||||||
|
|
||||||
|
|
||||||
module.exports = routes;
|
module.exports = routes;
|
||||||
Loading…
Reference in New Issue
Block a user