Skip to content

Commit

Permalink
Merge pull request #251 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Update production.
  • Loading branch information
mathewjordan authored Mar 8, 2023
2 parents c1fe5a1 + 34d19f8 commit aa0cb69
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pages/legacy-pid/[pid].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ApiSearchResponse } from "@/types/api/response";
import { DC_API_SEARCH_URL } from "@/lib/constants/endpoints";
import { GetServerSideProps } from "next";
import { ParsedUrlQuery } from "querystring";
import { apiPostRequest } from "@/lib/dc-api";

const LegacyPid = () => null;

interface Params extends ParsedUrlQuery {
pid: string;
}

export const getServerSideProps: GetServerSideProps = async ({ params }) => {
const { pid } = params as Params;
const response = await apiPostRequest<ApiSearchResponse>({
body: {
_source: ["id"],
query: {
bool: {
must: [
{
match: {
legacy_identifier: pid,
},
},
],
},
},
size: 1,
},
url: DC_API_SEARCH_URL,
});

if (!response?.data.length)
return {
notFound: true,
};

return {
redirect: {
destination: `/items/${response.data[0].id}`,
permanent: true,
},
};
};

export default LegacyPid;

0 comments on commit aa0cb69

Please sign in to comment.