File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments