drag reorder boards in admin, position respected on public site
This commit is contained in:
@@ -33,6 +33,7 @@ model Board {
|
||||
rssEnabled Boolean @default(true)
|
||||
rssFeedCount Int @default(50)
|
||||
staleDays Int @default(0)
|
||||
position Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export default async function adminBoardRoutes(app: FastifyInstance) {
|
||||
{ preHandler: [app.requireAdmin, app.requireRole("SUPER_ADMIN", "ADMIN")], config: { rateLimit: { max: 60, timeWindow: "1 minute" } } },
|
||||
async (_req, reply) => {
|
||||
const boards = await prisma.board.findMany({
|
||||
orderBy: { createdAt: "asc" },
|
||||
orderBy: [{ position: "asc" }, { createdAt: "asc" }],
|
||||
include: {
|
||||
_count: { select: { posts: true } },
|
||||
},
|
||||
@@ -128,4 +128,17 @@ export default async function adminBoardRoutes(app: FastifyInstance) {
|
||||
reply.status(204).send();
|
||||
}
|
||||
);
|
||||
|
||||
// reorder boards
|
||||
app.put(
|
||||
"/admin/boards/reorder",
|
||||
{ preHandler: [app.requireAdmin, app.requireRole("SUPER_ADMIN", "ADMIN")], config: { rateLimit: { max: 10, timeWindow: "1 minute" } } },
|
||||
async (req, reply) => {
|
||||
const body = z.object({ boardIds: z.array(z.string().min(1)).min(1) }).parse(req.body);
|
||||
await prisma.$transaction(
|
||||
body.boardIds.map((id, i) => prisma.board.update({ where: { id }, data: { position: i } }))
|
||||
);
|
||||
reply.send({ ok: true });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export default async function boardRoutes(app: FastifyInstance) {
|
||||
include: {
|
||||
_count: { select: { posts: true } },
|
||||
},
|
||||
orderBy: { createdAt: "asc" },
|
||||
orderBy: [{ position: "asc" }, { createdAt: "asc" }],
|
||||
});
|
||||
|
||||
// use aggregation queries instead of loading all posts into memory
|
||||
|
||||
Reference in New Issue
Block a user