feat: add local auth billing and usage management
This commit is contained in:
1 parent
f642b5e71f
commit
196fdde83f
119 files changed
+15695
-2650
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { jsonError, jsonOk } from "@/lib/server/api";
|
||||
import { requireSuperAdminSession } from "@/lib/server/auth/current-user";
|
||||
import { listPlatformOrganizations, listPlatformUsers } from "@/lib/server/account-store";
|
||||
import { listBillingLedgerEntries, listBillingPriceRules, listOrganizationWallets } from "@/lib/server/billing-store";
|
||||
import { ensureDefaultBillingPriceRules } from "@/lib/server/billing-catalog";
|
||||
import { getBillingAccountConfig } from "@/lib/server/billing-service";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
await requireSuperAdminSession();
|
||||
await ensureDefaultBillingPriceRules();
|
||||
const [organizations, wallets, members, ledger, priceRules] = await Promise.all([
|
||||
listPlatformOrganizations({ includeDisabled: true }),
|
||||
listOrganizationWallets(),
|
||||
listPlatformUsers({ includeDisabled: true }),
|
||||
listBillingLedgerEntries({ limit: 500 }),
|
||||
listBillingPriceRules({ includeDisabled: true })
|
||||
]);
|
||||
const walletByOrganization = new Map(wallets.map((wallet) => [wallet.organizationId, wallet]));
|
||||
return jsonOk({
|
||||
billingAccount: getBillingAccountConfig(),
|
||||
organizations: organizations.map((organization) => ({
|
||||
...organization,
|
||||
wallet: walletByOrganization.get(organization.id) || {
|
||||
organizationId: organization.id,
|
||||
balanceFen: 0,
|
||||
totalRechargedFen: 0,
|
||||
totalChargedFen: 0,
|
||||
updatedAt: organization.updatedAt
|
||||
}
|
||||
})),
|
||||
members: members.map((member) => ({
|
||||
id: member.id,
|
||||
displayName: member.displayName,
|
||||
phone: member.phone,
|
||||
role: member.role,
|
||||
organizationId: member.organizationId || null,
|
||||
status: member.status
|
||||
})),
|
||||
ledger,
|
||||
priceRules
|
||||
});
|
||||
} catch (error) {
|
||||
return jsonError(error, 500, { source: "api.admin.billing" });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user