Skip to content

Commit 0dd5283

Browse files
committed
refactor(python): extract method formatParamsAsPythonDict()
1 parent ca5089a commit 0dd5283

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/cli.js

+8
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ const createEndpoints = async (destDir, { lang }, config) => {
272272
).join('\n\t\t\t')
273273
},
274274

275+
// [ "p.categoryId" ] => ', {"categoryId": body.categoryId}'
276+
// (used only with Python)
277+
"formatParamsAsPythonDict": (params) => {
278+
return params.length > 0
279+
? ', {' + params.map(param => param.substring(2)).map(param => `"${param}": body.${param}`).join(', ') + '}'
280+
: ''
281+
},
282+
275283
"placeholdersMap": placeholdersMap,
276284
"removeComments": removeComments,
277285
}

src/templates/routes.py.ejs

+1-4
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,7 @@ def <%- pythonMethodName %>(<%- methodArgs.join(', ') %>):
245245
246246
const sql = convertToPsycopgNamedArguments(formatQueryForPython(method.query, 20))
247247
const params = extractParamsFromQuery(method.query);
248-
const formattedParams = params.length > 0
249-
// [ "p.categoryId" ] => [ '"categoryId": body.categoryId' ]
250-
? ', {' + params.map(param => param.substring(2)).map(param => `"${param}": body.${param}`).join(', ') + '}'
251-
: ''
248+
const formattedParams = formatParamsAsPythonDict(params)
252249
253250
%>
254251

0 commit comments

Comments
 (0)