Show total scans in social milestones
This commit is contained in:
@@ -18,7 +18,7 @@ export async function GET(request: NextRequest) {
|
||||
const milestone = await db.socialMilestone.findFirst({
|
||||
where: { userId, status: { in: ['detected', 'shown'] } },
|
||||
orderBy: { detectedAt: 'asc' },
|
||||
include: { qr: { select: { title: true } } },
|
||||
include: { qr: { select: { id: true, title: true } } },
|
||||
});
|
||||
if (!milestone) return NextResponse.json({ milestone: null });
|
||||
|
||||
@@ -28,6 +28,20 @@ export async function GET(request: NextRequest) {
|
||||
const threshold = milestoneThreshold(milestone.kind);
|
||||
if (!threshold) return NextResponse.json({ milestone: null });
|
||||
const locale = socialLocale(request.nextUrl.searchParams.get('locale'));
|
||||
const allScanCount = await db.qRScan.count({ where: { qrId: milestone.qr.id } });
|
||||
const storedCard = milestone.cardData as Record<string, unknown> | null;
|
||||
const card = storedCard
|
||||
? { ...storedCard, totalScans: typeof storedCard.totalScans === 'number' ? storedCard.totalScans : allScanCount }
|
||||
: buildMilestoneCardSnapshot({
|
||||
primaryUseCase: user.primaryUseCase,
|
||||
qrTitle: milestone.qr.title,
|
||||
totalScans: allScanCount,
|
||||
totalUniqueScans: threshold,
|
||||
milestoneThreshold: threshold,
|
||||
reachedAt: milestone.detectedAt,
|
||||
trend: null,
|
||||
locale,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
milestone: {
|
||||
@@ -44,15 +58,7 @@ export async function GET(request: NextRequest) {
|
||||
locale,
|
||||
milestone.qr.title,
|
||||
),
|
||||
card: milestone.cardData || buildMilestoneCardSnapshot({
|
||||
primaryUseCase: user.primaryUseCase,
|
||||
qrTitle: milestone.qr.title,
|
||||
totalUniqueScans: threshold,
|
||||
milestoneThreshold: threshold,
|
||||
reachedAt: milestone.detectedAt,
|
||||
trend: null,
|
||||
locale,
|
||||
}),
|
||||
card,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user