🐛 fix findOneAndUpdate

This commit is contained in:
Flam3rboy
2021-08-18 11:47:28 +02:00
parent 5e12d799e3
commit 4105df8dcb
17 changed files with 39 additions and 38 deletions
+6 -4
View File
@@ -151,7 +151,8 @@ export async function addRole(user_id: string, guild_id: string, role_id: string
id: user_id,
guild_id: guild_id
},
{ $push: { roles: role_id } }
{ $push: { roles: role_id } },
{ new: true }
).exec();
if (!memberObj) throw new HTTPError("Member not found", 404);
@@ -178,7 +179,8 @@ export async function removeRole(user_id: string, guild_id: string, role_id: str
id: user_id,
guild_id: guild_id
},
{ $pull: { roles: role_id } }
{ $pull: { roles: role_id } },
{ new: true }
).exec();
if (!memberObj) throw new HTTPError("Member not found", 404);
@@ -197,13 +199,13 @@ export async function removeRole(user_id: string, guild_id: string, role_id: str
export async function changeNickname(user_id: string, guild_id: string, nickname: string) {
const user = await getPublicUser(user_id);
var memberObj = await MemberModel.findOneAndUpdate(
{
id: user_id,
guild_id: guild_id
},
{ nick: nickname }
{ nick: nickname },
{ new: true }
).exec();
if (!memberObj) throw new HTTPError("Member not found", 404);
+1 -2
View File
@@ -157,7 +157,6 @@ export async function postHandleMessage(message: Message) {
await Promise.all([
emitEvent({
event: "MESSAGE_UPDATE",
guild_id: message.guild_id,
channel_id: message.channel_id,
data
} as MessageUpdateEvent),
@@ -172,7 +171,7 @@ export async function sendMessage(opts: Partial<Message>) {
await new MessageModel(message).populate({ path: "member", select: PublicMemberProjection }).populate("referenced_message").save()
);
await emitEvent({ event: "MESSAGE_CREATE", channel_id: opts.channel_id, data, guild_id: message.guild_id } as MessageCreateEvent);
await emitEvent({ event: "MESSAGE_CREATE", channel_id: opts.channel_id, data } as MessageCreateEvent);
postHandleMessage(data).catch((e) => {}); // no await as it shouldnt block the message send function and silently catch error