mirror of
https://gitlab.com/little-lines/backend.git
synced 2025-07-07 13:31:05 +00:00
create userHandler
This commit is contained in:
parent
f1f614d4e7
commit
cdd52920dc
4 changed files with 14 additions and 13 deletions
|
@ -11,21 +11,26 @@ const getAllUser = asyncHandler(async (req, res) => {
|
|||
// Create new user => POST api/users/create
|
||||
const createUser = asyncHandler(async (req, res) => {
|
||||
try {
|
||||
const { username,
|
||||
password,
|
||||
email,
|
||||
isGoogleAccount } = req.body;
|
||||
const { username, password, email, isGoogleAccount } = req.body;
|
||||
|
||||
const users = await user.create({
|
||||
const newUser = await user.create({
|
||||
username,
|
||||
password,
|
||||
email,
|
||||
isGoogleAccount
|
||||
});
|
||||
|
||||
res.status(200).json(users);
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
// Respond with the newly created user
|
||||
res.status(201).json(newUser);
|
||||
} catch (err) {
|
||||
// Handle validation errors
|
||||
if (err.name === 'ValidationError') {
|
||||
console.error(err);
|
||||
return res.status(400).json({ error: err.message });
|
||||
}
|
||||
|
||||
console.error(err);
|
||||
res.status(500).json({ error: 'An error occurred while creating the user.' });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue