Guest User

Untitled

a guest
Jan 13th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. // Register Action
  2. exports.create = (req, res) => {
  3. const today = new Date();
  4.  
  5. User.findOne({
  6. where: { login: req.body.login },
  7. }).then(user => {
  8. if (!user) {
  9. bcrypt.hash(req.body.password, 10, (err, hash) => {
  10. req.body.password = hash;
  11.  
  12. User.create({
  13. login: req.body.login,
  14. password: req.body.password,
  15. name: req.body.name,
  16. surname: req.body.surname,
  17. email: req.body.email,
  18. date_registration: today,
  19. })
  20. .then(user =>
  21. // ! TODO: If account_bill exist
  22. Bill.create({
  23. id_owner: user.id,
  24. account_bill: `022232${Math.floor(
  25. Math.random() * 90000000000000000000,
  26. ) + 10000000000000000000}`,
  27. available_funds: 0,
  28. }).then(account => {
  29. res.status(200).json({ register: true });
  30. }),
  31. )
  32. .catch(err => {
  33. res.status(400).json({ error: 'Register failed.' });
  34. });
  35. });
  36. } else {
  37. res.status(400).json({ error: 'User already exists.' });
  38. }
  39. });
  40. };
Add Comment
Please, Sign In to add comment