This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
@@ -1,24 +1,24 @@
|
||||
import { apiJson, apiError } from "@/lib/api";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
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);
|
||||
const uid = await bearerUserId(req);
|
||||
if (!uid) return apiError("Unauthorized", 401);
|
||||
|
||||
try {
|
||||
const agg = await prisma.radioListenerPoints.aggregate({
|
||||
where: { userId: uid },
|
||||
_sum: { points: true },
|
||||
});
|
||||
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 });
|
||||
}
|
||||
return apiJson({ points: agg._sum.points ?? 0 });
|
||||
} catch {
|
||||
// DB unavailable — report zero rather than a 500.
|
||||
return apiJson({ points: 0 }, { status: 200 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user