define API return type

This commit is contained in:
leander committed 2025-06-20 22:56:21 +02:00
1 parent c86da26f7b
commit 469dd70c45
2 files changed
+14 -2

No files matched your search

+2 -2
View File
@@ -1,11 +1,11 @@
import type { Match } from "@/types"; import type { Match, NorwegianPersonItem } from "@/types";
export async function findNorwegianPerson(input: string): Promise<Match> { export async function findNorwegianPerson(input: string): Promise<Match> {
const apiUrl = `https://snl.no/api/v1/search?query=${encodeURIComponent(input)}&limit=5`; const apiUrl = `https://snl.no/api/v1/search?query=${encodeURIComponent(input)}&limit=5`;
const response = await fetch(apiUrl); const response = await fetch(apiUrl);
const data = await response.json(); const data = await response.json();
function isNorwegianPerson(item: any): boolean { function isNorwegianPerson(item: NorwegianPersonItem): boolean {
// Must be a biography // Must be a biography
if (item.article_type_id !== 2) return false; if (item.article_type_id !== 2) return false;
+12
View File
@@ -4,3 +4,15 @@ export interface Match {
description: string | undefined; description: string | undefined;
correct: boolean; correct: boolean;
} }
export interface NorwegianPersonItem {
article_type_id: number;
rank: number;
taxonomy_title?: string;
subject_title?: string;
first_sentences?: string;
snippet?: string;
title?: string;
headword?: string;
article_url_json?: string;
}