summary refs log tree commit diff
path: root/api/src/routes/guilds/#guild_id/index.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-24 16:35:04 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-24 16:35:04 +0200
commitef4d4a318176c3e572adc17427a8b8c728a618ab (patch)
treed95fedbf18b7b7438613b08b72eb30fa5fca8921 /api/src/routes/guilds/#guild_id/index.ts
parent:sparkles: typeorm entities (diff)
downloadserver-ef4d4a318176c3e572adc17427a8b8c728a618ab.tar.xz
:construction: api
Diffstat (limited to 'api/src/routes/guilds/#guild_id/index.ts')
-rw-r--r--api/src/routes/guilds/#guild_id/index.ts29
1 files changed, 13 insertions, 16 deletions
diff --git a/api/src/routes/guilds/#guild_id/index.ts b/api/src/routes/guilds/#guild_id/index.ts

index 87103caa..af9ea9d6 100644 --- a/api/src/routes/guilds/#guild_id/index.ts +++ b/api/src/routes/guilds/#guild_id/index.ts
@@ -1,18 +1,18 @@ import { Request, Response, Router } from "express"; import { - ChannelModel, + Channel, emitEvent, EmojiModel, getPermission, GuildDeleteEvent, - GuildModel, + Guild, GuildUpdateEvent, InviteModel, - MemberModel, - MessageModel, - RoleModel, + Member, + Message, + Role, toObject, - UserModel + User } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import { GuildUpdateSchema } from "../../../schema/Guild"; @@ -26,11 +26,8 @@ const router = Router(); router.get("/", async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await GuildModel.findOne({ id: guild_id }) - .populate({ path: "joined_at", match: { id: req.user_id } }) - .exec(); - - const member = await MemberModel.exists({ guild_id: guild_id, id: req.user_id }); + const guild = await Guild.findOneOrFail({ id: guild_id }).populate({ path: "joined_at", match: { id: req.user_id } }); + const member = await Member.exists({ guild_id: guild_id, id: req.user_id }); if (!member) throw new HTTPError("You are not a member of the guild you are trying to access", 401); return res.json(guild); @@ -48,11 +45,11 @@ 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, { new: true }) - .populate({ path: "joined_at", match: { id: req.user_id } }) - .exec(); - - const data = toObject(guild); + const guild = await Guild.findOneOrFailAndUpdate({ id: guild_id }, body, { new: true }).populate({ + path: "joined_at", + match: { id: req.user_id } + }); + const data = guild; emitEvent({ event: "GUILD_UPDATE", data: data, guild_id } as GuildUpdateEvent);