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

🐛 fix templates

This commit is contained in:
Flam3rboy 2021-08-12 02:26:13 +02:00
parent 58d3ec17ae
commit fe1836a0d1
2 changed files with 8 additions and 4 deletions

View File

@ -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(),

View File

@ -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();
});