@@ -24,7 +24,6 @@ const getResourceHostnamesParamsSchema = z
24
24
} )
25
25
. strict ( ) ;
26
26
27
-
28
27
async function query ( resourceId ?: number , niceId ?: string , orgId ?: string ) {
29
28
if ( resourceId ) {
30
29
const [ res ] = await db
@@ -43,8 +42,7 @@ async function query(resourceId?: number, niceId?: string, orgId?: string) {
43
42
}
44
43
}
45
44
46
- export type GetResourceResponseWithHostnames = {
47
- data : Resource ;
45
+ export type GetResourceResponse = Resource & {
48
46
hostMode : string ;
49
47
hostnames : Array < {
50
48
hostnameId : number ;
@@ -53,12 +51,9 @@ export type GetResourceResponseWithHostnames = {
53
51
fullDomain : string ;
54
52
baseDomain : string ;
55
53
primary : boolean ;
56
- createdAt : string ;
57
54
} > ;
58
55
} ;
59
56
60
- export type GetResourceResponse = Resource ;
61
-
62
57
63
58
registry . registerPath ( {
64
59
method : "get" ,
@@ -87,6 +82,7 @@ registry.registerPath({
87
82
} ,
88
83
responses : { }
89
84
} ) ;
85
+
90
86
export async function getResource (
91
87
req : Request ,
92
88
res : Response ,
@@ -105,7 +101,6 @@ export async function getResource(
105
101
106
102
const { resourceId, niceId, orgId } = parsedParams . data ;
107
103
108
- // Use new query helper
109
104
const resource = await query ( resourceId , niceId , orgId ) ;
110
105
111
106
if ( ! resource ) {
@@ -114,19 +109,6 @@ export async function getResource(
114
109
) ;
115
110
}
116
111
117
- // Only HTTP resources have hostnames
118
- if ( ! resource . http ) {
119
- return response < GetResourceResponse > ( res , {
120
- data : resource ,
121
- success : true ,
122
- error : false ,
123
- message : "Resource retrieved successfully" ,
124
- status : HttpCode . OK
125
- } ) ;
126
- }
127
-
128
-
129
- // Get hostnames for the resource
130
112
const hostnames = await db
131
113
. select ( {
132
114
hostnameId : resourceHostnames . hostnameId ,
@@ -141,9 +123,9 @@ export async function getResource(
141
123
. where ( eq ( resourceHostnames . resourceId , resource . resourceId ) )
142
124
. orderBy ( resourceHostnames . primary , resourceHostnames . createdAt ) ;
143
125
144
- return response < GetResourceResponseWithHostnames > ( res , {
126
+ return response < GetResourceResponse > ( res , {
145
127
data : {
146
- data : resource ,
128
+ ... resource ,
147
129
hostMode : resource . hostMode || "multi" ,
148
130
hostnames : hostnames . map ( h => ( {
149
131
hostnameId : h . hostnameId ,
@@ -152,18 +134,17 @@ export async function getResource(
152
134
fullDomain : h . fullDomain ,
153
135
baseDomain : h . baseDomain ,
154
136
primary : h . primary ,
155
- createdAt : h . createdAt
156
- } ) )
137
+ } ) ) ,
157
138
} ,
158
139
success : true ,
159
140
error : false ,
160
- message : "Resource hostnames retrieved successfully" ,
161
- status : HttpCode . OK
141
+ message : "Resource retrieved successfully" ,
142
+ status : HttpCode . OK ,
162
143
} ) ;
163
144
} catch ( error ) {
164
145
logger . error ( error ) ;
165
146
return next (
166
147
createHttpError ( HttpCode . INTERNAL_SERVER_ERROR , "An error occurred" )
167
148
) ;
168
149
}
169
- }
150
+ }
0 commit comments