25 lines
732 B
TypeScript
25 lines
732 B
TypeScript
import { apiError, apiJson } from "@/lib/api";
|
|
import { bearerUserId } from "@/lib/api-auth";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
// The Bearer-authed user's total radio listener points: the sum of all
|
|
// radio_listener_points.points rows for that user_id.
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET(req: Request) {
|
|
const uid = await bearerUserId(req);
|
|
if (!uid) return apiError("Unauthorized", 401);
|
|
|
|
try {
|
|
const agg = await prisma.radioListenerPoints.aggregate({
|
|
where: { userId: uid },
|
|
_sum: { points: true },
|
|
});
|
|
|
|
return apiJson({ points: agg._sum.points ?? 0 });
|
|
} catch {
|
|
// DB unavailable — report zero rather than a 500.
|
|
return apiJson({ points: 0 }, { status: 200 });
|
|
}
|
|
}
|