summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/routes/guilds/#guild_id/templates.ts29
-rw-r--r--src/schema/Template.ts11
2 files changed, 39 insertions, 1 deletions
diff --git a/src/routes/guilds/#guild_id/templates.ts b/src/routes/guilds/#guild_id/templates.ts

index 422484a6..0690f0a4 100644 --- a/src/routes/guilds/#guild_id/templates.ts +++ b/src/routes/guilds/#guild_id/templates.ts
@@ -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; diff --git a/src/schema/Template.ts b/src/schema/Template.ts
index b467d4cb..64ca2165 100644 --- a/src/schema/Template.ts +++ b/src/schema/Template.ts
@@ -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, +}