Nodejs Curd Insert Update Excluir


///////////////Find all Data


app.get('/api/',async(req, res) =>{
     const result = await  users.findAll();
     res.send(result);
})


app.get('/api/findbyid/:id',async(req, res) =>{
    const result = await  users.findOne({
        where:{id: req.params.id}
    });
    res.send(result);
})


app.get('/api/findone/:name',async(req, res) =>{
  //  const name = req.body.name;
  //console.log(req.params.name);
  const name= req.params;
    const result = await  users.findAll({
        where:{name: name}
    });
    res.send(result);
})


///////////////    insert new users

app.post('/api/insert/',async (req, res) =>{
    const id = req.params.id;
    const result= await users.upsert(
     {name:req.body.name,
     displayName:req.body.displayName},
      // {
      //   where: { id: id }
      // }
    );
    res.send(result);
  
/////////////   update data 

})
app.put('/api/update/:id',async (req, res) =>{
  const data = req.body.name;              /////fetch 'name' from db
  const display = req.body.displayname;    ////fetch 'displayname'
  //  const id = req.params.id; 
     users.update(
     {name:data,
     displayName:display},
      {
        where: { id: req.params.id }
      }
    );
   // res.send(result);
    res.redirect('/api');
  
})


////////////////// Delete data from database

app.delete('/api/delete/:id',async (req, res)=>{
  const result = await users.destroy({
        where: {id: req.params.id}
    })
   // res.send(result);
    res.redirect('/api')
})

Embarrassed Elephant