fixed errors

This commit is contained in:
MarcUs7i 2025-07-11 01:44:22 +02:00
parent 71bdd08da9
commit 9cf0a294ad
10 changed files with 35 additions and 37 deletions

View file

@ -7,7 +7,7 @@ import logger from '@/lib/logger';
export async function POST( export async function POST(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string } } { params }: { params: Promise<{ accountId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
@ -19,7 +19,7 @@ export async function POST(
}, { status: 401 }); }, { status: 401 });
} }
const { accountId } = params; const { accountId } = await params;
if (!accountId) { if (!accountId) {
return NextResponse.json({ return NextResponse.json({
@ -58,7 +58,7 @@ export async function POST(
success: true, success: true,
}); });
} catch (error) { } catch (error) {
logger.error('Error toggling admin status:', { error }); logger.error('Error toggling admin status:', error);
return NextResponse.json({ return NextResponse.json({
message: "Failed to toggle admin status", message: "Failed to toggle admin status",
success: false, success: false,

View file

@ -7,7 +7,7 @@ import logger from '@/lib/logger';
export async function GET( export async function GET(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string, shortId: string } } { params }: { params: Promise<{ accountId: string, shortId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
@ -51,7 +51,7 @@ export async function GET(
success: true, success: true,
}); });
} catch (error) { } 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({ return NextResponse.json({
message: "Failed to retrieve analytics", message: "Failed to retrieve analytics",
success: false, success: false,
@ -61,7 +61,7 @@ export async function GET(
export async function DELETE( export async function DELETE(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string, shortId: string } } { params }: { params: Promise<{ accountId: string, shortId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
@ -107,7 +107,7 @@ export async function DELETE(
success: false, success: false,
}, { status: 400 }); }, { status: 400 });
} catch (error) { } 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({ return NextResponse.json({
message: "Failed to delete analytics", message: "Failed to delete analytics",
success: false, success: false,

View file

@ -7,7 +7,7 @@ import logger from '@/lib/logger';
export async function GET( export async function GET(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string, shortId: string } } { params }: { params: Promise<{ accountId: string, shortId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
@ -42,7 +42,7 @@ export async function GET(
success: true, success: true,
}); });
} catch (error) { } 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({ return NextResponse.json({
message: "Failed to retrieve link details", message: "Failed to retrieve link details",
success: false, success: false,
@ -52,7 +52,7 @@ export async function GET(
export async function PATCH( export async function PATCH(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string, shortId: string } } { params }: { params: Promise<{ accountId: string, shortId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
@ -90,7 +90,7 @@ export async function PATCH(
success: result.success, success: result.success,
}, { status: result.success ? 200 : 400 }); }, { status: result.success ? 200 : 400 });
} catch (error) { } 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({ return NextResponse.json({
message: "Failed to update link", message: "Failed to update link",
success: false, success: false,
@ -100,7 +100,7 @@ export async function PATCH(
export async function DELETE( export async function DELETE(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string, shortId: string } } { params }: { params: Promise<{ accountId: string, shortId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
@ -128,7 +128,7 @@ export async function DELETE(
success: result.success, success: result.success,
}, { status: result.success ? 200 : 400 }); }, { status: result.success ? 200 : 400 });
} catch (error) { } 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({ return NextResponse.json({
message: "Failed to delete link", message: "Failed to delete link",
success: false, success: false,

View file

@ -7,7 +7,7 @@ import logger from '@/lib/logger';
export async function GET( export async function GET(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string } } { params }: { params: Promise<{ accountId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
@ -36,7 +36,7 @@ export async function GET(
success: true, success: true,
}); });
} catch (error) { } catch (error) {
logger.error('Error getting user links:', { error }); logger.error('Error getting user links:', error);
return NextResponse.json({ return NextResponse.json({
message: "Failed to retrieve user links", message: "Failed to retrieve user links",
success: false, success: false,

View file

@ -7,7 +7,7 @@ import { sanitizeMongoDocument } from '@/lib/utils';
export async function GET( export async function GET(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string } } { params }: { params: Promise<{ accountId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);

View file

@ -7,7 +7,7 @@ import logger from '@/lib/logger';
export async function GET( export async function GET(
req: NextRequest, req: NextRequest,
{ params }: { params: { accountId: string } } { params }: { params: Promise<{ accountId: string }> }
) { ) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
@ -38,7 +38,7 @@ export async function GET(
success: true, success: true,
}); });
} catch (error) { } catch (error) {
logger.error('Error getting user sessions:', { error }); logger.error('Error getting user sessions:', error);
return NextResponse.json({ return NextResponse.json({
message: "Failed to retrieve user sessions", message: "Failed to retrieve user sessions",
success: false, success: false,

View file

@ -4,12 +4,13 @@ import { useState, useEffect, useRef } from 'react';
import { useParams, useRouter } from 'next/navigation'; import { useParams, useRouter } from 'next/navigation';
import Link from 'next/link'; import Link from 'next/link';
import { useToast } from '@/contexts/ToastContext'; 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 ConfirmModal from '@/components/ui/ConfirmModal';
import AnalyticsTable from '@/components/ui/dashboard/link/AnalyticsTable'; import AnalyticsTable from '@/components/ui/dashboard/link/AnalyticsTable';
import styles from './LinkDetail.module.css'; import styles from './LinkDetail.module.css';
import { Analytics } from '@/types/analytics'; 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() { export default function LinkDetailPage() {
const params = useParams(); const params = useParams();

View file

@ -6,7 +6,7 @@ import logger from '@/lib/logger';
export async function GET( export async function GET(
req: NextRequest, req: NextRequest,
{ params }: { params: { shortId: string } } { params }: { params: Promise<{ shortId: string }> }
) { ) {
try { try {
const { shortId } = await params; const { shortId } = await params;
@ -30,7 +30,7 @@ export async function GET(
return NextResponse.redirect(new URL(link.target_url)); return NextResponse.redirect(new URL(link.target_url));
} catch (error) { } catch (error) {
logger.error('Link redirection error', { error }); logger.error('Link redirection error', error);
return NextResponse.redirect(new URL('/error', req.url)); return NextResponse.redirect(new URL('/error', req.url));
} }
} }

View file

@ -265,7 +265,7 @@ export default function Graph({
data={getBarData()} data={getBarData()}
options={getOptions()} options={getOptions()}
ref={(ref) => { ref={(ref) => {
if (ref) chartRef.current = ref.chartInstance; if (ref) chartRef.current = ref;
}} }}
/> />
)} )}
@ -274,7 +274,7 @@ export default function Graph({
data={getLineData()} data={getLineData()}
options={getOptions()} options={getOptions()}
ref={(ref) => { ref={(ref) => {
if (ref) chartRef.current = ref.chartInstance; if (ref) chartRef.current = ref;
}} }}
/> />
)} )}
@ -283,7 +283,7 @@ export default function Graph({
data={getDoughnutData()} data={getDoughnutData()}
options={getOptions()} options={getOptions()}
ref={(ref) => { ref={(ref) => {
if (ref) chartRef.current = ref.chartInstance; if (ref) chartRef.current = ref;
}} }}
/> />
)} )}

View file

@ -1,15 +1,5 @@
import { Db, MongoClient, ObjectId } from "mongodb"; 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 client: MongoClient;
let db: Db; let db: Db;
@ -27,9 +17,16 @@ export async function getMongo(): Promise<{ client: MongoClient; db: Db }> {
return { client, db }; return { client, db };
} }
client = new MongoClient(uri); 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(process.env.MONGO_URI);
await client.connect(); await client.connect();
db = client.db(dbName); db = client.db(process.env.MONGO_DB_NAME);
return { client, db }; return { client, db };
} }