Skip to content

Commit

Permalink
feat: use created date from listforstress to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
sebald committed Oct 11, 2023
1 parent 2fa660a commit 39efcac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
17 changes: 1 addition & 16 deletions app/api/sync/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 }) => ({
Expand Down
13 changes: 11 additions & 2 deletions lib/vendor/listfortress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ 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 ({
q,
format,
from,
to,
created_after,
}: TournamentFilter = {}) => {
const api_url = 'https://listfortress.com/api/v1/tournaments/';
const res = await fetch(api_url);
Expand All @@ -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;
});
};
Expand Down

1 comment on commit 39efcac

@vercel
Copy link

@vercel vercel bot commented on 39efcac Oct 11, 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.