I need the id from mongoose before I continue
let newReportId = await ReportService.create(report);
console.log('new report id ', newReportId);
let reportAsString = turnDataIntoHtmlString(report);
return createJSReportPdf(reportAsString, newReportId, type);
Syntax wise this should be correct in this async function. Do not log newReportId until the service has returned.
However it is undefined and logs before the report service has done it's job even though I have stated AWAIT! ReportService.create(report)
does log the id, but I can't return it.
let id = await serviceReport.save((err, doc) => {
if (err) {
console.error(err);
} else {
console.log('doc cod ', doc._id);
return doc._id;
}
});
return id;
Please help!