@@ -33,6 +33,37 @@ export default async (fastify: FastifyInstance) => {
3333 return data
3434 } )
3535
36+ // HACK: Dark arts to get around https://github.com/delvedor/find-my-way/issues/285:
37+ // - this route has to be before /:tableId(^\\d+$)
38+ // - can't do :tableId(^\\d+$) instead of :tableId(^\\d+)
39+ // - need to separate :ordinalPosition as a 2nd param
40+ //
41+ // Anyhow, this probably just happens to work.
42+ fastify . get < {
43+ Headers : { pg : string }
44+ Params : {
45+ tableId : string
46+ ordinalPosition : string
47+ }
48+ } > ( '/:tableId(^\\d+).:ordinalPosition(^\\d+$)' , async ( request , reply ) => {
49+ const {
50+ headers : { pg : connectionString } ,
51+ params : { tableId, ordinalPosition } ,
52+ } = request
53+
54+ const pgMeta = new PostgresMeta ( { ...DEFAULT_POOL_CONFIG , connectionString } )
55+ const { data, error } = await pgMeta . columns . retrieve ( { id : `${ tableId } .${ ordinalPosition } ` } )
56+ await pgMeta . end ( )
57+ if ( error ) {
58+ request . log . error ( { error, request : extractRequestForLogging ( request ) } )
59+ reply . code ( 400 )
60+ if ( error . message . startsWith ( 'Cannot find' ) ) reply . code ( 404 )
61+ return { error : error . message }
62+ }
63+
64+ return data
65+ } )
66+
3667 fastify . get < {
3768 Headers : { pg : string }
3869 Params : { tableId : number }
@@ -66,27 +97,6 @@ export default async (fastify: FastifyInstance) => {
6697 return data
6798 } )
6899
69- fastify . get < {
70- Headers : { pg : string }
71- Params : {
72- id : string
73- }
74- } > ( '/:id(\\d+\\.\\d+)' , async ( request , reply ) => {
75- const connectionString = request . headers . pg
76-
77- const pgMeta = new PostgresMeta ( { ...DEFAULT_POOL_CONFIG , connectionString } )
78- const { data, error } = await pgMeta . columns . retrieve ( { id : request . params . id } )
79- await pgMeta . end ( )
80- if ( error ) {
81- request . log . error ( { error, request : extractRequestForLogging ( request ) } )
82- reply . code ( 400 )
83- if ( error . message . startsWith ( 'Cannot find' ) ) reply . code ( 404 )
84- return { error : error . message }
85- }
86-
87- return data
88- } )
89-
90100 fastify . post < {
91101 Headers : { pg : string }
92102 Body : any
0 commit comments