Some checks failed
Test and deploy staging / staging (push) Failing after 5m29s
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { json, error } from '@sveltejs/kit';
|
|
import { and, asc, eq } from 'drizzle-orm';
|
|
import { db } from '$lib/server/db';
|
|
import { pokemon, pokemonEncounters } from '$lib/server/db/schema';
|
|
|
|
export async function GET({ url }) {
|
|
const gameId = Number(url.searchParams.get('game'));
|
|
const locationId = Number(url.searchParams.get('location'));
|
|
if (![gameId, locationId].every((n) => Number.isSafeInteger(n) && n > 0 && n <= 2147483647))
|
|
error(400, 'Invalid game or location');
|
|
const rows = await db
|
|
.select({
|
|
pokemonId: pokemon.id,
|
|
number: pokemon.number,
|
|
name: pokemon.name,
|
|
type1: pokemon.type1,
|
|
type2: pokemon.type2,
|
|
area: pokemonEncounters.area,
|
|
method: pokemonEncounters.method,
|
|
minLevel: pokemonEncounters.minLevel,
|
|
maxLevel: pokemonEncounters.maxLevel,
|
|
rarity: pokemonEncounters.rarity,
|
|
conditions: pokemonEncounters.conditions,
|
|
form: pokemonEncounters.form,
|
|
note: pokemonEncounters.note
|
|
})
|
|
.from(pokemonEncounters)
|
|
.innerJoin(pokemon, eq(pokemon.id, pokemonEncounters.pokemonId))
|
|
.where(and(eq(pokemonEncounters.gameId, gameId), eq(pokemonEncounters.locationId, locationId)))
|
|
.orderBy(asc(pokemon.number), asc(pokemonEncounters.method), asc(pokemonEncounters.minLevel));
|
|
return json(rows, { headers: { 'Cache-Control': 'public, max-age=3600' } });
|
|
}
|