summary refs log tree commit diff
path: root/api/src/routes/channels/#channel_id
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-18 11:47:28 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-18 11:47:28 +0200
commit4105df8dcb825dd3d0ca048ca2bb09f9ada3d390 (patch)
treedff83a75ad8cb2fef29aac520005bf2c2accf9f2 /api/src/routes/channels/#channel_id
parentfix #199 (diff)
downloadserver-4105df8dcb825dd3d0ca048ca2bb09f9ada3d390.tar.xz
:bug: fix findOneAndUpdate
Diffstat (limited to 'api/src/routes/channels/#channel_id')
-rw-r--r--api/src/routes/channels/#channel_id/index.ts2
-rw-r--r--api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts2
-rw-r--r--api/src/routes/channels/#channel_id/permissions.ts15
-rw-r--r--api/src/routes/channels/#channel_id/pins.ts2
4 files changed, 13 insertions, 8 deletions
diff --git a/api/src/routes/channels/#channel_id/index.ts b/api/src/routes/channels/#channel_id/index.ts
index 3bfa80be..fb6bcb1a 100644
--- a/api/src/routes/channels/#channel_id/index.ts
+++ b/api/src/routes/channels/#channel_id/index.ts
@@ -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);
 
diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts b/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts
index 34d2ce3a..7da63644 100644
--- a/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts
+++ b/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts
@@ -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",
diff --git a/api/src/routes/channels/#channel_id/permissions.ts b/api/src/routes/channels/#channel_id/permissions.ts
index 4cbc7522..f93075b1 100644
--- a/api/src/routes/channels/#channel_id/permissions.ts
+++ b/api/src/routes/channels/#channel_id/permissions.ts
@@ -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);
diff --git a/api/src/routes/channels/#channel_id/pins.ts b/api/src/routes/channels/#channel_id/pins.ts
index 18a5861b..0dd81bd3 100644
--- a/api/src/routes/channels/#channel_id/pins.ts
+++ b/api/src/routes/channels/#channel_id/pins.ts
@@ -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",