feat: add the view graph on tiktok

This commit is contained in:
Pierre Ryssen
2026-03-27 00:58:38 +01:00
parent 51a376400c
commit 9bdbe8e153
6 changed files with 138 additions and 14 deletions

View File

@@ -21,6 +21,8 @@ export async function GET() {
followers: 124,
likes: 856,
videoCount: 1,
views: 3432,
profileViews: 287,
displayName: "CrowMate studio",
avatarUrl: "",
plan: (user as any)?.plan ?? "free",
@@ -56,8 +58,7 @@ export async function GET() {
try {
const stats = await fetchUserStats(accessToken, openId);
// Upsert TrackedAccount + snapshot automatique
try {
let account = await prisma.trackedAccount.findFirst({
where: { userId, platform: "tiktok" },
@@ -78,14 +79,12 @@ export async function GET() {
followers: stats.followers ?? 0,
likes: stats.likes ?? 0,
videoCount: stats.videoCount ?? 0,
views: 0,
views: stats.views ?? 0,
},
});
} catch (snapshotErr) {
console.error("[TikTok snapshot save error]", snapshotErr);
}
// Inclure le plan dans la réponse
const user = await prisma.user.findUnique({ where: { id: userId } });
return NextResponse.json({ ...stats, plan: (user as any)?.plan ?? "free" });
} catch (err) {