问题描述
我正在尝试根据对象的元素进行Typeorm查询,但是forEach
和异步函数存在问题。
我读过很多类似的文章,但是没有人为我工作。
这是我的代码段,forEach
中不允许等待:
public async runBudgetLimit(): Promise<void> {
const contracts: ContractEntity[] = await this.contractService.getAllProjects();
contracts.forEach((contract) => {
const project: UserEntity = await this.userService.findOne(contract.milestoneId);
const date: string = Time.moment().format('YYYY-MM-DD');
const budgetUsed = this.trackService.getBillingByProject(project.contractId,date,'1000',true);
});
}
这是异步Typeorm查询:
async findOne(id: string): Promise<UserEntity | undefined> {
return this.userRepository.findOne(id);
}
我不知道什么是解决此问题的最佳解决方案,我不认为for循环是一个好的解决方案,但我对所有解决方案持开放态度。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)