🐛 fix findOneAndUpdate
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user