Export is PDF, RULE.md, and Print on US Letter, with every shared term, no member names, and a takeaway that points at Ask an organizer. Finished Rules keep type and place so the team can read folded counts without a database, Umami can sit beside the app with no cookies, and the person who holds the pen gets working PDF and RULE.md links 48 hours later.
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { apiRoute } from "../../../../lib/server/apiRoute";
|
|
import { prisma } from "../../../../lib/server/db";
|
|
import {
|
|
getOpsPruneToken,
|
|
getRuleAdminEmails,
|
|
isDatabaseConfigured,
|
|
} from "../../../../lib/server/env";
|
|
import {
|
|
dbUnavailable,
|
|
notFound,
|
|
unauthorized,
|
|
} from "../../../../lib/server/responses";
|
|
import { isRuleAdminEmail } from "../../../../lib/server/ruleAdmins";
|
|
import { aggregateRuleLaunchCounts } from "../../../../lib/server/ruleLaunchCounts";
|
|
import { getSessionUser } from "../../../../lib/server/session";
|
|
|
|
export const GET = apiRoute("ops.ruleCounts", async (request: NextRequest) => {
|
|
if (getRuleAdminEmails().length === 0 && !getOpsPruneToken()) {
|
|
return notFound();
|
|
}
|
|
if (!isDatabaseConfigured()) return dbUnavailable();
|
|
|
|
const header = request.headers.get("authorization") ?? "";
|
|
const opsToken = getOpsPruneToken();
|
|
const bearerOk = Boolean(opsToken) && header === `Bearer ${opsToken}`;
|
|
if (!bearerOk) {
|
|
const user = await getSessionUser();
|
|
if (!user || !isRuleAdminEmail(user.email)) return unauthorized();
|
|
}
|
|
|
|
const rows = await prisma.publishedRule.findMany({
|
|
select: { orgType: true, communityLocation: true },
|
|
});
|
|
const counts = aggregateRuleLaunchCounts(
|
|
rows.map((row) => ({
|
|
orgType: row.orgType,
|
|
place: row.communityLocation,
|
|
})),
|
|
);
|
|
return NextResponse.json(counts);
|
|
});
|