brackt/app/routes/admin/jobs.sync-matches.ts
chrisp f40144e1e2
All checks were successful
🚀 Deploy / 🧪 Test (push) Successful in 2m45s
🚀 Deploy / ʦ🔍 Typecheck & Lint (push) Successful in 1m24s
🚀 Deploy / 🐳 Build (push) Successful in 1m14s
🚀 Deploy / 🚀 Deploy (push) Successful in 10s
claude/great-lovelace-r3bznh (#88)
Co-authored-by: Claude <noreply@anthropic.com>
Reviewed-on: #88
2026-06-12 22:35:35 +00:00

41 lines
1.2 KiB
TypeScript

import { and, eq, isNotNull } from "drizzle-orm";
import { database } from "~/database/context";
import * as schema from "~/database/schema";
import { requireCronSecret } from "~/lib/cron-auth";
import { syncMatches } from "~/services/match-sync";
export async function action({ request }: { request: Request }) {
requireCronSecret(request);
const db = database();
const seasons = await db.query.sportsSeasons.findMany({
where: and(
isNotNull(schema.sportsSeasons.externalSeasonId),
eq(schema.sportsSeasons.status, "active")
),
with: { sport: true },
});
const synced: string[] = [];
const errors: { id: string; name: string; error: string }[] = [];
for (const season of seasons) {
try {
const result = await syncMatches(season.id);
synced.push(season.id);
if (result.errors.length > 0) {
for (const e of result.errors) {
errors.push({ id: season.id, name: season.name, error: e.error });
}
}
} catch (err) {
errors.push({
id: season.id,
name: season.name,
error: err instanceof Error ? err.message : String(err),
});
}
}
return Response.json({ synced, errors }, { status: errors.length > 0 && synced.length === 0 ? 500 : 200 });
}