@@ -33,6 +33,37 @@ export default async (fastify: FastifyInstance) => {
33
33
return data
34
34
} )
35
35
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
+
36
67
fastify . get < {
37
68
Headers : { pg : string }
38
69
Params : { tableId : number }
@@ -66,27 +97,6 @@ export default async (fastify: FastifyInstance) => {
66
97
return data
67
98
} )
68
99
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
-
90
100
fastify . post < {
91
101
Headers : { pg : string }
92
102
Body : any
0 commit comments