1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 13:14:06 +01:00

[Route] PATCH /guilds/:id/templates

This commit is contained in:
Intevel ツ 2021-05-06 11:22:34 +02:00
parent aeafd30b01
commit be50cc3d35
2 changed files with 39 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import { Request, Response, Router } from "express";
import { TemplateModel, GuildModel, getPermission, toObject, UserModel } from "@fosscord/server-util";
import { HTTPError } from "lambert-server";
import { TemplateCreateSchema } from "../../../schema/Template";
import { TemplateCreateSchema, TemplateModifySchema } from "../../../schema/Template";
import { emitEvent } from "../../../util/Event";
import { check } from "../../../util/instanceOf";
import { getPublicUser } from "../../../util/User";
@ -103,4 +103,31 @@ router.put("/:template_id", async (req: Request, res: Response) => {
res.json(toObject(templateobj)).send();
});
router.patch("/:template_id", check(TemplateModifySchema), async (req: Request, res: Response) => {
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 user = await UserModel.findOne({ id: req.user_id }).exec();
if (!user) throw new HTTPError("User not found", 404);
const template = await TemplateModel.findById({ _id: template_id }).exec();
if (!template) throw new HTTPError("template not found", 404);
/*const perms = await getPermission(req.user_id, guild_id);
if (!perms.has("MANAGE_GUILD"))
throw new HTTPError("You missing the MANAGE_GUILD permission", 401);*/
var templateobj = await TemplateModel.findByIdAndUpdate({
_id: template_id
}, {name: req.body.name,
description: req.body.description || "No description"}).exec();
res.json(toObject(templateobj)).send();
});
export default router;

View File

@ -8,3 +8,14 @@ export interface TemplateCreateSchema {
name: string,
description?: string,
}
export const TemplateModifySchema = {
name: String,
$description: String,
};
export interface TemplateModifySchema {
name: string,
description?: string,
}