forked from hagopj13/node-express-boilerplate
-
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.
- Loading branch information
Showing
8 changed files
with
63 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
module.exports.authController = require('../controllers/auth.controller'); | ||
module.exports.userController = require('../controllers/user.controller'); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const httpStatus = require('http-status'); | ||
const catchAsync = require('../utils/catchAsync'); | ||
const { userService } = require('../services'); | ||
|
||
const createUser = catchAsync(async (req, res) => { | ||
const user = await userService.createUser(req.body); | ||
const response = user.transform(); | ||
res.status(httpStatus.CREATED).send(response); | ||
}); | ||
|
||
module.exports = { | ||
createUser, | ||
}; |
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,8 +1,10 @@ | ||
const express = require('express'); | ||
const authRoute = require('./auth.route'); | ||
const userRoute = require('./user.route'); | ||
|
||
const router = express.Router(); | ||
|
||
router.use('/auth', authRoute); | ||
router.use('/users', userRoute); | ||
|
||
module.exports = router; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const express = require('express'); | ||
const validate = require('../../middlewares/validate'); | ||
const userValidation = require('../../validations/user.validation'); | ||
const userController = require('../../controllers/user.controller'); | ||
|
||
const router = express.Router(); | ||
|
||
router.route('/').post(validate(userValidation.createUser), userController.createUser); | ||
|
||
module.exports = router; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const validatePassword = (value, helpers) => { | ||
if (value.length < 8) { | ||
return helpers.message('Password must be at least 8 characters'); | ||
} | ||
if (!value.match(/\d/) || !value.match(/[a-zA-Z]/)) { | ||
return helpers.message('Password must contain at least 1 letter and 1 number'); | ||
} | ||
return value; | ||
}; | ||
|
||
module.exports = { | ||
validatePassword, | ||
}; |
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 +1,2 @@ | ||
module.exports.authValidation = require('./auth.validation'); | ||
module.exports.userValidation = require('./user.validation'); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const Joi = require('@hapi/joi'); | ||
const validationUtils = require('../utils/validation.util'); | ||
|
||
const createUser = { | ||
body: Joi.object().keys({ | ||
email: Joi.string() | ||
.required() | ||
.email(), | ||
password: Joi.string() | ||
.required() | ||
.custom(validationUtils.validatePassword), | ||
name: Joi.string().required(), | ||
role: Joi.string() | ||
.required() | ||
.valid('user', 'admin'), | ||
}), | ||
}; | ||
|
||
module.exports = { | ||
createUser, | ||
}; |