22 lines
792 B
TypeScript
22 lines
792 B
TypeScript
import { FastifyInstance } from "fastify";
|
|
import { prisma } from "../lib/prisma.js";
|
|
|
|
export default async function templateRoutes(app: FastifyInstance) {
|
|
app.get<{ Params: { boardSlug: string } }>(
|
|
"/boards/:boardSlug/templates",
|
|
{ config: { rateLimit: { max: 30, timeWindow: "1 minute" } } },
|
|
async (req, reply) => {
|
|
const board = await prisma.board.findUnique({ where: { slug: req.params.boardSlug } });
|
|
if (!board) return reply.status(404).send({ error: "Board not found" });
|
|
|
|
const templates = await prisma.boardTemplate.findMany({
|
|
where: { boardId: board.id },
|
|
orderBy: { position: "asc" },
|
|
select: { id: true, name: true, fields: true, isDefault: true, position: true },
|
|
});
|
|
|
|
reply.send({ templates });
|
|
}
|
|
);
|
|
}
|