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');
|
var crypto = require('crypto');
|
||||||
const passport = require('passport');
|
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) => {
|
module.exports.authenticate = asyncHandler(async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
passport.authenticate('headerapikey', { session: false }, function (err, application, info) {
|
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) => {
|
module.exports.createUser = asyncHandler(async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
fieldValidation(req.body.user.username, next);
|
fieldValidation(req.body.user.username, next);
|
||||||
fieldValidation(req.body.user.email, next);
|
fieldValidation(req.body.user.email, next);
|
||||||
fieldValidation(req.body.user.password, 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) => {
|
module.exports.getAllUsers = asyncHandler(async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const users = await UserService.getAllUsers();
|
const users = await UserService.getAllUsers();
|
||||||
@@ -107,8 +83,7 @@ module.exports.getUser = asyncHandler(async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
user: user.toAuthJSON(),
|
user: user.toAuthJSON()
|
||||||
uuid: crypto.randomUUID()
|
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
|
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ var HWClanSchema = new mongoose.Schema({
|
|||||||
title: String,
|
title: String,
|
||||||
topActivity: String,
|
topActivity: String,
|
||||||
topDungeon: String,
|
topDungeon: String,
|
||||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
author: { type: mongoose.Schema.Types.UUID, ref: 'User' }
|
||||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||||
|
|
||||||
HWClanSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
HWClanSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ var HWMemberSchema = new mongoose.Schema({
|
|||||||
scoreGifts: Number,
|
scoreGifts: Number,
|
||||||
warGifts: Number,
|
warGifts: Number,
|
||||||
rewards: Number,
|
rewards: Number,
|
||||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
author: { type: mongoose.Schema.Types.UUID, ref: 'User' }
|
||||||
}, {timestamps: true, toJSON: {virtuals: true}});
|
}, {timestamps: true, toJSON: {virtuals: true}});
|
||||||
|
|
||||||
HWMemberSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
HWMemberSchema.plugin(uniqueValidator, { message: 'is already taken' });
|
||||||
|
|||||||
Reference in New Issue
Block a user