Files
vat-api.eu/server/api/admin/requests.get.ts
2026-02-14 10:14:49 +01:00

32 lines
798 B
TypeScript

export default defineEventHandler(async (event) => {
const query = getQuery(event);
const page = Math.max(1, parseInt(query.page as string) || 1);
const limit = Math.min(100, Math.max(1, parseInt(query.limit as string) || 50));
const ip = (query.ip as string) || undefined;
const db = await getDb();
const collection = db.collection("requests");
const filter: Record<string, unknown> = {};
if (ip) filter.ip = ip;
const [requests, total] = await Promise.all([
collection
.find(filter)
.sort({ timestamp: -1 })
.skip((page - 1) * limit)
.limit(limit)
.project({ _id: 0 })
.toArray(),
collection.countDocuments(filter),
]);
return {
requests,
total,
page,
limit,
totalPages: Math.ceil(total / limit),
};
});