-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(website): add search-single page
- Loading branch information
1 parent
010fc8b
commit 6b4ea03
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { APIRoute } from 'astro'; | ||
|
||
import { LapisClient } from '../../services/lapisClient.ts'; | ||
|
||
export const GET: APIRoute = async ({ params, request, redirect }) => { | ||
const url = new URL(request.url); | ||
const submissionId = url.searchParams.get('submissionId'); | ||
const organism = params.organism!; | ||
|
||
if (submissionId == null) { | ||
return new Response('submissionId parameter is required', { status: 400 }); | ||
} | ||
const client = LapisClient.createForOrganism(organism); | ||
const responseData = await client.call('details', { | ||
submissionId, | ||
versionStatus: 'LATEST_VERSION', | ||
isRevocation: "false", | ||
fields: ['accessionVersion'] | ||
}); | ||
const accessionVersions = responseData.unwrapOr({data: []}).data.map(d => d.accessionVersion); | ||
if (accessionVersions.length === 1) { | ||
return redirect(`/seq/${accessionVersions[0]}`) | ||
} | ||
return redirect(`/${params.organism}/search?submissionId=${encodeURIComponent(submissionId)}`); | ||
}; |