1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-21 18:21:36 +02:00

🐛 fix guild create with channel template

This commit is contained in:
Flam3rboy 2021-08-14 13:55:51 +02:00
parent 21808cf750
commit 6db7620582

View File

@ -80,7 +80,27 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
}).save() }).save()
]); ]);
await createChannel({ name: "general", type: 0, guild_id, position: 0, permission_overwrites: [] }, req.user_id); if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }];
const ids = new Map();
body.channels.forEach((x) => {
if (x.id) {
ids.set(x.id, Snowflake.generate());
}
});
await Promise.all(
body.channels?.map((x) => {
var id = ids.get(x.id) || Snowflake.generate();
// TODO: should we abort if parent_id is a category? (or not to allow sub category channels)
var parent_id = ids.get(x.parent_id);
return createChannel({ ...x, guild_id, id, parent_id }, req.user_id, { keepId: true, skipExistsCheck: true });
})
);
await addMember(req.user_id, guild_id); await addMember(req.user_id, guild_id);
res.status(201).json({ id: guild.id }); res.status(201).json({ id: guild.id });