@@ -149,6 +149,11 @@ function dtoInCache(dto) {
149
149
return dtoCache .hasOwnProperty (dto .signature )
150
150
}
151
151
152
+ function obtainDtoName (dto ) {
153
+ const cacheKey = dto ? dto .signature : null
154
+ return dtoInCache (dto) ? dtoCache[cacheKey] : dto .name
155
+ }
156
+
152
157
const verbs_with_dto = [ ' get' , ' post' , ' put' ]
153
158
endpoints .forEach (function (endpoint ) {
154
159
const dtos = endpoint .methods
@@ -181,8 +186,7 @@ endpoints.forEach(function(endpoint) {
181
186
if (hasGetOne || hasGetMany) {
182
187
const dto = query2dto (sqlParser, method)
183
188
// LATER: do we really need signature and cache?
184
- const cacheKey = dto ? dto .signature : null
185
- const dtoName = dtoInCache (dto) ? dtoCache[cacheKey] : dto .name
189
+ const dataType = obtainDtoName (dto)
186
190
const resultVariableDeclaration = hasGetMany
187
191
? ` result := []${ dtoName} \{\} `
188
192
: ` var result ${ dtoName} `
@@ -227,8 +231,7 @@ endpoints.forEach(function(endpoint) {
227
231
if (method .name === ' post' ) {
228
232
const dto = query2dto (sqlParser, method)
229
233
// LATER: do we really need signature and cache?
230
- const cacheKey = dto ? dto .signature : null
231
- const dataType = dtoInCache (dto) ? dtoCache[cacheKey] : dto .name
234
+ const dataType = obtainDtoName (dto)
232
235
% >
233
236
r .Post (" <%- path %>" , func (w http .ResponseWriter , r * http .Request ) {
234
237
var body < %- dataType % >
@@ -254,8 +257,7 @@ endpoints.forEach(function(endpoint) {
254
257
if (method .name === ' put' ) {
255
258
const dto = query2dto (sqlParser, method)
256
259
// LATER: do we really need signature and cache?
257
- const cacheKey = dto ? dto .signature : null
258
- const dataType = dtoInCache (dto) ? dtoCache[cacheKey] : dto .name
260
+ const dataType = obtainDtoName (dto)
259
261
% >
260
262
r .Put (" <%- path %>" , func (w http .ResponseWriter , r * http .Request ) {
261
263
var body < %- dataType % >
0 commit comments