title: How to correctly update an entity with express and typeorm
body: <p>I'm looking for the best way to update a <code>User</code> entity with typeorm and express.</p>
  
  <p>I have something like this (I have reduced, but there are many other attributes) :</p>
  
  <pre class="lang-js prettyprint-override"><code>class User {
    id: string;
    lastname: string;
    firstname: string;
    email: string;
    password: string;
    isAdmin: boolean;
  }
  </code></pre>
  
  <p>And I have a path to update user's attributes like :   </p>
  
  <pre class="lang-js prettyprint-override"><code>app.patch("/users/me", ensureAuthenticated, UserController.update);
  </code></pre>
  
  <p>Now (and it's my question), how to properly update the user? I don't want the user to be able to add themselves as an admin.</p>
  
  <p>So I have : </p>
  
  <pre class="lang-js prettyprint-override"><code>export const update = async (req: Request, res: Response) =&gt; {
    const { sub } = res.locals.token;
    const { lastname, firstname, phone, email } = req.body;
  
    const userRepository = getRepository(User);
    const currentUser = await userRepository.findOne({ id: sub });
  
    const newUserData: User = {
      ...currentUser,
      lastname: lastname || currentUser.lastname,
      firstname: firstname || currentUser.firstname,
      phone: phone || currentUser.phone,
      email: email || currentUser.email
    };
  
    await userRepository
      .update({ id: sub }, newUserData)
      .then(r =&gt; {
        return res.status(204).send();
      })
      .catch(err =&gt; {
        logger.error(err);
        return res.status(500).json({ error: "Error." });
      });
  };
  </code></pre>
  
  <p>With that, I'm sure to update the right attributes, and the user can't update admin. 
  But I find it very verbose to create a new object and fill in the informations.</p>
  
  <p>Do you have a better way to do it?
  Thanks.</p>