-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from victorsoares96/feat/celebrate
feat: celebrate
- Loading branch information
Showing
18 changed files
with
363 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"config:base" | ||
] | ||
"extends": ["config:base"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
import { Router } from 'express'; | ||
import { celebrate, Joi, Segments } from 'celebrate'; | ||
import { AuthenticateController } from '@/controllers/authenticate.controller'; | ||
|
||
export const authenticateRouter = Router(); | ||
const authenticateController = new AuthenticateController(); | ||
|
||
authenticateRouter.post('/auth', authenticateController.execute); | ||
authenticateRouter.post( | ||
'/auth', | ||
celebrate({ | ||
[Segments.BODY]: Joi.object().keys({ | ||
username: Joi.string().required().messages({ | ||
'string.base': 'Username must be a string.', | ||
'any.required': 'Username is required.', | ||
}), | ||
password: Joi.string().required().messages({ | ||
'string.base': 'Password must be a string.', | ||
'any.required': 'Password is required.', | ||
}), | ||
}), | ||
}), | ||
authenticateController.execute, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,152 @@ | ||
import { Router } from 'express'; | ||
import { celebrate, Segments, Joi } from 'celebrate'; | ||
import ensureAuthenticated from '@/middlewares/ensureAuthenticated.middleware'; | ||
import { UsersController } from '../controllers/user.controller'; | ||
import { passwordRule } from '@/utils/validators.util'; | ||
|
||
export const usersRouter = Router(); | ||
const usersController = new UsersController(); | ||
|
||
usersRouter.get('/users', ensureAuthenticated, usersController.index); | ||
usersRouter.get( | ||
'/users', | ||
celebrate({ | ||
[Segments.BODY]: Joi.object().keys({ | ||
name: Joi.string().messages({ | ||
'string.base': 'Name must be a string.', | ||
}), | ||
username: Joi.string().messages({ | ||
'string.base': 'Username must be a string.', | ||
}), | ||
email: Joi.string().messages({ | ||
'string.base': 'Email must be a string.', | ||
}), | ||
isDeleted: Joi.boolean().messages({ | ||
'boolean.base': 'isDeleted must be a boolean.', | ||
}), | ||
offset: Joi.number().messages({ | ||
'number.base': 'Offset must be a number.', | ||
}), | ||
isAscending: Joi.boolean().messages({ | ||
'boolean.base': 'isAscending must be a boolean.', | ||
}), | ||
limit: Joi.number().messages({ | ||
'number.base': 'Limit must be a number.', | ||
}), | ||
}), | ||
}), | ||
ensureAuthenticated, | ||
usersController.index, | ||
); | ||
|
||
usersRouter.post('/users', /* ensureAuthenticated, */ usersController.create); | ||
usersRouter.post( | ||
'/users', | ||
celebrate({ | ||
[Segments.BODY]: Joi.object().keys({ | ||
name: Joi.string().required().messages({ | ||
'string.base': 'Name must be a string.', | ||
'any.required': 'Name is required.', | ||
}), | ||
username: Joi.string().required().messages({ | ||
'string.base': 'Username must be a string.', | ||
'any.required': 'Username is required.', | ||
}), | ||
email: Joi.string().email().required().messages({ | ||
'string.base': 'Email must be a string.', | ||
'any.required': 'Email is required.', | ||
'string.email': 'Email is invalid.', | ||
}), | ||
password: Joi.string().regex(passwordRule).required().messages({ | ||
'string.base': 'Password must be a string.', | ||
'any.required': 'Password is required.', | ||
'string.pattern.base': | ||
'Password must be at least 8 characters, at least 1 uppercase letter, 1 lowercase letter, 1 number and 1 special character.', | ||
}), | ||
}), | ||
}), | ||
usersController.create, | ||
); | ||
|
||
usersRouter.put('/users', ensureAuthenticated, usersController.update); | ||
usersRouter.put( | ||
'/users', | ||
celebrate({ | ||
[Segments.BODY]: Joi.object().keys({ | ||
id: Joi.string().required().messages({ | ||
'string.base': 'Id must be a string.', | ||
'any.required': 'The user id must be provided.', | ||
}), | ||
name: Joi.string().messages({ | ||
'string.base': 'Name must be a string.', | ||
}), | ||
email: Joi.string().email().messages({ | ||
'string.email': 'Email is invalid.', | ||
}), | ||
}), | ||
}), | ||
ensureAuthenticated, | ||
usersController.update, | ||
); | ||
|
||
usersRouter.delete( | ||
'/users/remove', | ||
celebrate({ | ||
[Segments.BODY]: Joi.object().keys({ | ||
ids: Joi.string().required().messages({ | ||
'string.base': 'Ids must be a string.', | ||
'any.required': 'The user(s) id(s) must be provided.', | ||
}), | ||
}), | ||
}), | ||
ensureAuthenticated, | ||
usersController.remove, | ||
); | ||
|
||
usersRouter.patch('/users/password', usersController.resetPassword); | ||
usersRouter.delete( | ||
'/users/soft-remove', | ||
celebrate({ | ||
[Segments.BODY]: Joi.object().keys({ | ||
ids: Joi.string().required().messages({ | ||
'string.base': 'Ids must be a string.', | ||
'any.required': 'The user(s) id(s) must be provided.', | ||
}), | ||
}), | ||
}), | ||
ensureAuthenticated, | ||
usersController.softRemove, | ||
); | ||
|
||
usersRouter.patch( | ||
'/users/recover', | ||
celebrate({ | ||
[Segments.BODY]: Joi.object().keys({ | ||
ids: Joi.string().required().messages({ | ||
'string.base': 'Ids must be a string.', | ||
'any.required': 'The user(s) id(s) must be provided.', | ||
}), | ||
}), | ||
}), | ||
ensureAuthenticated, | ||
usersController.recover, | ||
); | ||
|
||
usersRouter.patch( | ||
'/users/password', | ||
celebrate({ | ||
[Segments.BODY]: Joi.object().keys({ | ||
id: Joi.string().required().messages({ | ||
'string.base': 'Id must be a string.', | ||
'any.required': 'The user id must be provided.', | ||
}), | ||
currentPassword: Joi.string().required().messages({ | ||
'string.base': 'Current password must be a string.', | ||
'any.required': 'The current password must be provided.', | ||
}), | ||
newPassword: Joi.string().regex(passwordRule).required().messages({ | ||
'string.base': 'New password must be a string.', | ||
'any.required': 'The new password must be provided.', | ||
'string.pattern.base': | ||
'Password must be at least 8 characters, at least 1 uppercase letter, 1 lowercase letter, 1 number and 1 special character.', | ||
}), | ||
}), | ||
}), | ||
usersController.resetPassword, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.