Вы передаете функцию async
в качестве обратного вызова для map()
, что приводит к массиву обещаний, но вы никогда не ждете этих .
В напротив, вы await
получаете много вещей, которые вам не нужно ждать, поскольку они не являются обещаниями, например, возвращаемое значение push
, возвращаемое значение map
или литерал массива.
Вы должны написать что-то вроде
async studentCount(@Parent() school: School): Promise<number> {
let studentIds = new Set
const programs = await this.programService.find({ schoolId: school.id })
await Promise.all(programs.map(async program => {
// ^^^^^^^^^^^^^^^^^
const cohortsWithStudents = await this.cohortService.getStudentsForCohortsByProgramId(program.id)
for (const cohort of cohortsWithStudents) {
for (const student of cohort.students) {
studentIds.add(student.id)
}
}
});
return studentIds.size
}