summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 02:26:13 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 02:26:13 +0200
commit2c9a661dd8f72fa64cff8161cbbf766d7d8abb9b (patch)
treea24f9a66a12ec9f4e6cd46e4cbe8506c9e113c9e
parent:bug: fix login undelete/undisable (diff)
downloadserver-2c9a661dd8f72fa64cff8161cbbf766d7d8abb9b.tar.xz
:bug: :sparkles: fix templates
-rw-r--r--src/routes/guilds/#guild_id/templates.ts10
-rw-r--r--src/routes/guilds/templates/index.ts2
2 files changed, 8 insertions, 4 deletions
diff --git a/src/routes/guilds/#guild_id/templates.ts b/src/routes/guilds/#guild_id/templates.ts

index 04ac196e..8306ac37 100644 --- a/src/routes/guilds/#guild_id/templates.ts +++ b/src/routes/guilds/#guild_id/templates.ts
@@ -28,17 +28,21 @@ router.get("/", async (req: Request, res: Response) => { const { guild_id } = req.params; var templates = await TemplateModel.find({ source_guild_id: guild_id }).exec(); + return res.json(toObject(templates)); }); router.post("/", check(TemplateCreateSchema), async (req: Request, res: Response) => { - const guild_id = req.params.guild_id; - + const { guild_id } = req.params; const guild = await GuildModel.findOne({ id: guild_id }, TemplateGuildProjection).exec(); - const perms = await getPermission(req.user_id, guild_id); perms.hasThrow("MANAGE_GUILD"); + const exists = await TemplateModel.findOne({ id: guild_id }) + .exec() + .catch((e) => {}); + if (exists) throw new HTTPError("Template already exists", 400); + const template = await new TemplateModel({ ...req.body, code: generateCode(), diff --git a/src/routes/guilds/templates/index.ts b/src/routes/guilds/templates/index.ts
index cc95069d..0f332de0 100644 --- a/src/routes/guilds/templates/index.ts +++ b/src/routes/guilds/templates/index.ts
@@ -10,7 +10,7 @@ import { addMember } from "../../../util/Member"; router.get("/:code", async (req: Request, res: Response) => { const { code } = req.params; - const template = await TemplateModel.findOne({ id: code }).exec(); + const template = await TemplateModel.findOne({ code: code }).exec(); res.json(toObject(template)).send(); });