Save username instead of uuid (no queries necessary anymore)

This commit is contained in:
Mateus Etto
2018-02-19 00:18:29 +09:00
parent 7af71d1457
commit 477c23dd67
5 changed files with 20 additions and 40 deletions

View File

@@ -74,8 +74,7 @@ api.getChat = {
let group = await Group.getGroup({user, groupId: req.params.groupId, fields: 'chat'});
if (!group) throw new NotFound(res.t('groupNotFound'));
let toJSON = await Group.toJSONCleanChat(group, user);
res.respond(200, toJSON.chat);
res.respond(200, Group.toJSONCleanChat(group, user).chat);
},
};
@@ -195,8 +194,7 @@ api.postChat = {
}
if (chatUpdated) {
let toJSON = await Group.toJSONCleanChat(savedGroup, user);
res.respond(200, {chat: toJSON.chat});
res.respond(200, {chat: Group.toJSONCleanChat(savedGroup, user).chat});
} else {
res.respond(200, {message: savedGroup.chat[0]});
}
@@ -488,8 +486,7 @@ api.deleteChat = {
).exec();
if (chatUpdated) {
let toJSON = await Group.toJSONCleanChat(group, user);
let chatRes = toJSON.chat;
let chatRes = Group.toJSONCleanChat(group, user).chat;
removeFromArray(chatRes, {id: chatId});
res.respond(200, chatRes);
} else {

View File

@@ -391,7 +391,7 @@ api.getGroup = {
throw new NotFound(res.t('groupNotFound'));
}
let groupJson = await Group.toJSONCleanChat(group, user);
let groupJson = Group.toJSONCleanChat(group, user);
if (groupJson.leader === user._id) {
groupJson.purchased.plan = group.purchased.plan.toObject();
@@ -455,7 +455,7 @@ api.updateGroup = {
_.assign(group, _.merge(group.toObject(), Group.sanitizeUpdate(req.body)));
let savedGroup = await group.save();
let response = await Group.toJSONCleanChat(savedGroup, user);
let response = Group.toJSONCleanChat(savedGroup, user);
// If the leader changed fetch new data, otherwise use authenticated user
if (response.leader !== user._id) {
@@ -619,7 +619,7 @@ api.joinGroup = {
promises = await Bluebird.all(promises);
let response = await Group.toJSONCleanChat(promises[0], user);
let response = Group.toJSONCleanChat(promises[0], user);
let leader = await User.findById(response.leader).select(nameFields).exec();
if (leader) {
response.leader = leader.toJSON({minimize: true});

View File

@@ -424,7 +424,7 @@ api.abortQuest = {
let questName = questScrolls[group.quest.key].text('en');
group.sendChat(`\`${user.profile.name} aborted the party quest ${questName}.\``, null, null, {
type: 'quest_abort',
user: user._id,
user: user.profile.name,
quest: group.quest.key,
});

View File

@@ -738,7 +738,7 @@ api.castSpell = {
if (targetType === 'user') {
party.sendChat(message, null, null, {
type: 'spell_cast_user',
user: user._id,
user: user.profile.name,
class: klass,
spell: spellId,
target: partyMembers._id,
@@ -746,7 +746,7 @@ api.castSpell = {
} else {
party.sendChat(message, null, null, {
type: 'spell_cast_party',
user: user._id,
user: user.profile.name,
class: klass,
spell: spellId,
});