Answer the question
In order to leave comments, you need to log in
How to get a promise?
Hello, I'm using Expres+TypeORM+routing-controllers
The application renders pages from ejs.
I can't understand why I get an empty object from the controller.
Controller code:
@Controller()
@Get('/dashboard')
@Render ('dashboard')
getDashboard () {
const sites = this.usersSitesService.selectSitesByUserId(1);
return { sites };
}
selectSitesByUserId = async (id: number): Promise<any> => {
const res = await this.sitesRepository.createQueryBuilder('s')
.leftJoin('usites', 'u', 's.id = u.site_id')
.where('u.user_id =:id', {id: id}).getMany();
return res;
}
<ul class="nav nav-treeview">
<% for(let i = 0; i < sites.length; i++) { %>
<li class="nav-item">
<a href="/dashboard/sites/?siteId=<%= sites[i].id %>" class="nav-link">
<p><%= sites[i].siteName %></p>
</a>
</li>
<% } %>
</ul>
Answer the question
In order to leave comments, you need to log in
And who will wait for the asynchronous action?
@Controller()
@Get('/dashboard')
@Render ('dashboard')
async getDashboard () {
const sites = await this.usersSitesService.selectSitesByUserId(1);
return { sites };
}
What's the point of a typescript if you writeselectSitesByUserId = async (id: number): Promise<any>
any
?Repo with docker router-controller https://github-com.translate.goog/typestack/routin...Link to machine translation? Are you serious?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question