[Route] GET /guilds/:id/templates

This commit is contained in:
Intevel ツ 2021-05-05 21:40:33 +02:00
parent abb1fee752
commit 7e07997d27
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import { Request, Response, Router } from "express";
import { TemplateModel, GuildModel, getPermission, toObject } 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";
const router: Router = Router();
router.get("/", async (req: Request, res: Response) => {
const guild_id = req.params.id;
const guild = await GuildModel.exists({ id: guild_id });
if (!guild) throw new HTTPError("Guild not found", 404);
var templates = await TemplateModel.find({ source_guild_id: guild_id }).exec();
return res.json(toObject(templates));
});
export default router;

10
src/schema/Template.ts Normal file
View File

@ -0,0 +1,10 @@
export const TemplateCreateSchema = {
name: String,
$description: String,
};
export interface TemplateCreateSchema {
name: string,
descriptio?: string,
}