SHARE
TWEET

Untitled

a guest Aug 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //query
  3. users.update = (id_user, name_user, address_user) => {
  4.     return new Promise(( resolve, reject ) => {
  5.         db.query('UPDATE users SET name_user = name_user WHERE name_user = ?"',
  6.         {  
  7.             id_user: id_user,      
  8.             name_user: name_user,
  9.             address_user: address_user
  10.         },
  11.         (err, results) => {
  12.             if (err) {
  13.                 console.log(err)
  14.                 return reject({ message: 'Invalid data', error: true })
  15.             }
  16.         return resolve({ message: 'Data has been updated successfully.', error: false, data:results.affectedRows })
  17.      })
  18.     })
  19. }
  20. //router
  21. router.put('/:id', async (req, res) => {
  22.     try{
  23.         let id = req.params.id_user
  24.         let response = await db.update(id,req.body.name_user, req.body.address_user)
  25.         res.json(response)
  26.     }catch(e) {
  27.         console.log(e)
  28.         res.sendStatus(500)
  29.     }
  30. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top