Controller and Model updates
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
const { UserService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
module.exports.addFollowUser = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
return res.status(200).json({
|
||||
message: 'The user is now being followed.'
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while following a user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.deleteFollowUser = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
return res.status(200).json({
|
||||
message: 'The user is no longer being followed.',
|
||||
user: true
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while unfollowing a user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.getProfile = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
console.log(req.profile)
|
||||
/*const user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
return next(new ErrorResponse("Unauthorized", 401, "Authentication required."));
|
||||
}*/
|
||||
res.status(200).json({
|
||||
user: req.profile.toProfileJSONFor()
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.getParamUsername = async (req, res, next, value) => {
|
||||
try {
|
||||
const user = await UserService.getUserByUsername(value);
|
||||
if (!user) {
|
||||
return next(new ErrorResponse("User not found", 404));
|
||||
}
|
||||
req.profile = user;
|
||||
return next();
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
|
||||
}
|
||||
};
|
||||
@@ -4,18 +4,6 @@ const ErrorResponse = require("../utils/errorResponse");
|
||||
var crypto = require('crypto');
|
||||
const passport = require('passport');
|
||||
|
||||
|
||||
module.exports.addFollowUser = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
return res.status(200).json({
|
||||
message: 'The user is now being followed.',
|
||||
user: true
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while following a user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.authenticate = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
passport.authenticate('headerapikey', { session: false }, function (err, application, info) {
|
||||
@@ -44,7 +32,6 @@ module.exports.authenticate = asyncHandler(async (req, res, next) => {
|
||||
|
||||
module.exports.createUser = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
|
||||
fieldValidation(req.body.user.username, next);
|
||||
fieldValidation(req.body.user.email, next);
|
||||
fieldValidation(req.body.user.password, next);
|
||||
@@ -76,17 +63,6 @@ module.exports.createUser = asyncHandler(async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.deleteFollowUser = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
return res.status(200).json({
|
||||
message: 'The user is no longer being followed.',
|
||||
user: true
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while unfollowing a user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.getAllUsers = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
const users = await UserService.getAllUsers();
|
||||
@@ -107,8 +83,7 @@ module.exports.getUser = asyncHandler(async (req, res, next) => {
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
user: user.toAuthJSON(),
|
||||
uuid: crypto.randomUUID()
|
||||
user: user.toAuthJSON()
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
|
||||
|
||||
Reference in New Issue
Block a user