Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions server/services/user-service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {v4 as uuidv4} from 'uuid';
const bcrypt = require('bcrypt')
const User = require('../models/user-model')
const Role = require('../models/role-model')
Expand All @@ -15,13 +16,19 @@ class UserService {
if (password !== rePassword) {
throw new Error({status: 400, message: 'Паролі не співпадають.'})
}
let uniq_id = uuid4();
let uniq_key = await User.findOne({uniq_id});
while(uniq_key) {
uniq_id = uuid4();
uniq_key = await User.findOne({uniq_id});
}
const hashPassword = await bcrypt.hash(password, 5)
const {value} = new Role({value: role})
const user = new User({email, fullName, login, password: hashPassword, role: value})
const user = new User({email, fullName, login, password: hashPassword, role: value, uniq_key: uniq_id})
return await user.save()
}
async updateUser () {}
async deleteUser () {}
}

module.exports = new UserService()
module.exports = new UserService()