Compare commits
3 Commits
f1a31bb5e1
...
d7906ad601
| Author | SHA1 | Date | |
|---|---|---|---|
| d7906ad601 | |||
| 5b28bedeb9 | |||
| bd8ce41504 |
@ -1,3 +1,5 @@
|
|||||||
|
// /src/app/[locale]/components/MiniPlayerCard.tsx
|
||||||
|
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
||||||
|
|||||||
@ -18,8 +18,18 @@ export async function GET(
|
|||||||
steamId: true,
|
steamId: true,
|
||||||
name: true,
|
name: true,
|
||||||
avatar: true,
|
avatar: true,
|
||||||
status: true, // ✅ WICHTIG
|
status: true,
|
||||||
lastActiveAt: true, // (optional) falls vorhanden
|
lastActiveAt: true,
|
||||||
|
|
||||||
|
// ▼ FACEIT: Stammdaten + Game-Stats aus der DB
|
||||||
|
faceitNickname: true,
|
||||||
|
faceitUrl: true,
|
||||||
|
faceitGames: {
|
||||||
|
where: { game: { in: ['cs2', 'csgo'] } }, // cs2 bevorzugt, sonst csgo
|
||||||
|
select: { game: true, skillLevel: true, elo: true, updatedAt: true },
|
||||||
|
orderBy: { updatedAt: 'desc' }, // neueste zuerst
|
||||||
|
take: 2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -27,11 +37,36 @@ export async function GET(
|
|||||||
return NextResponse.json({ error: 'User nicht gefunden' }, { status: 404 })
|
return NextResponse.json({ error: 'User nicht gefunden' }, { status: 404 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// (optional) wenn du weiterhin stats mitsenden willst:
|
// bevorzugt CS2, sonst CSGO
|
||||||
// const stats = await prisma.matchPlayer.findMany({ where: { steamId } })
|
const preferred = user.faceitGames.find(g => g.game === 'cs2') ?? user.faceitGames.find(g => g.game === 'csgo')
|
||||||
|
const faceitLevel = preferred?.skillLevel ?? null
|
||||||
|
const faceitElo = preferred?.elo ?? null
|
||||||
|
|
||||||
return NextResponse.json({ user }, { status: 200 })
|
// FACEIT-URL ggf. auf /en/ normalisieren (falls {lang} Platzhalter)
|
||||||
// oder: return NextResponse.json({ user, stats }, { status: 200 })
|
const faceitUrl =
|
||||||
|
user.faceitUrl ? user.faceitUrl.replace('{lang}', 'en') : null
|
||||||
|
|
||||||
|
// Antwort-Objekt flach + optional die Rohdaten beilegen
|
||||||
|
const payload = {
|
||||||
|
user: {
|
||||||
|
steamId: user.steamId,
|
||||||
|
name: user.name,
|
||||||
|
avatar: user.avatar,
|
||||||
|
status: user.status,
|
||||||
|
lastActiveAt: user.lastActiveAt,
|
||||||
|
|
||||||
|
// FACEIT (flattened, wie im ProfileHeader)
|
||||||
|
faceitNickname: user.faceitNickname ?? null,
|
||||||
|
faceitUrl,
|
||||||
|
faceitLevel,
|
||||||
|
faceitElo,
|
||||||
|
|
||||||
|
// optional: falls du sie im Client debuggen/anzeigen willst
|
||||||
|
faceitGames: user.faceitGames,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(payload, { status: 200 })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[API] Fehler beim Laden des Users:', error)
|
console.error('[API] Fehler beim Laden des Users:', error)
|
||||||
return NextResponse.json({ error: 'Interner Serverfehler' }, { status: 500 })
|
return NextResponse.json({ error: 'Interner Serverfehler' }, { status: 500 })
|
||||||
|
|||||||
@ -405,7 +405,7 @@ const config = {
|
|||||||
"value": "prisma-client-js"
|
"value": "prisma-client-js"
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"value": "C:\\Users\\Rother\\fork\\ironie-nextjs\\src\\generated\\prisma",
|
"value": "C:\\Users\\Chris\\fork\\ironie-nextjs\\src\\generated\\prisma",
|
||||||
"fromEnvVar": null
|
"fromEnvVar": null
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
@ -419,7 +419,7 @@ const config = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"previewFeatures": [],
|
"previewFeatures": [],
|
||||||
"sourceFilePath": "C:\\Users\\Rother\\fork\\ironie-nextjs\\prisma\\schema.prisma",
|
"sourceFilePath": "C:\\Users\\Chris\\fork\\ironie-nextjs\\prisma\\schema.prisma",
|
||||||
"isCustomOutput": true
|
"isCustomOutput": true
|
||||||
},
|
},
|
||||||
"relativeEnvPaths": {
|
"relativeEnvPaths": {
|
||||||
|
|||||||
@ -406,7 +406,7 @@ const config = {
|
|||||||
"value": "prisma-client-js"
|
"value": "prisma-client-js"
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"value": "C:\\Users\\Rother\\fork\\ironie-nextjs\\src\\generated\\prisma",
|
"value": "C:\\Users\\Chris\\fork\\ironie-nextjs\\src\\generated\\prisma",
|
||||||
"fromEnvVar": null
|
"fromEnvVar": null
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
@ -420,7 +420,7 @@ const config = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"previewFeatures": [],
|
"previewFeatures": [],
|
||||||
"sourceFilePath": "C:\\Users\\Rother\\fork\\ironie-nextjs\\prisma\\schema.prisma",
|
"sourceFilePath": "C:\\Users\\Chris\\fork\\ironie-nextjs\\prisma\\schema.prisma",
|
||||||
"isCustomOutput": true
|
"isCustomOutput": true
|
||||||
},
|
},
|
||||||
"relativeEnvPaths": {
|
"relativeEnvPaths": {
|
||||||
|
|||||||
@ -405,7 +405,7 @@ const config = {
|
|||||||
"value": "prisma-client-js"
|
"value": "prisma-client-js"
|
||||||
},
|
},
|
||||||
"output": {
|
"output": {
|
||||||
"value": "C:\\Users\\Rother\\fork\\ironie-nextjs\\src\\generated\\prisma",
|
"value": "C:\\Users\\Chris\\fork\\ironie-nextjs\\src\\generated\\prisma",
|
||||||
"fromEnvVar": null
|
"fromEnvVar": null
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
@ -419,7 +419,7 @@ const config = {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"previewFeatures": [],
|
"previewFeatures": [],
|
||||||
"sourceFilePath": "C:\\Users\\Rother\\fork\\ironie-nextjs\\prisma\\schema.prisma",
|
"sourceFilePath": "C:\\Users\\Chris\\fork\\ironie-nextjs\\prisma\\schema.prisma",
|
||||||
"isCustomOutput": true
|
"isCustomOutput": true
|
||||||
},
|
},
|
||||||
"relativeEnvPaths": {
|
"relativeEnvPaths": {
|
||||||
|
|||||||
@ -23,6 +23,16 @@ export type FaceitPlayer = {
|
|||||||
games?: Record<'cs2' | 'csgo' | string, FaceitGame>
|
games?: Record<'cs2' | 'csgo' | string, FaceitGame>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Hilfsfunktion: {lang} → en normalisieren */
|
||||||
|
function normalizeFaceitUrl(url?: string | null): string | undefined {
|
||||||
|
if (!url) return undefined
|
||||||
|
// häufiges Muster: https://www.faceit.com/{lang}/players/<nick>
|
||||||
|
// wir ersetzen sowohl "/{lang}/" als auch nacktes "{lang}"
|
||||||
|
return url
|
||||||
|
.replace('/{lang}/', '/en/')
|
||||||
|
.replace('{lang}', 'en')
|
||||||
|
}
|
||||||
|
|
||||||
/** Nur holen – kein DB-Schreibzugriff */
|
/** Nur holen – kein DB-Schreibzugriff */
|
||||||
export async function fetchFaceitBySteam64(
|
export async function fetchFaceitBySteam64(
|
||||||
steam64: string,
|
steam64: string,
|
||||||
@ -60,7 +70,7 @@ export async function upsertFaceitProfile(
|
|||||||
steam64: string,
|
steam64: string,
|
||||||
faceit: FaceitPlayer
|
faceit: FaceitPlayer
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// 1) User-Metadaten aktualisieren
|
// 1) User-Metadaten aktualisieren (faceit_url normalisiert)
|
||||||
await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: { steamId: steam64 },
|
where: { steamId: steam64 },
|
||||||
data: {
|
data: {
|
||||||
@ -68,7 +78,7 @@ export async function upsertFaceitProfile(
|
|||||||
faceitNickname: faceit.nickname,
|
faceitNickname: faceit.nickname,
|
||||||
faceitAvatar: faceit.avatar ?? undefined,
|
faceitAvatar: faceit.avatar ?? undefined,
|
||||||
faceitCountry: faceit.country ?? undefined,
|
faceitCountry: faceit.country ?? undefined,
|
||||||
faceitUrl: faceit.faceit_url ?? undefined,
|
faceitUrl: normalizeFaceitUrl(faceit.faceit_url),
|
||||||
faceitVerified: !!faceit.verified,
|
faceitVerified: !!faceit.verified,
|
||||||
faceitActivatedAt: faceit.activated_at ? new Date(faceit.activated_at) : undefined,
|
faceitActivatedAt: faceit.activated_at ? new Date(faceit.activated_at) : undefined,
|
||||||
faceitSteamId64: faceit.steam_id_64 ?? steam64,
|
faceitSteamId64: faceit.steam_id_64 ?? steam64,
|
||||||
@ -91,18 +101,15 @@ export async function upsertFaceitProfile(
|
|||||||
gamePlayerName: g.game_player_name ?? null,
|
gamePlayerName: g.game_player_name ?? null,
|
||||||
skillLevel: g.skill_level ?? null,
|
skillLevel: g.skill_level ?? null,
|
||||||
elo: g.faceit_elo ?? null,
|
elo: g.faceit_elo ?? null,
|
||||||
skillLabel: g.skill_level_label ?? null,
|
|
||||||
gameProfileId: g.game_profile_id ?? null,
|
gameProfileId: g.game_profile_id ?? null,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
userSteamId: steam64,
|
userSteamId: steam64,
|
||||||
game: gameId as any, // 'cs2' | 'csgo' (enum in Prisma)
|
game: gameId as any, // 'cs2' | 'csgo' (enum in Prisma)
|
||||||
region: g.region ?? null,
|
region: g.region ?? null,
|
||||||
gamePlayerId: g.game_player_id ?? null,
|
|
||||||
gamePlayerName: g.game_player_name ?? null,
|
gamePlayerName: g.game_player_name ?? null,
|
||||||
skillLevel: g.skill_level ?? null,
|
skillLevel: g.skill_level ?? null,
|
||||||
elo: g.faceit_elo ?? null,
|
elo: g.faceit_elo ?? null,
|
||||||
skillLabel: g.skill_level_label ?? null,
|
|
||||||
gameProfileId: g.game_profile_id ?? null,
|
gameProfileId: g.game_profile_id ?? null,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user