billing
This commit is contained in:
49
backend/src/routes/billing.ts
Normal file
49
backend/src/routes/billing.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { Router } from 'express';
|
||||
import { requireAuth, requireSuperAdmin } from '../middleware/auth.js';
|
||||
import { computeMonthlyBilling, listBillingEvents, PRICE_PER_INBOX } from '../services/billing.js';
|
||||
|
||||
export const billingRouter = Router();
|
||||
billingRouter.use(requireAuth);
|
||||
billingRouter.use(requireSuperAdmin);
|
||||
|
||||
/**
|
||||
* GET /api/billing/summary
|
||||
* Optional query params:
|
||||
* ?domain=foo.com -> restrict to one domain
|
||||
*
|
||||
* Returns:
|
||||
* { price_per_inbox: 5,
|
||||
* months: [
|
||||
* { domain, ym, year, month, inbox_count, amount_usd, inbox_emails: [...] },
|
||||
* ...
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
billingRouter.get('/summary', async (req, res) => {
|
||||
const domain = req.query.domain ? String(req.query.domain).toLowerCase() : undefined;
|
||||
const months = await computeMonthlyBilling({ domain });
|
||||
res.json({
|
||||
price_per_inbox: PRICE_PER_INBOX,
|
||||
months,
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/billing/events
|
||||
* Raw event log. Useful for "Show me the create/delete history".
|
||||
*
|
||||
* Optional query params:
|
||||
* ?domain=foo.com
|
||||
* ?from=2026-01-01T00:00:00Z
|
||||
* ?to=2026-02-01T00:00:00Z
|
||||
* ?limit=200 (1..5000)
|
||||
*/
|
||||
billingRouter.get('/events', async (req, res) => {
|
||||
const events = await listBillingEvents({
|
||||
domain: req.query.domain ? String(req.query.domain).toLowerCase() : undefined,
|
||||
fromIso: req.query.from ? String(req.query.from) : undefined,
|
||||
toIso: req.query.to ? String(req.query.to) : undefined,
|
||||
limit: req.query.limit ? Number(req.query.limit) : 500,
|
||||
});
|
||||
res.json(events);
|
||||
});
|
||||
Reference in New Issue
Block a user