summary refs log tree commit diff
diff options
context:
space:
mode:
authorIntevel ツ <59223342+Intevel@users.noreply.github.com>2021-05-05 22:19:02 +0200
committerIntevel ツ <59223342+Intevel@users.noreply.github.com>2021-05-05 22:19:02 +0200
commitcdd56ff3b78e6d4516cc73982ab81076b56329c8 (patch)
tree43fbae1245bf6eb1eb2ba30dbd3bdd475cc7f426
parent[Route] GET /guilds/template/:code (diff)
downloadserver-cdd56ff3b78e6d4516cc73982ab81076b56329c8.tar.xz
[Route] GET /guilds/template/:code
fixed
-rw-r--r--src/routes/guilds/#guild_id/templates.ts15
-rw-r--r--src/routes/guilds/templates/index.ts23
2 files changed, 22 insertions, 16 deletions
diff --git a/src/routes/guilds/#guild_id/templates.ts b/src/routes/guilds/#guild_id/templates.ts

index 28947779..422484a6 100644 --- a/src/routes/guilds/#guild_id/templates.ts +++ b/src/routes/guilds/#guild_id/templates.ts
@@ -75,21 +75,6 @@ router.delete("/:template_id", async (req: Request, res: Response) => { res.send("Deleted"); }); -router.get("/:template_id", 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 template = await TemplateModel.findById({ _id: template_id }).exec(); - if (!template) throw new HTTPError("template not found", 404); - - res.json(toObject(template)).send(); -}); - router.put("/:template_id", async (req: Request, res: Response) => { const guild_id = req.params.guild_id; diff --git a/src/routes/guilds/templates/index.ts b/src/routes/guilds/templates/index.ts
index 9a4e81fa..918c8e7c 100644 --- a/src/routes/guilds/templates/index.ts +++ b/src/routes/guilds/templates/index.ts
@@ -1,4 +1,25 @@ -import { Router } from "express"; +import { Request, Response, Router } from "express"; const router: Router = Router(); +import { TemplateModel, GuildModel, getPermission, toObject, UserModel } from "@fosscord/server-util"; +import { HTTPError } from "lambert-server"; +import { TemplateCreateSchema } from "../../../schema/Template"; +import { emitEvent } from "../../../util/Event"; +import { check } from "../../../util/instanceOf"; +import { getPublicUser } from "../../../util/User"; + +router.get("/:template_id", 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 template = await TemplateModel.findById({ _id: template_id }).exec(); + if (!template) throw new HTTPError("template not found", 404); + + res.json(toObject(template)).send(); +}); export default router;