TypeOrm repository preload entity while filtering

Viewed 1354

Can I call the preload method and filter the entity at the same time?

For example, here I want to filter by user id.

The reason I would need this is because I need to ensure that the user excludes only the entities that belongs to him.

async update(id: number, status: TaskStatus, user: User) {
  const existingTask = await this.taskRepository.preload({
    id: id,
    status: status,
  });

   if (!existingTask) {
    throw new NotFoundException(`Task #${id} not found`);
  }

  return this.taskRepository.save(existingTask);
}
1 Answers
Related