mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Added username invite
This commit is contained in:
@@ -356,23 +356,17 @@ schema.statics.toJSONCleanChat = async function groupToJSONCleanChat (group, use
|
||||
return toJSON;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks invitation uuids and emails for possible errors.
|
||||
*
|
||||
* @param uuids An array of user ids
|
||||
* @param emails An array of emails
|
||||
* @param res Express res object for use with translations
|
||||
* @throws BadRequest An error describing the issue with the invitations
|
||||
*/
|
||||
schema.statics.validateInvitations = async function getInvitationError (uuids, emails, res, group = null) {
|
||||
let uuidsIsArray = Array.isArray(uuids);
|
||||
let emailsIsArray = Array.isArray(emails);
|
||||
let emptyEmails = emailsIsArray && emails.length < 1;
|
||||
let emptyUuids = uuidsIsArray && uuids.length < 1;
|
||||
function getIniviteError (uuids, emails, usernames) {
|
||||
const uuidsIsArray = Array.isArray(uuids);
|
||||
const emailsIsArray = Array.isArray(emails);
|
||||
const usernamesIsArray = Array.isArray(usernames);
|
||||
const emptyEmails = emailsIsArray && emails.length < 1;
|
||||
const emptyUuids = uuidsIsArray && uuids.length < 1;
|
||||
const emptyUsernames = usernamesIsArray && usernames.length < 1;
|
||||
|
||||
let errorString;
|
||||
|
||||
if (!uuids && !emails) {
|
||||
if (!uuids && !emails && !usernames) {
|
||||
errorString = 'canOnlyInviteEmailUuid';
|
||||
} else if (uuids && !uuidsIsArray) {
|
||||
errorString = 'uuidsMustBeAnArray';
|
||||
@@ -386,10 +380,12 @@ schema.statics.validateInvitations = async function getInvitationError (uuids, e
|
||||
errorString = 'inviteMustNotBeEmpty';
|
||||
}
|
||||
|
||||
if (errorString) {
|
||||
throw new BadRequest(res.t(errorString));
|
||||
}
|
||||
if (usernames && emptyUsernames) errorString = 'usernamesMustNotBeEmpty';
|
||||
|
||||
return errorString;
|
||||
}
|
||||
|
||||
function getInviteCount (uuids, emails) {
|
||||
let totalInvites = 0;
|
||||
|
||||
if (uuids) {
|
||||
@@ -400,6 +396,28 @@ schema.statics.validateInvitations = async function getInvitationError (uuids, e
|
||||
totalInvites += emails.length;
|
||||
}
|
||||
|
||||
return totalInvites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks invitation uuids and emails for possible errors.
|
||||
*
|
||||
* @param uuids An array of user ids
|
||||
* @param emails An array of emails
|
||||
* @param res Express res object for use with translations
|
||||
* @throws BadRequest An error describing the issue with the invitations
|
||||
*/
|
||||
schema.statics.validateInvitations = async function getInvitationError (invites, res, group = null) {
|
||||
const {
|
||||
uuids,
|
||||
emails,
|
||||
usernames,
|
||||
} = invites;
|
||||
|
||||
const errorString = getIniviteError(uuids, emails, usernames);
|
||||
if (errorString) throw new BadRequest(res.t(errorString));
|
||||
|
||||
const totalInvites = getInviteCount(uuids, emails);
|
||||
if (totalInvites > INVITES_LIMIT) {
|
||||
throw new BadRequest(res.t('canOnlyInviteMaxInvites', {maxInvites: INVITES_LIMIT}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user