diff --git a/app/api/sync/route.ts b/app/api/sync/route.ts index 7abfadb8..8ed16460 100644 --- a/app/api/sync/route.ts +++ b/app/api/sync/route.ts @@ -6,21 +6,6 @@ import { getLastSync, setLastSync } from '@/lib/db/system'; import { normalize, toCompositionId } from '@/lib/xws'; import { percentile } from '@/lib/utils/math.utils'; -// GET -// --------------- -export const GET = async () => { - const lastSync = await getLastSync(); - return NextResponse.json( - { - name: 'Sync!', - message: `Latest sync at ${lastSync}`, - }, - { - status: 200, - } - ); -}; - // POST // --------------- export const POST = async (request: NextRequest) => { @@ -41,7 +26,7 @@ export const POST = async (request: NextRequest) => { // Find new tournaments const tournaments = await getAllTournaments({ - from: lastSync, + created_after: lastSync, format: 'standard', }).then(result => result.map(({ id, name, date }) => ({ diff --git a/lib/vendor/listfortress.ts b/lib/vendor/listfortress.ts index 5261e136..7532a362 100644 --- a/lib/vendor/listfortress.ts +++ b/lib/vendor/listfortress.ts @@ -29,6 +29,10 @@ export interface TournamentFilter { * Tournaments occured at or before given date. */ to?: Date; + /** + * Tournament was created (added to DB) after given date. + */ + created_after?: Date; } export const getAllTournaments = async ({ @@ -36,6 +40,7 @@ export const getAllTournaments = async ({ format, from, to, + created_after, }: TournamentFilter = {}) => { const api_url = 'https://listfortress.com/api/v1/tournaments/'; const res = await fetch(api_url); @@ -59,15 +64,19 @@ export const getAllTournaments = async ({ // Occured in given time frame const date = new Date(t.date); - if (from && date < from) { return false; } - if (to && date > to) { return false; } + // Created after given date + const created = new Date(t.created_at); + if (created_after && created < created_after) { + return false; + } + return true; }); };