fix typecheck

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-04-16 21:03:03 +02:00
committed by Carl-Gerhard Lindesvärd
parent f4c79710e5
commit 04375807d0

View File

@@ -9,6 +9,7 @@ type EventsQuery = {
start?: string; start?: string;
end?: string; end?: string;
page?: string; page?: string;
limit?: string;
}; };
export async function events( export async function events(
request: FastifyRequest<{ request: FastifyRequest<{
@@ -17,6 +18,8 @@ export async function events(
reply: FastifyReply reply: FastifyReply
) { ) {
const query = request.query; const query = request.query;
const limit = parseInt(query.limit || '50', 10);
const page = parseInt(query.page || '1', 10);
if (query.project_id) { if (query.project_id) {
if ( if (
@@ -56,8 +59,8 @@ export async function events(
return; return;
} }
const take = Math.max(Math.min(query.limit, 50), 1); const take = Math.max(Math.min(limit, 50), 1);
const cursor = (parseInt(query.page || '1', 10) || 1) - 1; const cursor = page - 1;
const options: GetEventListOptions = { const options: GetEventListOptions = {
projectId, projectId,
events: (Array.isArray(query.event) ? query.event : [query.event]).filter( events: (Array.isArray(query.event) ? query.event : [query.event]).filter(
@@ -78,7 +81,6 @@ export async function events(
reply.send({ reply.send({
meta: { meta: {
// options,
count: data.length, count: data.length,
totalCount: totalCount, totalCount: totalCount,
pages: Math.ceil(totalCount / options.take), pages: Math.ceil(totalCount / options.take),