🐛 fix findOneAndUpdate

This commit is contained in:
Flam3rboy
2021-08-18 11:47:28 +02:00
parent bf8718489e
commit 9ab8fc8e6e
17 changed files with 43 additions and 40 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ router.patch("/", check(ChannelModifySchema), async (req: Request, res: Response
const permission = await getPermission(req.user_id, undefined, channel_id);
permission.hasThrow("MANAGE_CHANNELS");
const channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, payload).exec();
const channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, payload, { new: true }).exec();
const data = toObject(channel);
@@ -43,7 +43,7 @@ router.delete("/", async (req: Request, res: Response) => {
const permissions = await getPermission(req.user_id, undefined, channel_id);
permissions.hasThrow("MANAGE_MESSAGES");
await MessageModel.findOneAndUpdate({ id: message_id, channel_id }, { reactions: [] }).exec();
await MessageModel.findOneAndUpdate({ id: message_id, channel_id }, { reactions: [] }, { new: true }).exec();
await emitEvent({
event: "MESSAGE_REACTION_REMOVE_ALL",
@@ -5,7 +5,8 @@ import {
emitEvent,
getPermission,
MemberModel,
RoleModel
RoleModel,
toObject
} from "@fosscord/util";
import { Router, Response, Request } from "express";
import { HTTPError } from "lambert-server";
@@ -47,12 +48,12 @@ router.put("/:overwrite_id", check({ allow: String, deny: String, type: Number,
overwrite.deny = body.deny;
// @ts-ignore
channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, channel).exec();
channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, channel, { new: true }).exec();
await emitEvent({
event: "CHANNEL_UPDATE",
channel_id,
data: channel
data: toObject(channel)
} as ChannelUpdateEvent);
return res.sendStatus(204);
@@ -65,13 +66,17 @@ router.delete("/:overwrite_id", async (req: Request, res: Response) => {
const permissions = await getPermission(req.user_id, undefined, channel_id);
permissions.hasThrow("MANAGE_ROLES");
const channel = await ChannelModel.findOneAndUpdate({ id: channel_id }, { $pull: { permission_overwrites: { id: overwrite_id } } });
const channel = await ChannelModel.findOneAndUpdate(
{ id: channel_id },
{ $pull: { permission_overwrites: { id: overwrite_id } } },
{ new: true }
);
if (!channel.guild_id) throw new HTTPError("Channel not found", 404);
await emitEvent({
event: "CHANNEL_UPDATE",
channel_id,
data: channel
data: toObject(channel)
} as ChannelUpdateEvent);
return res.sendStatus(204);
+1 -1
View File
@@ -57,7 +57,7 @@ router.delete("/:message_id", async (req: Request, res: Response) => {
permission.hasThrow("VIEW_CHANNEL");
if (channel.guild_id) permission.hasThrow("MANAGE_MESSAGES");
const message = toObject(await MessageModel.findOneAndUpdate({ id: message_id }, { pinned: false }).exec());
const message = toObject(await MessageModel.findOneAndUpdate({ id: message_id }, { pinned: false }, { new: true }).exec());
await emitEvent({
event: "MESSAGE_UPDATE",