fork download
  1. const registerHandle = (req, res, db, bcrypt) => {
  2. const { email, name, password } = req.body;
  3. if (!email || !name || !password)
  4. return res.status(400).json('empty')
  5. const hash = bcrypt.hashSync(password, 8);
  6. db.transaction(trx => {
  7. trx.insert({
  8. hash: hash,
  9. email: email
  10. })
  11. .into('login')
  12. .returning('email')
  13. .then(loginEmail => {
  14. return trx('users')
  15. .returning('*')
  16. .insert({
  17. email: loginEmail[0],
  18. name: name,
  19. joined: new Date()
  20. })
  21. .then(user => res.json(user[0]))
  22.  
  23. })
  24. .then(trx.commit)
  25. .catch(err => res.status(400).json(err))
  26. })
  27. .catch(err => res.status(400).json(err))
  28. }
  29.  
  30. module.exports = {
  31. registerHandle: registerHandle
  32. }
Success #stdin #stdout 0.08s 29288KB
stdin
Standard input is empty
stdout
Standard output is empty