Answer the question
In order to leave comments, you need to log in
What is the correct way to return the Promise of an object?
There is a function, it returns a Promise
getTotalProducts(): Promise<number> {
return this.productsRepository.count();
}
getTestProducts(): GetTestProducts {
return {
total: this.productsService.getTotalProducts()
};
}
export interface GetTestProducts {
total: Promise<number>
}
{
"total": {}
}
Answer the question
In order to leave comments, you need to log in
Decision
async getProducts(page: number, perPage: number): Promise<getProducts> {
const products = await this.productsRepository.find({
relations: ["category", "photos"] }
);
const total = await this.productsRepository.count();
return {
products,
total
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question