diff options
Diffstat (limited to 'api/src/routes')
-rw-r--r-- | api/src/routes/channels/#channel_id/index.ts | 2 | ||||
-rw-r--r-- | api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts | 2 | ||||
-rw-r--r-- | api/src/routes/channels/#channel_id/permissions.ts | 15 | ||||
-rw-r--r-- | api/src/routes/channels/#channel_id/pins.ts | 2 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/channels.ts | 15 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/index.ts | 2 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/members/#member_id/index.ts | 2 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/roles.ts | 3 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/templates.ts | 8 | ||||
-rw-r--r-- | api/src/routes/invites/index.ts | 2 | ||||
-rw-r--r-- | api/src/routes/users/@me/index.ts | 2 |
11 files changed, 27 insertions, 28 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", 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(); }); diff --git a/api/src/routes/invites/index.ts b/api/src/routes/invites/index.ts index 992694df..b4066bd8 100644 --- a/api/src/routes/invites/index.ts +++ b/api/src/routes/invites/index.ts @@ -16,7 +16,7 @@ router.get("/:code", async (req: Request, res: Response) => { router.post("/:code", async (req: Request, res: Response) => { const { code } = req.params; - const invite = await InviteModel.findOneAndUpdate({ code }, { $inc: { uses: 1 } }).exec(); + const invite = await InviteModel.findOneAndUpdate({ code }, { $inc: { uses: 1 } }, { new: true }).exec(); if (!invite) throw new HTTPError("Unknown Invite", 404); await addMember(req.user_id, invite.guild_id); diff --git a/api/src/routes/users/@me/index.ts b/api/src/routes/users/@me/index.ts index c073e78a..6ebc6634 100644 --- a/api/src/routes/users/@me/index.ts +++ b/api/src/routes/users/@me/index.ts @@ -38,7 +38,7 @@ router.patch("/", check(UserModifySchema), async (req: Request, res: Response) = if (body.avatar) body.avatar = await handleFile(`/avatars/${req.user_id}`, body.avatar as string); if (body.banner) body.banner = await handleFile(`/banners/${req.user_id}`, body.banner as string); - const user = await UserModel.findOneAndUpdate({ id: req.user_id }, body, { projection: UserUpdateProjection }).exec(); + const user = await UserModel.findOneAndUpdate({ id: req.user_id }, body, { projection: UserUpdateProjection, new: true }).exec(); // TODO: dispatch user update event res.json(toObject(user)); |