Files
drop/server/api/v1/admin/task/index.get.ts
DecDuck 4184705b14 Task groups & viewer in admin panel #52 (#91)
* feat: historical tasks in database, better scheduling, and unified API for accessing tasks

* feat: new UI for everything

* fix: add translations and fix formatting
2025-06-07 15:39:01 +10:00

36 lines
984 B
TypeScript

import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
import taskHandler from "~/server/internal/tasks";
export default defineEventHandler(async (h3) => {
const allowed = await aclManager.allowSystemACL(h3, ["task:read"]);
if (!allowed) throw createError({ statusCode: 403 });
const allAcls = await aclManager.fetchAllACLs(h3);
if (!allAcls)
throw createError({
statusCode: 403,
statusMessage: "Somehow no ACLs on authenticated request.",
});
const runningTasks = (await taskHandler.runningTasks()).map((e) => e.id);
const historicalTasks = await prisma.task.findMany({
where: {
OR: [
{
acls: { hasSome: allAcls },
},
{
acls: { isEmpty: true },
},
],
},
orderBy: {
ended: "desc",
},
take: 10,
});
const dailyTasks = await taskHandler.dailyTasks();
return { runningTasks, historicalTasks, dailyTasks };
});