mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
📂Better folder structures and file names in backend
This commit is contained in:
25
backend/src/controllers/UserController.js
Normal file
25
backend/src/controllers/UserController.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { validationResult } = require("express-validator");
|
||||
const bcrypt = require("bcryptjs");
|
||||
|
||||
const User = require("../models/User");
|
||||
|
||||
exports.store = async (req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: "Validation failed", data: errors.array() });
|
||||
}
|
||||
|
||||
const { name, password, email } = req.body;
|
||||
|
||||
const hashedPw = await bcrypt.hash(password, 12);
|
||||
const user = User.build({
|
||||
email: email,
|
||||
password: hashedPw,
|
||||
name: name,
|
||||
});
|
||||
const result = await user.save();
|
||||
res.status(201).json({ message: "User created!", userId: result.id });
|
||||
};
|
||||
Reference in New Issue
Block a user