fix: remove invalid distinct option from Prisma findMany
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 19s

Prisma v5.22 findMany does not support distinct — handled in JS instead.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
WangDL 2026-05-24 14:23:36 +08:00
parent 098b8055f5
commit 3f2ba8ba93

View File

@ -13,16 +13,21 @@ export class GrowthService {
where: { userId }, where: { userId },
orderBy: { date: 'desc' }, orderBy: { date: 'desc' },
select: { date: true }, select: { date: true },
distinct: ['date'],
take: 365, take: 365,
}); });
if (activities.length === 0) return { currentStreak: 0, longestStreak: 0 }; if (activities.length === 0) return { currentStreak: 0, longestStreak: 0 };
const dates = activities.map(a => new Date(a.date).toISOString().slice(0, 10)); // Dedupe by date
let currentStreak = 1; const seen = new Set<string>();
let longestStreak = 1; const dates: string[] = [];
let streak = 1; for (const a of activities) {
const d = new Date(a.date).toISOString().slice(0, 10);
if (!seen.has(d)) { seen.add(d); dates.push(d); }
}
let currentStreak = dates.length > 0 ? 1 : 0;
let longestStreak = currentStreak;
let streak = currentStreak;
for (let i = 1; i < dates.length; i++) { for (let i = 1; i < dates.length; i++) {
const prev = new Date(dates[i - 1]); const prev = new Date(dates[i - 1]);