Projektstart

This commit is contained in:
2026-01-22 16:19:07 +01:00
parent 5174b88af9
commit bc7fbf8ce6
1553 changed files with 111281 additions and 141 deletions

View File

@@ -29,7 +29,7 @@ export async function adminRoutes(app: FastifyInstance) {
app.get("/tenants/:id/export", async (request, reply) => {
const params = request.params as { id: string };
const query = request.query as { format?: string };
const query = request.query as { format?: string; scope?: string };
const tenant = await prisma.tenant.findUnique({
where: { id: params.id },
include: {
@@ -64,6 +64,17 @@ export async function adminRoutes(app: FastifyInstance) {
return reply.send(rows.join("\n"));
}
if (query.format === "zip" || query.format === "async") {
const exportJob = await prisma.exportJob.create({
data: {
tenantId: tenant.id,
format: "zip",
scope: scope
}
});
return { jobId: exportJob.id };
}
if (scope === "users") return { users: tenant.users };
if (scope === "accounts") return { accounts: tenant.mailboxAccounts };
if (scope === "jobs") return { jobs: tenant.jobs };
@@ -71,6 +82,24 @@ export async function adminRoutes(app: FastifyInstance) {
return { tenant };
});
app.get("/exports/:id", async (request, reply) => {
const params = request.params as { id: string };
const job = await prisma.exportJob.findUnique({ where: { id: params.id } });
if (!job) return reply.code(404).send({ message: "Export job not found" });
return { job };
});
app.get("/exports/:id/download", async (request, reply) => {
const params = request.params as { id: string };
const job = await prisma.exportJob.findUnique({ where: { id: params.id } });
if (!job || !job.filePath) return reply.code(404).send({ message: "Export file not ready" });
reply.header("Content-Type", "application/zip");
reply.header("Content-Disposition", `attachment; filename=export-${job.id}.zip`);
return reply.sendFile(job.filePath);
});
app.delete("/tenants/:id", async (request, reply) => {
const params = request.params as { id: string };
const tenant = await prisma.tenant.findUnique({ where: { id: params.id } });