Skip to content

Commit aa0cb69

Browse files
authored
Merge pull request #251 from nulib/deploy/staging
Update production.
2 parents c1fe5a1 + 34d19f8 commit aa0cb69

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

pages/legacy-pid/[pid].tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { ApiSearchResponse } from "@/types/api/response";
2+
import { DC_API_SEARCH_URL } from "@/lib/constants/endpoints";
3+
import { GetServerSideProps } from "next";
4+
import { ParsedUrlQuery } from "querystring";
5+
import { apiPostRequest } from "@/lib/dc-api";
6+
7+
const LegacyPid = () => null;
8+
9+
interface Params extends ParsedUrlQuery {
10+
pid: string;
11+
}
12+
13+
export const getServerSideProps: GetServerSideProps = async ({ params }) => {
14+
const { pid } = params as Params;
15+
const response = await apiPostRequest<ApiSearchResponse>({
16+
body: {
17+
_source: ["id"],
18+
query: {
19+
bool: {
20+
must: [
21+
{
22+
match: {
23+
legacy_identifier: pid,
24+
},
25+
},
26+
],
27+
},
28+
},
29+
size: 1,
30+
},
31+
url: DC_API_SEARCH_URL,
32+
});
33+
34+
if (!response?.data.length)
35+
return {
36+
notFound: true,
37+
};
38+
39+
return {
40+
redirect: {
41+
destination: `/items/${response.data[0].id}`,
42+
permanent: true,
43+
},
44+
};
45+
};
46+
47+
export default LegacyPid;

0 commit comments

Comments
 (0)