mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
fix edge case where res.respond would not work, misc comments
This commit is contained in:
@@ -146,6 +146,7 @@ api.getChallenge = {
|
||||
let challenge = await Challenge.findOne({_id: challengeId}).exec(); // TODO populate
|
||||
|
||||
// If the challenge does not exist, or if it exists but user is not a member, not the leader and not an admin -> throw error
|
||||
// TODO support challenges in groups I'm a member of
|
||||
if (!challenge || (user.challenges.indexOf(challengeId) === -1 && challenge.leader !== user._id && !user.contributor.admin)) { // eslint-disable-line no-extra-parens
|
||||
throw new NotFound(res.t('challengeNotFound'));
|
||||
}
|
||||
|
||||
@@ -100,13 +100,13 @@ api.getGroups = {
|
||||
type: 'guild',
|
||||
privacy: 'private',
|
||||
_id: {$in: user.guilds},
|
||||
}).select(groupFields).sort(sort).exec()); // TODO isMember
|
||||
}).select(groupFields).sort(sort).exec());
|
||||
break;
|
||||
case 'publicGuilds':
|
||||
queries.push(Group.find({
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
}).select(groupFields).sort(sort).exec()); // TODO use lean? isMember
|
||||
}).select(groupFields).sort(sort).exec()); // TODO use lean?
|
||||
break;
|
||||
case 'tavern':
|
||||
queries.push(Group.getGroup(user, 'habitrpg', groupFields));
|
||||
|
||||
@@ -74,5 +74,7 @@ export default function errorHandler (err, req, res, next) { // eslint-disable-l
|
||||
|
||||
if (responseErr.errors) jsonRes.errors = responseErr.errors;
|
||||
|
||||
return res.respond(responseErr.httpCode, jsonRes);
|
||||
// In some occasions like when invalid JSON is supplied `res.respond` might be not yet avalaible,
|
||||
// in this case we use the standard res.status(...).json(...)
|
||||
return res.respond ? res.respond(responseErr.httpCode, jsonRes) : res.status(responseErr.httpCode).json(jsonRes);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,6 @@ schema.statics.getGroup = function getGroup (user, groupId, fields, optionalMemb
|
||||
// TODO purge chat flags info? in tojson?
|
||||
};
|
||||
|
||||
// TODO move to its own model
|
||||
export function chatDefaults (msg, user) {
|
||||
let message = {
|
||||
id: shared.uuid(),
|
||||
|
||||
Reference in New Issue
Block a user