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
commitfe1836a0d13c65f0fbe6f46293fd29edc49e02fc (patch)
treede5fe7bdd122da84fa882aeaab97cb8b1e3e54e5
parent:bug: fix login undelete/undisable (diff)
downloadserver-fe1836a0d13c65f0fbe6f46293fd29edc49e02fc.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();
 });