Skip to content

Commit 3955873

Browse files
committed
refactor(js,ts): format query parameters on multiple lines
1 parent 81cce99 commit 3955873

File tree

3 files changed

+62
-18
lines changed

3 files changed

+62
-18
lines changed

examples/js/express/mysql/routes.js

+27-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const register = (app, pool) => {
2727
JOIN series s
2828
ON s.id = cs.series_id
2929
WHERE cs.collection_id = :collectionId`,
30-
{ "collectionId": req.params.collectionId },
30+
{
31+
"collectionId": req.params.collectionId
32+
},
3133
(err, rows, fields) => {
3234
if (err) {
3335
return next(err)
@@ -81,7 +83,13 @@ const register = (app, pool) => {
8183
, NOW()
8284
, :user_id
8385
)`,
84-
{ "name": req.body.name, "name_ru": req.body.name_ru, "slug": req.body.slug, "hidden": req.body.hidden, "user_id": req.body.user_id },
86+
{
87+
"name": req.body.name,
88+
"name_ru": req.body.name_ru,
89+
"slug": req.body.slug,
90+
"hidden": req.body.hidden,
91+
"user_id": req.body.user_id
92+
},
8593
(err, rows, fields) => {
8694
if (err) {
8795
return next(err)
@@ -100,7 +108,9 @@ const register = (app, pool) => {
100108
, hidden
101109
FROM categories
102110
WHERE hidden = :hidden`,
103-
{ "hidden": parseBoolean(req.query.hidden) },
111+
{
112+
"hidden": parseBoolean(req.query.hidden)
113+
},
104114
(err, rows, fields) => {
105115
if (err) {
106116
return next(err)
@@ -119,7 +129,9 @@ const register = (app, pool) => {
119129
, hidden
120130
FROM categories
121131
WHERE id = :categoryId`,
122-
{ "categoryId": req.params.categoryId },
132+
{
133+
"categoryId": req.params.categoryId
134+
},
123135
(err, rows, fields) => {
124136
if (err) {
125137
return next(err)
@@ -143,7 +155,14 @@ const register = (app, pool) => {
143155
, updated_at = NOW()
144156
, updated_by = :user_id
145157
WHERE id = :categoryId`,
146-
{ "name": req.body.name, "name_ru": req.body.name_ru, "slug": req.body.slug, "hidden": req.body.hidden, "user_id": req.body.user_id, "categoryId": req.params.categoryId },
158+
{
159+
"name": req.body.name,
160+
"name_ru": req.body.name_ru,
161+
"slug": req.body.slug,
162+
"hidden": req.body.hidden,
163+
"user_id": req.body.user_id,
164+
"categoryId": req.params.categoryId
165+
},
147166
(err, rows, fields) => {
148167
if (err) {
149168
return next(err)
@@ -158,7 +177,9 @@ const register = (app, pool) => {
158177
`DELETE
159178
FROM categories
160179
WHERE id = :categoryId`,
161-
{ "categoryId": req.params.categoryId },
180+
{
181+
"categoryId": req.params.categoryId
182+
},
162183
(err, rows, fields) => {
163184
if (err) {
164185
return next(err)

examples/ts/express/mysql/routes.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const register = (app: Express, pool: Pool) => {
3030
JOIN series s
3131
ON s.id = cs.series_id
3232
WHERE cs.collection_id = :collectionId`,
33-
{ "collectionId": req.params.collectionId },
33+
{
34+
"collectionId": req.params.collectionId
35+
},
3436
(err, rows, fields) => {
3537
if (err) {
3638
return next(err)
@@ -84,7 +86,13 @@ const register = (app: Express, pool: Pool) => {
8486
, NOW()
8587
, :user_id
8688
)`,
87-
{ "name": req.body.name, "name_ru": req.body.name_ru, "slug": req.body.slug, "hidden": req.body.hidden, "user_id": req.body.user_id },
89+
{
90+
"name": req.body.name,
91+
"name_ru": req.body.name_ru,
92+
"slug": req.body.slug,
93+
"hidden": req.body.hidden,
94+
"user_id": req.body.user_id
95+
},
8896
(err, rows, fields) => {
8997
if (err) {
9098
return next(err)
@@ -103,7 +111,9 @@ const register = (app: Express, pool: Pool) => {
103111
, hidden
104112
FROM categories
105113
WHERE hidden = :hidden`,
106-
{ "hidden": parseBoolean(req.query.hidden) },
114+
{
115+
"hidden": parseBoolean(req.query.hidden)
116+
},
107117
(err, rows, fields) => {
108118
if (err) {
109119
return next(err)
@@ -122,7 +132,9 @@ const register = (app: Express, pool: Pool) => {
122132
, hidden
123133
FROM categories
124134
WHERE id = :categoryId`,
125-
{ "categoryId": req.params.categoryId },
135+
{
136+
"categoryId": req.params.categoryId
137+
},
126138
(err, rows, fields) => {
127139
if (err) {
128140
return next(err)
@@ -146,7 +158,14 @@ const register = (app: Express, pool: Pool) => {
146158
, updated_at = NOW()
147159
, updated_by = :user_id
148160
WHERE id = :categoryId`,
149-
{ "name": req.body.name, "name_ru": req.body.name_ru, "slug": req.body.slug, "hidden": req.body.hidden, "user_id": req.body.user_id, "categoryId": req.params.categoryId },
161+
{
162+
"name": req.body.name,
163+
"name_ru": req.body.name_ru,
164+
"slug": req.body.slug,
165+
"hidden": req.body.hidden,
166+
"user_id": req.body.user_id,
167+
"categoryId": req.params.categoryId
168+
},
150169
(err, rows, fields) => {
151170
if (err) {
152171
return next(err)
@@ -161,7 +180,9 @@ const register = (app: Express, pool: Pool) => {
161180
`DELETE
162181
FROM categories
163182
WHERE id = :categoryId`,
164-
{ "categoryId": req.params.categoryId },
183+
{
184+
"categoryId": req.params.categoryId
185+
},
165186
(err, rows, fields) => {
166187
if (err) {
167188
return next(err)

src/cli.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,23 @@ const createEndpoints = async (destDir, { lang }, config) => {
239239
if (params.length === 0) {
240240
return params
241241
}
242-
const indentLevel = 12
243-
const indent = ' '.repeat(indentLevel)
244-
return `\n${indent}{ ` + Array.from(
242+
const initialIndentLevel = 12
243+
const codeIndentLevel = initialIndentLevel + 4
244+
const initialIndent = ' '.repeat(initialIndentLevel)
245+
const indent = ' '.repeat(codeIndentLevel)
246+
return `\n${initialIndent}{\n` + Array.from(
245247
new Set(params),
246248
p => {
247249
const bindTarget = p.substring(0, 1)
248250
const paramName = p.substring(2)
249251
const prefix = placeholdersMap['js'][bindTarget]
250252
// LATER: add support for path (method.params.path) and body (method.dto.fields) parameters
251253
if (bindTarget === 'q' && retrieveType(method.params.query, paramName) === 'boolean') {
252-
return `"${paramName}": parseBoolean(${prefix}.${paramName})`
254+
return `${indent}"${paramName}": parseBoolean(${prefix}.${paramName})`
253255
}
254-
return `"${paramName}": ${prefix}.${paramName}`
256+
return `${indent}"${paramName}": ${prefix}.${paramName}`
255257
}
256-
).join(', ') + ' },'
258+
).join(',\n') + `\n${initialIndent}},`
257259
},
258260

259261
// "SELECT *\n FROM foo WHERE id = :p.id" => "SELECT * FROM foo WHERE id = :id"

0 commit comments

Comments
 (0)