Skip to content

Commit

Permalink
feat(website): add search-single page
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoran-chen committed Oct 31, 2024
1 parent 010fc8b commit 6b4ea03
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions website/src/pages/[organism]/search-single.ts
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)}`);
};

0 comments on commit 6b4ea03

Please sign in to comment.