fix: add admin
This commit is contained in:
31
server/api/admin/requests.get.ts
Normal file
31
server/api/admin/requests.get.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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),
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user