diff options
author | Intevel ツ <59223342+Intevel@users.noreply.github.com> | 2021-05-08 14:57:30 +0200 |
---|---|---|
committer | Intevel ツ <59223342+Intevel@users.noreply.github.com> | 2021-05-08 14:57:30 +0200 |
commit | 462c40521a85f2ecf19cccb46a6910fab669b1c7 (patch) | |
tree | 387a781a1b4bbf78c5c916ab0267f01900fa84fd /src/routes | |
parent | Create welcome_screen.ts (diff) | |
download | server-462c40521a85f2ecf19cccb46a6910fab669b1c7.tar.xz |
Update welcome_screen.ts
Diffstat (limited to 'src/routes')
-rw-r--r-- | src/routes/guilds/#guild_id/welcome_screen.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/routes/guilds/#guild_id/welcome_screen.ts b/src/routes/guilds/#guild_id/welcome_screen.ts index 98f80509..86eb9996 100644 --- a/src/routes/guilds/#guild_id/welcome_screen.ts +++ b/src/routes/guilds/#guild_id/welcome_screen.ts @@ -17,5 +17,29 @@ router.get("/", async (req: Request, res: Response) => { res.json(toObject(guild.welcome_screen)); }); +router.post("/", check(GuildAddChannelToWelcomeScreenSchema), async (req: Request, res: Response) => { + const guild_id = req.params.id; + const body = req.body as GuildAddChannelToWelcomeScreenSchema; + + const guild = await GuildModel.findOne({ id: guild_id }).exec(); + if (!guild) throw new HTTPError("Guild not found", 404); + + var channelObject = { + ...body + } + + if(guild.welcome_screen.welcome_channels.some(channel => channel.channel_id === body.channel_id)){ + + + await GuildModel.findOneAndUpdate( + { + id: guild_id, + }, + { $push: { "welcome_screen.welcome_channels": channelObject } } + ).exec(); + + res.json(toObject(guild.welcome_screen)); +}); + export default router; |