summary refs log tree commit diff
path: root/src/routes/guilds/templates/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/guilds/templates/index.ts')
-rw-r--r--src/routes/guilds/templates/index.ts23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/routes/guilds/templates/index.ts b/src/routes/guilds/templates/index.ts

index 80dbe5f8..2d8cdf0e 100644 --- a/src/routes/guilds/templates/index.ts +++ b/src/routes/guilds/templates/index.ts
@@ -8,23 +8,17 @@ import { check } from "../../../util/instanceOf"; import Config from "../../../util/Config"; import { addMember } from "../../../util/Member"; -router.get("/:template_id", async (req: Request, res: Response) => { +router.get("/:code", async (req: Request, res: Response) => { + const { code } = req.params; - const guild_id = req.params.guild_id; - const { template_id } = req.params; - - const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec(); - if (!guild) throw new HTTPError("Guild not found", 404); - if (!template_id) throw new HTTPError("Unknown template_id", 404); - - const template = await TemplateModel.findOne({ id: template_id }).exec(); + const template = await TemplateModel.findOne({ id: code }).exec(); if (!template) throw new HTTPError("template not found", 404); res.json(toObject(template)).send(); }); -router.post("/:template_id", check(GuildTemplateCreateSchema), async (req: Request, res: Response) => { - const { template_id } = req.params; +router.post("/:code", check(GuildTemplateCreateSchema), async (req: Request, res: Response) => { + const { code } = req.params; const body = req.body as GuildTemplateCreateSchema; const { maxGuilds } = Config.get().limits.user; @@ -34,9 +28,7 @@ router.post("/:template_id", check(GuildTemplateCreateSchema), async (req: Reque throw new HTTPError(`Maximum number of guilds reached ${maxGuilds}`, 403); } - if (!template_id) throw new HTTPError("Unknown template_id", 404); - - const template = await TemplateModel.findOne({ id: template_id }).exec(); + const template = await TemplateModel.findOne({ code: code }).exec(); if (!template) throw new HTTPError("template not found", 404); const guild_id = Snowflake.generate(); @@ -45,7 +37,7 @@ router.post("/:template_id", check(GuildTemplateCreateSchema), async (req: Reque ...body, ...template.serialized_source_guild, id: guild_id, - owner_id: req.user_id + owner_id: req.user_id, }; await Promise.all([ @@ -68,5 +60,4 @@ router.post("/:template_id", check(GuildTemplateCreateSchema), async (req: Reque res.status(201).json({ id: guild.id }); }); - export default router;