1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 05:02:37 +01:00

Update welcome_screen.ts

This commit is contained in:
Intevel ツ 2021-05-08 14:57:30 +02:00
parent 1ee6d29c64
commit 462c40521a

View File

@ -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;