-
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
takuyadev
committed
Nov 4, 2022
1 parent
da74a38
commit 2025183
Showing
14 changed files
with
332 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const ErrorResponse = require('../utils/errorResponse'); | ||
const asyncHandler = require('../middleware/async'); | ||
const User = require('../model/User'); | ||
|
||
// @desc Get all users | ||
// @route GET /api/v1/users | ||
// @access Private/Admin | ||
exports.getUsers = asyncHandler(async (req, res, next) => { | ||
res.status(200).json(res.advancedResults); | ||
}); | ||
|
||
// @desc Get single user | ||
// @route GET /api/v1/users/:id | ||
// @access Private/Admin | ||
exports.getUser = asyncHandler(async (req, res, next) => { | ||
const user = await User.findById(req.params.id); | ||
|
||
res.status(200).json({ | ||
success: true, | ||
data: user | ||
}); | ||
}); | ||
|
||
// @desc Create user | ||
// @route POST /api/v1/users | ||
// @access Private/Admin | ||
exports.createUser = asyncHandler(async (req, res, next) => { | ||
const user = await User.create(req.body); | ||
|
||
res.status(201).json({ | ||
success: true, | ||
data: user | ||
}); | ||
}); | ||
|
||
// @desc Update user | ||
// @route PUT /api/v1/users/:id | ||
// @access Private/Admin | ||
exports.updateUser = asyncHandler(async (req, res, next) => { | ||
const user = await User.findByIdAndUpdate(req.params.id, req.body, { | ||
new: true, | ||
runValidators: true | ||
}); | ||
|
||
res.status(200).json({ | ||
success: true, | ||
data: user | ||
}); | ||
}); | ||
|
||
// @desc Delete user | ||
// @route DELETE /api/v1/users/:id | ||
// @access Private/Admin | ||
exports.deleteUser = asyncHandler(async (req, res, next) => { | ||
await User.findByIdAndDelete(req.params.id); | ||
|
||
res.status(200).json({ | ||
success: true, | ||
data: {} | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.