Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Register Action
- exports.create = (req, res) => {
- const today = new Date();
- User.findOne({
- where: { login: req.body.login },
- }).then(user => {
- if (!user) {
- bcrypt.hash(req.body.password, 10, (err, hash) => {
- req.body.password = hash;
- User.create({
- login: req.body.login,
- password: req.body.password,
- name: req.body.name,
- surname: req.body.surname,
- email: req.body.email,
- date_registration: today,
- })
- .then(user =>
- // ! TODO: If account_bill exist
- Bill.create({
- id_owner: user.id,
- account_bill: `022232${Math.floor(
- Math.random() * 90000000000000000000,
- ) + 10000000000000000000}`,
- available_funds: 0,
- }).then(account => {
- res.status(200).json({ register: true });
- }),
- )
- .catch(err => {
- res.status(400).json({ error: 'Register failed.' });
- });
- });
- } else {
- res.status(400).json({ error: 'User already exists.' });
- }
- });
- };
Add Comment
Please, Sign In to add comment