.
This commit is contained in:
parent
522257517c
commit
37e1eb1af7
@ -10,16 +10,6 @@ const MODULE_NAME = '[value.controller]';
|
|||||||
|
|
||||||
const controllerOptions = { MODULE_NAME };
|
const controllerOptions = { MODULE_NAME };
|
||||||
const extraControllers = {
|
const extraControllers = {
|
||||||
findSpeakers: async (req, res, next) => {
|
|
||||||
const params = extractParamsFromRequest(req, res, {});
|
|
||||||
try {
|
|
||||||
const result = await valueService.associationFetchAll(params, { user: req.user });
|
|
||||||
console.log(result);
|
|
||||||
return handleResultResponse(result, result.count, params, res);
|
|
||||||
} catch (error) {
|
|
||||||
handleErrorResponse(MODULE_NAME, 'findNext', error, res);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = generateControllers(valueService, extraControllers, controllerOptions);
|
module.exports = generateControllers(valueService, extraControllers, controllerOptions);
|
||||||
|
|||||||
@ -39,15 +39,4 @@ routes.get('/values/:id/:association',
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
routes.get('/values/:id/speakers/:speakerId',
|
|
||||||
//isLoggedUser,
|
|
||||||
FieldMiddleware.middleware({
|
|
||||||
invalidFields: ['createdAt']
|
|
||||||
}),
|
|
||||||
PaginateMiddleware.middleware(),
|
|
||||||
SortMiddleware.middleware({ default: "name" }),
|
|
||||||
valueController.findSpeakers
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = routes;
|
module.exports = routes;
|
||||||
@ -86,29 +86,6 @@ function extractParams(params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const extraMethods = {
|
const extraMethods = {
|
||||||
associationFetchAll: async (params, context) => {
|
|
||||||
|
|
||||||
async function fetchOne(params, context) {
|
|
||||||
const findOptions = parseParamsToFindOptions(params);
|
|
||||||
|
|
||||||
return await model.findOne({
|
|
||||||
where: findOptions.where,
|
|
||||||
include: findOptions.include
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const model = models.Value;
|
|
||||||
const associationName = params.params.association;
|
|
||||||
delete params.params.association;
|
|
||||||
const associationInfo = foundModelAssociation(model, associationName);
|
|
||||||
if (associationInfo) {
|
|
||||||
const result = await fetchOne(params, context);
|
|
||||||
const prueba = await result[associationInfo.getFunc]();
|
|
||||||
return prueba;
|
|
||||||
} else {
|
|
||||||
throw new Error('error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = generateService(models.Value, extraMethods);
|
module.exports = generateService(models.Value, extraMethods);
|
||||||
Loading…
Reference in New Issue
Block a user