mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
feat(usernames): invite by username
This commit is contained in:
@@ -17,9 +17,9 @@ import {
|
||||
import { removeFromArray } from '../../libs/collectionManipulators';
|
||||
import { sendTxn as sendTxnEmail } from '../../libs/email';
|
||||
import {
|
||||
_inviteByUUID,
|
||||
_inviteByEmail,
|
||||
_inviteByUserName,
|
||||
inviteByUUID,
|
||||
inviteByEmail,
|
||||
inviteByUserName,
|
||||
} from '../../libs/invites';
|
||||
import common from '../../../common';
|
||||
import payments from '../../libs/payments/payments';
|
||||
@@ -1038,13 +1038,13 @@ api.inviteToGroup = {
|
||||
const results = [];
|
||||
|
||||
if (uuids) {
|
||||
const uuidInvites = uuids.map((uuid) => _inviteByUUID(uuid, group, user, req, res));
|
||||
const uuidInvites = uuids.map((uuid) => inviteByUUID(uuid, group, user, req, res));
|
||||
const uuidResults = await Promise.all(uuidInvites);
|
||||
results.push(...uuidResults);
|
||||
}
|
||||
|
||||
if (emails) {
|
||||
const emailInvites = emails.map((invite) => _inviteByEmail(invite, group, user, req, res));
|
||||
const emailInvites = emails.map((invite) => inviteByEmail(invite, group, user, req, res));
|
||||
user.invitesSent += emails.length;
|
||||
await user.save();
|
||||
const emailResults = await Promise.all(emailInvites);
|
||||
@@ -1052,7 +1052,7 @@ api.inviteToGroup = {
|
||||
}
|
||||
|
||||
if (usernames) {
|
||||
const usernameInvites = usernames.map((username) => _inviteByUserName(username, group, user, req, res));
|
||||
const usernameInvites = usernames.map((username) => inviteByUserName(username, group, user, req, res));
|
||||
const usernameResults = await Promise.all(usernameInvites);
|
||||
results.push(...usernameResults);
|
||||
}
|
||||
|
||||
@@ -119,6 +119,33 @@ api.getMember = {
|
||||
},
|
||||
};
|
||||
|
||||
api.getMemberByUsername = {
|
||||
method: 'GET',
|
||||
url: '/members/username/:username',
|
||||
middlewares: [],
|
||||
async handler (req, res) {
|
||||
req.checkParams('username', res.t('invalidReqParams')).notEmpty();
|
||||
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let username = req.params.username.toLowerCase();
|
||||
|
||||
let member = await User
|
||||
.findOne({'auth.local.lowerCaseUsername': username})
|
||||
.select(memberFields)
|
||||
.exec();
|
||||
|
||||
if (!member || !member.flags.verifiedUsername) throw new NotFound(res.t('userNotFound'));
|
||||
|
||||
// manually call toJSON with minimize: true so empty paths aren't returned
|
||||
let memberToJSON = member.toJSON({minimize: true});
|
||||
User.addComputedStatsToJSONObj(memberToJSON.stats, member);
|
||||
|
||||
res.respond(200, memberToJSON);
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {get} /api/v3/members/:memberId/achievements Get member achievements object
|
||||
* @apiName GetMemberAchievements
|
||||
|
||||
Reference in New Issue
Block a user