In my controller I have this method that renders a marko file sending an object to the view with data (dataView)
export const renderRecoveryData = (
req: Request | any,
reply: ResponseToolkit,
callback: any
): void => {
const dataView: { [key: string]: any } = {
id: 1,
info: getInfo(req, reply, callback),
};
templateEngine.renderFromTemplate(
"./views/private/info/info.marko",
dataView,
req,
reply,
);
};
In the "info" property I want to load an object that obtains the data from the call to two services, using this method:
const getInfo = (req: Request | any, reply: any, callback: any): void => {
const headers = helpers.setHeaders(req);
const idNumber = req.yar.get('idNumber');
async.parallel({
personalData: (callback: any) => infoService.personalInfo(idNumber, headers, callback),
addionalInfo: (callback: any) => infoService.addicionalInfo(headers, callback),
}, (err: any, responses: any) => {
if (err) {
return callback(err);
}
console.log("response", responses);
return responses;
});
};
The console.log correctly shows me the object that I want to save in the "info" property of "dataView", but when I check what the view gets, the "info" property doesn't show up, it just shows me the "id" property
I call "renderRecoveryData" from a routes file:
server.route({
method: "GET",
path: "/{locale}/private/info/dashboard/step1",
handler: renderRecoveryData,
});
What can be the problem? Thanks
getInfois async function and you will have to either useawaitwhen calling it or render template in callback ofgetInfo. Other problem is you are not invoking callback in case of success (please replacereturn responseswithreturn callback(null, responses)).