TypeORM: update item and return it

后端 未结 4 1455
感情败类
感情败类 2021-02-18 14:47

As far as I know, it\'s a best practice to return an item after it has been updated. TypeORM\'s updateById returns void, not the updated item though.

4条回答
  •  醉酒成梦
    2021-02-18 14:59

    I just found out that I can do this with the .save method:

    return this.taskRepository.save({
        id: task.id,
        state,
        dueDate
    });
    

    According to the docs (section save), partial updates are supported as well:

    Also supports partial updating since all undefined properties are skipped.

提交回复
热议问题