initial commit
This commit is contained in:
34
controllers/user.controller.js
Normal file
34
controllers/user.controller.js
Normal file
@@ -0,0 +1,34 @@
|
||||
var { User, Class } = require("../models/models");
|
||||
var { hashSync } = require("bcryptjs");
|
||||
|
||||
async function getSingleUser(req, res, next) {
|
||||
try {
|
||||
let user = await User.findByPk(parseInt(req.params.id));
|
||||
if (user) {
|
||||
res.json(user);
|
||||
} else {
|
||||
res.status(404).end();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).end();
|
||||
}
|
||||
}
|
||||
|
||||
async function createSingleUser(req, res, next) {
|
||||
try {
|
||||
let user = await User.create({
|
||||
username: req.fields.username,
|
||||
password: hashSync(req.fields.password, 15)
|
||||
});
|
||||
res.json(user);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).end();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createSingleUser,
|
||||
getSingleUser
|
||||
};
|
||||
Reference in New Issue
Block a user