diff --git a/frontend/src/routes/app/admin/dictionary-search/dictionarySearch.remote.ts b/frontend/src/routes/app/admin/dictionary-search/dictionarySearch.remote.ts index 16714b0..2d17801 100644 --- a/frontend/src/routes/app/admin/dictionary-search/dictionarySearch.remote.ts +++ b/frontend/src/routes/app/admin/dictionary-search/dictionarySearch.remote.ts @@ -1,17 +1,27 @@ import { query, getRequestEvent } from '$app/server'; import * as v from 'valibot'; import { - searchWordformsApiDictionarySearchGet, + searchWordformsPrefixApiDictionarySearchGet, searchWordformsApiDictionaryWordformsGet } from '../../../../client'; import { COOKIE_NAME_AUTH_TOKEN } from '$lib/auth'; +export type DictionarySearchResult = { + lemma: { + text: string; + }; + senses: { + text: string; + id: string; + }[]; +}; + export const dictionarySearch = query( v.object({ text: v.string(), langCode: v.string() }), - async ({ langCode, text }) => { + async ({ langCode, text }): Promise => { const { cookies } = getRequestEvent(); const trimmed = text.trim(); @@ -25,14 +35,26 @@ export const dictionarySearch = query( query: { lang_code: langCode, text } }); - return data; + return (data ?? []).map(({ lemma, senses }) => ({ + lemma: { text: lemma.headword }, + senses: senses.map(({ gloss, id }) => ({ + text: gloss, + id + })) + })); } else { - const { data } = await searchWordformsApiDictionarySearchGet({ + const { data } = await searchWordformsPrefixApiDictionarySearchGet({ headers: { Authorization: `Bearer ${cookies.get(COOKIE_NAME_AUTH_TOKEN)}` }, query: { lang_code: langCode, text } }); - return data; + return (data ?? []).map(({ lemma, senses }) => ({ + lemma: { text: lemma.headword }, + senses: senses.map(({ gloss, id }) => ({ + text: gloss, + id + })) + })); } } );