feat: add AI event data fetching functions
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export async function getAIEvents(options?: {
|
||||
year?: number;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}) {
|
||||
const where = options?.year
|
||||
? {
|
||||
eventDate: {
|
||||
gte: new Date(`${options.year}-01-01T00:00:00Z`),
|
||||
lte: new Date(`${options.year}-12-31T23:59:59Z`),
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const events = await prisma.aIEvent.findMany({
|
||||
where,
|
||||
orderBy: { eventDate: 'desc' },
|
||||
take: options?.limit || 100,
|
||||
skip: options?.offset || 0,
|
||||
});
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
export async function getAIEventBySlug(slug: string) {
|
||||
// 暂不实现,后续如需要详细页面时添加
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getAllAIEventYears() {
|
||||
const events = await prisma.aIEvent.findMany({
|
||||
select: {
|
||||
eventDate: true,
|
||||
},
|
||||
orderBy: { eventDate: 'desc' },
|
||||
});
|
||||
|
||||
const years = new Set<number>();
|
||||
events.forEach(event => {
|
||||
years.add(new Date(event.eventDate).getFullYear());
|
||||
});
|
||||
|
||||
return Array.from(years).sort((a, b) => b - a);
|
||||
}
|
||||
Reference in New Issue
Block a user