diff --git a/src/app/api/admin/users/[accountId]/admin/route.ts b/src/app/api/admin/users/[accountId]/admin/route.ts index af3760d..3be4129 100644 --- a/src/app/api/admin/users/[accountId]/admin/route.ts +++ b/src/app/api/admin/users/[accountId]/admin/route.ts @@ -7,7 +7,7 @@ import logger from '@/lib/logger'; export async function POST( req: NextRequest, - { params }: { params: { accountId: string } } + { params }: { params: Promise<{ accountId: string }> } ) { try { const session = await getServerSession(authOptions); @@ -19,7 +19,7 @@ export async function POST( }, { status: 401 }); } - const { accountId } = params; + const { accountId } = await params; if (!accountId) { return NextResponse.json({ @@ -58,7 +58,7 @@ export async function POST( success: true, }); } catch (error) { - logger.error('Error toggling admin status:', { error }); + logger.error('Error toggling admin status:', error); return NextResponse.json({ message: "Failed to toggle admin status", success: false, diff --git a/src/app/api/admin/users/[accountId]/links/[shortId]/analytics/route.ts b/src/app/api/admin/users/[accountId]/links/[shortId]/analytics/route.ts index c8f7820..402cf13 100644 --- a/src/app/api/admin/users/[accountId]/links/[shortId]/analytics/route.ts +++ b/src/app/api/admin/users/[accountId]/links/[shortId]/analytics/route.ts @@ -7,7 +7,7 @@ import logger from '@/lib/logger'; export async function GET( req: NextRequest, - { params }: { params: { accountId: string, shortId: string } } + { params }: { params: Promise<{ accountId: string, shortId: string }> } ) { try { const session = await getServerSession(authOptions); @@ -51,7 +51,7 @@ export async function GET( success: true, }); } catch (error) { - logger.error('Error getting analytics:', { error, accountId: params.accountId, shortId: params.shortId }); + logger.error('Error getting analytics:', { error, accountId: (await params).accountId, shortId: (await params).shortId }); return NextResponse.json({ message: "Failed to retrieve analytics", success: false, @@ -61,7 +61,7 @@ export async function GET( export async function DELETE( req: NextRequest, - { params }: { params: { accountId: string, shortId: string } } + { params }: { params: Promise<{ accountId: string, shortId: string }> } ) { try { const session = await getServerSession(authOptions); @@ -107,7 +107,7 @@ export async function DELETE( success: false, }, { status: 400 }); } catch (error) { - logger.error('Error deleting analytics:', { error, accountId: params.accountId, shortId: params.shortId }); + logger.error('Error deleting analytics:', { error, accountId: (await params).accountId, shortId: (await params).shortId }); return NextResponse.json({ message: "Failed to delete analytics", success: false, diff --git a/src/app/api/admin/users/[accountId]/links/[shortId]/route.ts b/src/app/api/admin/users/[accountId]/links/[shortId]/route.ts index 6fdb5a8..16c971a 100644 --- a/src/app/api/admin/users/[accountId]/links/[shortId]/route.ts +++ b/src/app/api/admin/users/[accountId]/links/[shortId]/route.ts @@ -7,7 +7,7 @@ import logger from '@/lib/logger'; export async function GET( req: NextRequest, - { params }: { params: { accountId: string, shortId: string } } + { params }: { params: Promise<{ accountId: string, shortId: string }> } ) { try { const session = await getServerSession(authOptions); @@ -42,7 +42,7 @@ export async function GET( success: true, }); } catch (error) { - logger.error('Error getting link details:', { error, accountId: params.accountId, shortId: params.shortId }); + logger.error('Error getting link details:', { error, accountId: (await params).accountId, shortId: (await params).shortId }); return NextResponse.json({ message: "Failed to retrieve link details", success: false, @@ -52,7 +52,7 @@ export async function GET( export async function PATCH( req: NextRequest, - { params }: { params: { accountId: string, shortId: string } } + { params }: { params: Promise<{ accountId: string, shortId: string }> } ) { try { const session = await getServerSession(authOptions); @@ -90,7 +90,7 @@ export async function PATCH( success: result.success, }, { status: result.success ? 200 : 400 }); } catch (error) { - logger.error('Error updating link:', { error, accountId: params.accountId, shortId: params.shortId }); + logger.error('Error updating link:', { error, accountId: (await params).accountId, shortId: (await params).shortId }); return NextResponse.json({ message: "Failed to update link", success: false, @@ -100,7 +100,7 @@ export async function PATCH( export async function DELETE( req: NextRequest, - { params }: { params: { accountId: string, shortId: string } } + { params }: { params: Promise<{ accountId: string, shortId: string }> } ) { try { const session = await getServerSession(authOptions); @@ -128,7 +128,7 @@ export async function DELETE( success: result.success, }, { status: result.success ? 200 : 400 }); } catch (error) { - logger.error('Error deleting link:', { error, accountId: params.accountId, shortId: params.shortId }); + logger.error('Error deleting link:', { error, accountId: (await params).accountId, shortId: (await params).shortId }); return NextResponse.json({ message: "Failed to delete link", success: false, diff --git a/src/app/api/admin/users/[accountId]/links/route.ts b/src/app/api/admin/users/[accountId]/links/route.ts index 550c9f3..1a4e0e5 100644 --- a/src/app/api/admin/users/[accountId]/links/route.ts +++ b/src/app/api/admin/users/[accountId]/links/route.ts @@ -7,7 +7,7 @@ import logger from '@/lib/logger'; export async function GET( req: NextRequest, - { params }: { params: { accountId: string } } + { params }: { params: Promise<{ accountId: string }> } ) { try { const session = await getServerSession(authOptions); @@ -36,7 +36,7 @@ export async function GET( success: true, }); } catch (error) { - logger.error('Error getting user links:', { error }); + logger.error('Error getting user links:', error); return NextResponse.json({ message: "Failed to retrieve user links", success: false, diff --git a/src/app/api/admin/users/[accountId]/route.ts b/src/app/api/admin/users/[accountId]/route.ts index 87f2b37..7f8644c 100644 --- a/src/app/api/admin/users/[accountId]/route.ts +++ b/src/app/api/admin/users/[accountId]/route.ts @@ -7,7 +7,7 @@ import { sanitizeMongoDocument } from '@/lib/utils'; export async function GET( req: NextRequest, - { params }: { params: { accountId: string } } + { params }: { params: Promise<{ accountId: string }> } ) { try { const session = await getServerSession(authOptions); diff --git a/src/app/api/admin/users/[accountId]/sessions/route.ts b/src/app/api/admin/users/[accountId]/sessions/route.ts index c771bda..1a866ed 100644 --- a/src/app/api/admin/users/[accountId]/sessions/route.ts +++ b/src/app/api/admin/users/[accountId]/sessions/route.ts @@ -7,7 +7,7 @@ import logger from '@/lib/logger'; export async function GET( req: NextRequest, - { params }: { params: { accountId: string } } + { params }: { params: Promise<{ accountId: string }> } ) { try { const session = await getServerSession(authOptions); @@ -38,7 +38,7 @@ export async function GET( success: true, }); } catch (error) { - logger.error('Error getting user sessions:', { error }); + logger.error('Error getting user sessions:', error); return NextResponse.json({ message: "Failed to retrieve user sessions", success: false, diff --git a/src/app/dashboard/link/[shortId]/page.tsx b/src/app/dashboard/link/[shortId]/page.tsx index d695e88..7a32abf 100644 --- a/src/app/dashboard/link/[shortId]/page.tsx +++ b/src/app/dashboard/link/[shortId]/page.tsx @@ -4,12 +4,13 @@ import { useState, useEffect, useRef } from 'react'; import { useParams, useRouter } from 'next/navigation'; import Link from 'next/link'; import { useToast } from '@/contexts/ToastContext'; -import Graph, { StatItem } from '@/components/ui/Graph'; +import Graph from '@/components/ui/Graph'; import ConfirmModal from '@/components/ui/ConfirmModal'; import AnalyticsTable from '@/components/ui/dashboard/link/AnalyticsTable'; import styles from './LinkDetail.module.css'; import { Analytics } from '@/types/analytics'; -import { Link as LinkType } from '@/types/link'; +import type { Link as LinkType } from '@/types/link'; +import type { StatItem } from '@/types/statistics'; export default function LinkDetailPage() { const params = useParams(); diff --git a/src/app/l/[shortId]/route.ts b/src/app/l/[shortId]/route.ts index 96166d3..5a47355 100644 --- a/src/app/l/[shortId]/route.ts +++ b/src/app/l/[shortId]/route.ts @@ -6,7 +6,7 @@ import logger from '@/lib/logger'; export async function GET( req: NextRequest, - { params }: { params: { shortId: string } } + { params }: { params: Promise<{ shortId: string }> } ) { try { const { shortId } = await params; @@ -30,7 +30,7 @@ export async function GET( return NextResponse.redirect(new URL(link.target_url)); } catch (error) { - logger.error('Link redirection error', { error }); + logger.error('Link redirection error', error); return NextResponse.redirect(new URL('/error', req.url)); } } \ No newline at end of file diff --git a/src/components/ui/Graph.tsx b/src/components/ui/Graph.tsx index 228d16f..b284097 100644 --- a/src/components/ui/Graph.tsx +++ b/src/components/ui/Graph.tsx @@ -265,7 +265,7 @@ export default function Graph({ data={getBarData()} options={getOptions()} ref={(ref) => { - if (ref) chartRef.current = ref.chartInstance; + if (ref) chartRef.current = ref; }} /> )} @@ -274,7 +274,7 @@ export default function Graph({ data={getLineData()} options={getOptions()} ref={(ref) => { - if (ref) chartRef.current = ref.chartInstance; + if (ref) chartRef.current = ref; }} /> )} @@ -283,7 +283,7 @@ export default function Graph({ data={getDoughnutData()} options={getOptions()} ref={(ref) => { - if (ref) chartRef.current = ref.chartInstance; + if (ref) chartRef.current = ref; }} /> )} diff --git a/src/lib/mongodb.ts b/src/lib/mongodb.ts index dc57c2e..be30113 100644 --- a/src/lib/mongodb.ts +++ b/src/lib/mongodb.ts @@ -1,15 +1,5 @@ import { Db, MongoClient, ObjectId } from "mongodb"; -const uri = process.env.MONGO_URI!; -const dbName = process.env.MONGO_DB_NAME!; - -if (!process.env.MONGO_URI) { - throw new Error('Please add your MongoDB URI to .env'); -} -if (!process.env.MONGO_DB_NAME) { - throw new Error('Please add your MongoDB DB name to .env'); -} - let client: MongoClient; let db: Db; @@ -26,10 +16,17 @@ export async function getMongo(): Promise<{ client: MongoClient; db: Db }> { if (client && db) { return { client, db }; } + + if (!process.env.MONGO_URI) { + throw new Error('Please add your MongoDB URI to .env'); + } + if (!process.env.MONGO_DB_NAME) { + throw new Error('Please add your MongoDB DB name to .env'); + } - client = new MongoClient(uri); + client = new MongoClient(process.env.MONGO_URI); await client.connect(); - db = client.db(dbName); + db = client.db(process.env.MONGO_DB_NAME); return { client, db }; }