Skip to content

Commit 82b5195

Browse files
committed
refactor params.twig
1 parent c75aa6f commit 82b5195

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

templates/node/base/params.twig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
let payload = {};
2+
{% if method.parameters.all | length %}
13
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
24
{% if parameter.required %}
35
if (typeof {{ parameter.name | caseCamel | escapeKeyword }} === 'undefined') {
@@ -6,3 +8,16 @@
68

79
{% endif %}
810
{% endfor %}
11+
{% for parameter in method.parameters.query %}
12+
13+
if (typeof {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
14+
payload['{{ parameter.name }}'] = {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% if method.consumes[0] == "multipart/form-data" and ( parameter.type != "string" and parameter.type != "array" and parameter.type != "file" ) %}.toString(){% endif %};
15+
}
16+
{% endfor %}
17+
{% for parameter in method.parameters.body %}
18+
19+
if (typeof {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
20+
payload['{{ parameter.name }}'] = {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword}}{% if method.consumes[0] == "multipart/form-data" and ( parameter.type != "string" and parameter.type != "array" and parameter.type != "file" ) %}.toString(){% endif %};
21+
}
22+
{% endfor %}
23+
{% endif %}

templates/node/lib/services/service.js.twig

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,7 @@ class {{ service.name | caseUcfirst }} extends Service {
5858
async {{ method.name | caseCamel }}({% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = () => {}{% endif %}) {
5959
{# modified params section #}
6060
let path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
61-
let payload = {};
62-
{% for parameter in method.parameters.query %}
63-
64-
if (typeof {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
65-
payload['{{ parameter.name }}'] = {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% if method.consumes[0] == "multipart/form-data" and ( parameter.type != "string" and parameter.type != "array" and parameter.type != "file" ) %}.toString(){% endif %};
66-
}
67-
{% endfor %}
68-
{% for parameter in method.parameters.body %}
69-
70-
if (typeof {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }} !== 'undefined') {
71-
payload['{{ parameter.name }}'] = {% if parameter.isGlobal %}this.{% endif %}{{ parameter.name | caseCamel | escapeKeyword}}{% if method.consumes[0] == "multipart/form-data" and ( parameter.type != "string" and parameter.type != "array" and parameter.type != "file" ) %}.toString(){% endif %};
72-
}
73-
{% endfor %}
61+
{# modified params #}
7462

7563
{% if 'multipart/form-data' in method.consumes %}
7664
{# file section #}

0 commit comments

Comments
 (0)