Skip to content

Commit 2679d92

Browse files
author
Victor
committed
chore: add an email validation before creating a user
1 parent f1f3a52 commit 2679d92

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/controllers/UserController.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class UserController {
99

1010
async create(request, response) {
1111
const { name, email } = request.body;
12+
const result = await User.find({ where: { email } });
13+
const userFoundByEmail = result[0];
14+
15+
if (userFoundByEmail)
16+
return response.status(400).json({ error: 'Email already exists!' });
17+
1218
const user = await User.create({ name, email });
1319

1420
return response.status(201).json(user);

0 commit comments

Comments
 (0)