summary refs log tree commit diff
path: root/api/src/routes/channels/#channel_id/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/routes/channels/#channel_id/index.ts')
-rw-r--r--api/src/routes/channels/#channel_id/index.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/api/src/routes/channels/#channel_id/index.ts b/api/src/routes/channels/#channel_id/index.ts
index fb6bcb1a..91534602 100644
--- a/api/src/routes/channels/#channel_id/index.ts
+++ b/api/src/routes/channels/#channel_id/index.ts
@@ -1,4 +1,4 @@
-import { ChannelDeleteEvent, ChannelModel, ChannelUpdateEvent, emitEvent, getPermission, GuildUpdateEvent, toObject } from "@fosscord/util";
+import { ChannelDeleteEvent, Channel, ChannelUpdateEvent, emitEvent, getPermission, GuildUpdateEvent, toObject } from "@fosscord/util";
 import { Router, Response, Request } from "express";
 import { HTTPError } from "lambert-server";
 import { ChannelModifySchema } from "../../../schema/Channel";
@@ -10,28 +10,28 @@ const router: Router = Router();
 router.get("/", async (req: Request, res: Response) => {
 	const { channel_id } = req.params;
 
-	const channel = await ChannelModel.findOne({ id: channel_id }).exec();
+	const channel = await Channel.findOneOrFail({ id: channel_id });
 
 	const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
 	permission.hasThrow("VIEW_CHANNEL");
 
-	return res.send(toObject(channel));
+	return res.send(channel);
 });
 
 router.delete("/", async (req: Request, res: Response) => {
 	const { channel_id } = req.params;
 
-	const channel = await ChannelModel.findOne({ id: channel_id }).exec();
+	const channel = await Channel.findOneOrFail({ id: channel_id });
 
 	const permission = await getPermission(req.user_id, channel?.guild_id, channel_id, { channel });
 	permission.hasThrow("MANAGE_CHANNELS");
 
 	// TODO: Dm channel "close" not delete
-	const data = toObject(channel);
+	const data = channel;
 
 	await emitEvent({ event: "CHANNEL_DELETE", data, channel_id } as ChannelDeleteEvent);
 
-	await ChannelModel.deleteOne({ id: channel_id });
+	await Channel.deleteOne({ id: channel_id });
 
 	res.send(data);
 });
@@ -43,9 +43,9 @@ 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, { new: true }).exec();
+	const channel = await Channel.findOneOrFailAndUpdate({ id: channel_id }, payload, { new: true });
 
-	const data = toObject(channel);
+	const data = channel;
 
 	await emitEvent({
 		event: "CHANNEL_UPDATE",