title: TypeScript CRUD route
body: <p>I am working on a CRUD implementation for a user.</p>
  
  <p>I have a user class, users consists of first name, username, surname and password:</p>
  
  <pre><code>class User {
      public readonly uName: string;
      public fName: string;
      public lName: string;
      private password: string;
  
      constructor(fName: string, lName: string, uName: string, password: string) {
          this.fName = fName;
          this.lName = lName;
          this.uName = uName;
          this.password = password;
      }
  }
  
  let Users: User[];
  Users = [];
  </code></pre>
  
  <p>I already have something that compares entered data and inserts it:</p>
  
  <pre><code>router.post("/nutzer?", (req: express.Request, res: express.Response)=&gt;{
      const fName: string = req.body.fName;
      const lName: string = req.body.lName;
      const uName: string = req.body.uName;
      const password: string = req.body.password;
  
      if (fName &amp;&amp; lName &amp;&amp; uName &amp;&amp; password) {
          let neuerUser = new User(fName, lName, uName, password);
          Users.push(neuerUser);
          res.status(201);
          res.send({
              neuerUser,
              message: 'Nutzer erstellt'
          });
      } else {
          res.status(400);
          res.send({
              message: 'alle Felder müssen ausgefüllt sein',
          });
      }
  });
  </code></pre>
  
  <p>However, I have a problem with the read/update/delete</p>
  
  <h2>Read</h2>
  
  <p>The route spits out only the first one from the array and does not look for the current one that I have in the url</p>
  
  <pre><code>router.get('/nutzer/:uName?', (req: express.Request, res: express.Response) =&gt; {
      const uName: string = req.params.uName;
      for (let User of Users) {
          if (User.uName === uName) {
             res.status(200);
                 res.send({
                  User,
                  message: 'Nutzer gefunden',
              });
          }else{
              res.status(404);
                  res.send({
                  message: 'Nutzer nicht gefunden',
              });
          }
      }
  });
  </code></pre>
  
  <p>Edit user PUT does not work from front to back.</p>
  
  <pre><code>router.put('/nutzer/:uName?', (req: express.Request, res: express.Response)=&gt; {
      const uName: string = req.params.userId;
      const fName: string = req.body.firstName;
      const lName: string = req.body.lastName;
  
      if (fName &amp;&amp; lName) {
          for (const user of Users) {
              if (uName === req.params.uName) {
                  user.fName = fName;
                  user.lName = lName;
                  res.status(200);
                  res.send({
                      user,
                      message: `Nutzer erfolgreich ugedatet ${user.fName} ${user.lName}`
                  });
              }else{
                  res.status(400).send({
                  message: 'Nutzerupdate nicht gefunden'
              });
              }
          }
      }
  });
  </code></pre>
  
  <p>Delete user DELETE only deletes the first user in the array</p>
  
  <pre><code>router.delete("/nutzer/:uName?", (req: express.Request, res: express.Response) =&gt; {
                      const uName: string = req.params.uName;
                      if (uName === req.params.uName) {
                          //nicht
                          Users.splice(Users.indexOf(uName), 1);
                          res.status(200);
                          res.send({
                              message: 'Benutzer gelöscht'});
                      } else {
                          res.status(404);
                          res.send({
                              message: 'Benutzer nicht gefunden'});
                      }
                  });
  </code></pre>