Skip to content

Commit

Permalink
Merge pull request #72 from Js41637/fix/api-past-events
Browse files Browse the repository at this point in the history
fix: include_past and page query params on events api
  • Loading branch information
CactusPuppy authored Oct 30, 2023
2 parents 56a2d5c + 132e05a commit 6994cdc
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/routes/api/events/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { SUPABASE_TABLE_NAME } from '$env/static/private'

export const GET: RequestHandler = async (request) => {
const { supabaseClient } = await getSupabase(request);
const { params, setHeaders } = request;
const pageNum = Number.parseInt(params["page"], 10) || 0;
const { url: { searchParams }, setHeaders } = request;

let pageNum = Number.parseInt(searchParams.get("page"), 10) || 1;
pageNum = pageNum < 1 ? 1 : pageNum;

const DATES_PAGE_SIZE = 25;

Expand All @@ -17,9 +19,10 @@ export const GET: RequestHandler = async (request) => {
.order("priority", {ascending: false})
.order("date", {ascending: true})

if (!params["include_past"]) { query = query.or(`date.gte.${formatISO(new Date())},end_date.gte.${formatISO(new Date())},date.is.null`) }
const includePast = searchParams.get("include_past") === "true";
if (!includePast) { query = query.or(`date.gte.${formatISO(new Date())},end_date.gte.${formatISO(new Date())},date.is.null`) }

query = query.range(pageNum * DATES_PAGE_SIZE, ((pageNum + 1) * DATES_PAGE_SIZE) - 1);
query = query.range((pageNum - 1) * DATES_PAGE_SIZE, (pageNum * DATES_PAGE_SIZE) - 1);

const { data, error: err } = await query;

Expand Down

1 comment on commit 6994cdc

@vercel
Copy link

@vercel vercel bot commented on 6994cdc Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.