diff --git a/api/src/routes/guilds/#guild_id/channels.ts b/api/src/routes/guilds/#guild_id/channels.ts
index 8d97cf96..4383c79b 100644
--- a/api/src/routes/guilds/#guild_id/channels.ts
+++ b/api/src/routes/guilds/#guild_id/channels.ts
@@ -1,16 +1,5 @@
import { Router, Response, Request } from "express";
-import {
- ChannelCreateEvent,
- ChannelModel,
- ChannelType,
- GuildModel,
- Snowflake,
- toObject,
- ChannelUpdateEvent,
- AnyChannel,
- getPermission,
- emitEvent
-} from "@fosscord/util";
+import { ChannelModel, toObject, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
import { HTTPError } from "lambert-server";
import { ChannelModifySchema } from "../../../schema/Channel";
@@ -63,7 +52,7 @@ router.patch(
}
}
- const channel = await ChannelModel.findOneAndUpdate({ id: req.body, guild_id }, opts).exec();
+ const channel = await ChannelModel.findOneAndUpdate({ id: req.body, guild_id }, opts, { new: true }).exec();
await emitEvent({ event: "CHANNEL_UPDATE", data: toObject(channel), channel_id: body.id, guild_id } as ChannelUpdateEvent);
diff --git a/api/src/routes/guilds/#guild_id/index.ts b/api/src/routes/guilds/#guild_id/index.ts
index 1afa603f..87103caa 100644
--- a/api/src/routes/guilds/#guild_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/index.ts
@@ -48,7 +48,7 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response)
if (body.banner) body.banner = await handleFile(`/banners/${guild_id}`, body.banner);
if (body.splash) body.splash = await handleFile(`/splashes/${guild_id}`, body.splash);
- const guild = await GuildModel.findOneAndUpdate({ id: guild_id }, body)
+ const guild = await GuildModel.findOneAndUpdate({ id: guild_id }, body, { new: true })
.populate({ path: "joined_at", match: { id: req.user_id } })
.exec();
diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
index eac6684a..515434d6 100644
--- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
@@ -36,7 +36,7 @@ router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response)
// TODO: check if user has permission to add role
}
- const member = await MemberModel.findOneAndUpdate({ id: member_id, guild_id }, body).exec();
+ const member = await MemberModel.findOneAndUpdate({ id: member_id, guild_id }, body, { new: true }).exec();
await emitEvent({
event: "GUILD_MEMBER_UPDATE",
diff --git a/api/src/routes/guilds/#guild_id/roles.ts b/api/src/routes/guilds/#guild_id/roles.ts
index 36370bb4..f095c885 100644
--- a/api/src/routes/guilds/#guild_id/roles.ts
+++ b/api/src/routes/guilds/#guild_id/roles.ts
@@ -108,7 +108,8 @@ router.patch("/:role_id", check(RoleModifySchema), async (req: Request, res: Res
guild_id: guild_id
},
// @ts-ignore
- body
+ body,
+ { new: true }
).exec();
await emitEvent({
diff --git a/api/src/routes/guilds/#guild_id/templates.ts b/api/src/routes/guilds/#guild_id/templates.ts
index fdca1c40..e441ee12 100644
--- a/api/src/routes/guilds/#guild_id/templates.ts
+++ b/api/src/routes/guilds/#guild_id/templates.ts
@@ -79,7 +79,7 @@ router.put("/:code", async (req: Request, res: Response) => {
const perms = await getPermission(req.user_id, guild_id);
perms.hasThrow("MANAGE_GUILD");
- const template = await TemplateModel.findOneAndUpdate({ code }, { serialized_source_guild: guild }).exec();
+ const template = await TemplateModel.findOneAndUpdate({ code }, { serialized_source_guild: guild }, { new: true }).exec();
res.json(toObject(template)).send();
});
@@ -91,7 +91,11 @@ router.patch("/:code", check(TemplateModifySchema), async (req: Request, res: Re
const perms = await getPermission(req.user_id, guild_id);
perms.hasThrow("MANAGE_GUILD");
- const template = await TemplateModel.findOneAndUpdate({ code }, { name: req.body.name, description: req.body.description }).exec();
+ const template = await TemplateModel.findOneAndUpdate(
+ { code },
+ { name: req.body.name, description: req.body.description },
+ { new: true }
+ ).exec();
res.json(toObject(template)).send();
});
|