mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
🐛 ✨ fix templates
This commit is contained in:
parent
58d3ec17ae
commit
fe1836a0d1
@ -28,17 +28,21 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
var templates = await TemplateModel.find({ source_guild_id: guild_id }).exec();
|
var templates = await TemplateModel.find({ source_guild_id: guild_id }).exec();
|
||||||
|
|
||||||
return res.json(toObject(templates));
|
return res.json(toObject(templates));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/", check(TemplateCreateSchema), async (req: Request, res: Response) => {
|
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 guild = await GuildModel.findOne({ id: guild_id }, TemplateGuildProjection).exec();
|
||||||
|
|
||||||
const perms = await getPermission(req.user_id, guild_id);
|
const perms = await getPermission(req.user_id, guild_id);
|
||||||
perms.hasThrow("MANAGE_GUILD");
|
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({
|
const template = await new TemplateModel({
|
||||||
...req.body,
|
...req.body,
|
||||||
code: generateCode(),
|
code: generateCode(),
|
||||||
|
@ -10,7 +10,7 @@ import { addMember } from "../../../util/Member";
|
|||||||
router.get("/:code", async (req: Request, res: Response) => {
|
router.get("/:code", async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
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();
|
res.json(toObject(template)).send();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user