Skip to content

Commit 812cb18

Browse files
committed
updated dominion
1 parent 4f60160 commit 812cb18

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

.docsalot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
ignore:
2-
- app/api/*
2+
- app/api/**/*

app/api/dominions/[id]/route.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { NextResponse } from 'next/server';
2+
import { prisma } from '../../../../lib/prisma';
3+
4+
export async function GET(
5+
request: Request,
6+
{ params }: { params: { id: string } }
7+
) {
8+
try {
9+
const { id } = params;
10+
const dominion = await prisma.dominion.findUnique({
11+
where: { id },
12+
include: {
13+
posts: true, // Include posts by the dominion
14+
accounts: true, // Include dominion accounts
15+
},
16+
});
17+
18+
if (!dominion) {
19+
return NextResponse.json({ message: 'dominion not found' }, { status: 404 });
20+
}
21+
22+
return NextResponse.json(dominion);
23+
} catch (error) {
24+
console.error('Error fetching dominion:', error);
25+
return NextResponse.json({ message: 'Error fetching dominion' }, { status: 500 });
26+
}
27+
}

app/api/dominions/stats/routs.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { NextResponse } from 'next/server'
2+
import { prisma } from '@/lib/prisma'
3+
import { getServerSession } from 'next-auth'
4+
5+
export async function GET() {
6+
const session = await getServerSession()
7+
8+
if (!session) {
9+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
10+
}
11+
12+
try {
13+
const totaldominion = await prisma.dominion.count()
14+
const activedominion = await prisma.session.count({
15+
where: {
16+
expires: {
17+
gt: new Date()
18+
}
19+
}
20+
})
21+
22+
const recentdominion = await prisma.dominion.count({
23+
where: {
24+
createdAt: {
25+
gte: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) // Last 7 days
26+
}
27+
}
28+
})
29+
30+
return NextResponse.json({
31+
totaldominion,
32+
activedominion,
33+
recentdominions,
34+
timestamp: new Date().toISOString()
35+
})
36+
} catch (error) {
37+
console.error('Stats error:', error)
38+
return NextResponse.json({ error: 'Failed to fetch stats' }, { status: 500 })
39+
}
40+
}

0 commit comments

Comments
 (0)