Skip to content

Commit 9ffd4ca

Browse files
committed
fix(js): correct indentation of generated routes.js
1 parent b692d7d commit 9ffd4ca

File tree

2 files changed

+135
-139
lines changed

2 files changed

+135
-139
lines changed

examples/js/routes.js

Lines changed: 88 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,106 @@
11
const register = (app, pool) => {
22

3-
4-
app.get('/v1/categories/count', (req, res) => {
5-
pool.query(
6-
'SELECT COUNT(*) AS counter FROM categories',
7-
(err, rows, fields) => {
8-
if (err) {
9-
throw err
10-
}
11-
if (rows.length === 0) {
12-
res.status(404).end()
13-
return
3+
app.get('/v1/categories/count', (req, res) => {
4+
pool.query(
5+
'SELECT COUNT(*) AS counter FROM categories',
6+
(err, rows, fields) => {
7+
if (err) {
8+
throw err
9+
}
10+
if (rows.length === 0) {
11+
res.status(404).end()
12+
return
13+
}
14+
res.json(rows[0])
1415
}
15-
res.json(rows[0])
16-
}
17-
)
18-
})
16+
)
17+
})
1918

20-
app.get('/v1/collections/:collectionId/categories/count', (req, res) => {
21-
pool.query(
22-
'SELECT COUNT(DISTINCT s.category_id) AS counter FROM collections_series cs JOIN series s ON s.id = cs.series_id WHERE cs.collection_id = :collectionId',
23-
{ "collectionId": req.params.collectionId },
24-
(err, rows, fields) => {
25-
if (err) {
26-
throw err
27-
}
28-
if (rows.length === 0) {
29-
res.status(404).end()
30-
return
19+
app.get('/v1/collections/:collectionId/categories/count', (req, res) => {
20+
pool.query(
21+
'SELECT COUNT(DISTINCT s.category_id) AS counter FROM collections_series cs JOIN series s ON s.id = cs.series_id WHERE cs.collection_id = :collectionId',
22+
{ "collectionId": req.params.collectionId },
23+
(err, rows, fields) => {
24+
if (err) {
25+
throw err
26+
}
27+
if (rows.length === 0) {
28+
res.status(404).end()
29+
return
30+
}
31+
res.json(rows[0])
3132
}
32-
res.json(rows[0])
33-
}
34-
)
35-
})
33+
)
34+
})
3635

37-
app.get('/v1/categories', (req, res) => {
38-
pool.query(
39-
'SELECT id , name , name_ru , slug FROM categories LIMIT :limit',
40-
{ "limit": req.query.limit },
41-
(err, rows, fields) => {
42-
if (err) {
43-
throw err
36+
app.get('/v1/categories', (req, res) => {
37+
pool.query(
38+
'SELECT id , name , name_ru , slug FROM categories LIMIT :limit',
39+
{ "limit": req.query.limit },
40+
(err, rows, fields) => {
41+
if (err) {
42+
throw err
43+
}
44+
res.json(rows)
4445
}
45-
res.json(rows)
46-
}
47-
)
48-
})
46+
)
47+
})
4948

50-
app.post('/v1/categories', (req, res) => {
51-
pool.query(
52-
'INSERT INTO categories ( name , name_ru , slug , created_at , created_by , updated_at , updated_by ) VALUES ( :name , :name_ru , :slug , NOW() , :user_id , NOW() , :user_id )',
53-
{ "name": req.body.name, "name_ru": req.body.name_ru, "slug": req.body.slug, "user_id": req.body.user_id },
54-
(err, rows, fields) => {
55-
if (err) {
56-
throw err
49+
app.post('/v1/categories', (req, res) => {
50+
pool.query(
51+
'INSERT INTO categories ( name , name_ru , slug , created_at , created_by , updated_at , updated_by ) VALUES ( :name , :name_ru , :slug , NOW() , :user_id , NOW() , :user_id )',
52+
{ "name": req.body.name, "name_ru": req.body.name_ru, "slug": req.body.slug, "user_id": req.body.user_id },
53+
(err, rows, fields) => {
54+
if (err) {
55+
throw err
56+
}
57+
res.sendStatus(204)
5758
}
58-
res.sendStatus(204)
59-
}
60-
)
61-
})
59+
)
60+
})
6261

63-
app.get('/v1/categories/:categoryId', (req, res) => {
64-
pool.query(
65-
'SELECT id , name , name_ru , slug FROM categories WHERE id = :categoryId',
66-
{ "categoryId": req.params.categoryId },
67-
(err, rows, fields) => {
68-
if (err) {
69-
throw err
62+
app.get('/v1/categories/:categoryId', (req, res) => {
63+
pool.query(
64+
'SELECT id , name , name_ru , slug FROM categories WHERE id = :categoryId',
65+
{ "categoryId": req.params.categoryId },
66+
(err, rows, fields) => {
67+
if (err) {
68+
throw err
69+
}
70+
if (rows.length === 0) {
71+
res.status(404).end()
72+
return
73+
}
74+
res.json(rows[0])
7075
}
71-
if (rows.length === 0) {
72-
res.status(404).end()
73-
return
74-
}
75-
res.json(rows[0])
76-
}
77-
)
78-
})
76+
)
77+
})
7978

80-
app.put('/v1/categories/:categoryId', (req, res) => {
81-
pool.query(
82-
'UPDATE categories SET name = :name , name_ru = :name_ru , slug = :slug , updated_at = NOW() , updated_by = :user_id WHERE id = :categoryId',
83-
{ "name": req.body.name, "name_ru": req.body.name_ru, "slug": req.body.slug, "user_id": req.body.user_id, "categoryId": req.params.categoryId },
84-
(err, rows, fields) => {
85-
if (err) {
86-
throw err
79+
app.put('/v1/categories/:categoryId', (req, res) => {
80+
pool.query(
81+
'UPDATE categories SET name = :name , name_ru = :name_ru , slug = :slug , updated_at = NOW() , updated_by = :user_id WHERE id = :categoryId',
82+
{ "name": req.body.name, "name_ru": req.body.name_ru, "slug": req.body.slug, "user_id": req.body.user_id, "categoryId": req.params.categoryId },
83+
(err, rows, fields) => {
84+
if (err) {
85+
throw err
86+
}
87+
res.sendStatus(204)
8788
}
88-
res.sendStatus(204)
89-
}
90-
)
91-
})
89+
)
90+
})
9291

93-
app.delete('/v1/categories/:categoryId', (req, res) => {
94-
pool.query(
95-
'DELETE FROM categories WHERE id = :categoryId',
96-
{ "categoryId": req.params.categoryId },
97-
(err, rows, fields) => {
98-
if (err) {
99-
throw err
92+
app.delete('/v1/categories/:categoryId', (req, res) => {
93+
pool.query(
94+
'DELETE FROM categories WHERE id = :categoryId',
95+
{ "categoryId": req.params.categoryId },
96+
(err, rows, fields) => {
97+
if (err) {
98+
throw err
99+
}
100+
res.sendStatus(204)
100101
}
101-
res.sendStatus(204)
102-
}
103-
)
104-
})
105-
102+
)
103+
})
106104

107105
}
108106

src/templates/routes.js.ejs

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const register = (app, pool) => {
2-
32
<%
43
endpoints.forEach(function(endpoint) {
54
const path = endpoint.path;
@@ -14,81 +13,80 @@ endpoints.forEach(function(endpoint) {
1413
const sql = formatQuery(method.query);
1514
const params = extractParamsFromQuery(method.query);
1615
const formattedParams = params.length > 0
17-
? '\n { ' + formatParamsAsJavaScriptObject(params) + ' },'
16+
? '\n { ' + formatParamsAsJavaScriptObject(params) + ' },'
1817
: ''
1918
2019
if (hasGetOne || hasGetMany) {
2120
%>
22-
app.get('<%- path %>', (req, res) => {
23-
pool.query(
24-
'<%- sql %>',<%- formattedParams %>
25-
(err, rows, fields) => {
26-
if (err) {
27-
throw err
28-
}
21+
app.get('<%- path %>', (req, res) => {
22+
pool.query(
23+
'<%- sql %>',<%- formattedParams %>
24+
(err, rows, fields) => {
25+
if (err) {
26+
throw err
27+
}
2928
<% if (hasGetMany) { -%>
30-
res.json(rows)
29+
res.json(rows)
3130
<% } else { -%>
32-
if (rows.length === 0) {
33-
res.status(404).end()
34-
return
35-
}
36-
res.json(rows[0])
31+
if (rows.length === 0) {
32+
res.status(404).end()
33+
return
34+
}
35+
res.json(rows[0])
3736
<% } -%>
38-
}
39-
)
40-
})
37+
}
38+
)
39+
})
4140
<%
4241
}
4342
if (method.name === 'post') {
4443
%>
45-
app.post('<%- path %>', (req, res) => {
46-
pool.query(
47-
'<%- sql %>',<%- formattedParams %>
48-
(err, rows, fields) => {
49-
if (err) {
50-
throw err
44+
app.post('<%- path %>', (req, res) => {
45+
pool.query(
46+
'<%- sql %>',<%- formattedParams %>
47+
(err, rows, fields) => {
48+
if (err) {
49+
throw err
50+
}
51+
res.sendStatus(204)
5152
}
52-
res.sendStatus(204)
53-
}
54-
)
55-
})
53+
)
54+
})
5655
<%
5756
}
5857
if (method.name === 'put') {
5958
%>
60-
app.put('<%- path %>', (req, res) => {
61-
pool.query(
62-
'<%- sql %>',<%- formattedParams %>
63-
(err, rows, fields) => {
64-
if (err) {
65-
throw err
59+
app.put('<%- path %>', (req, res) => {
60+
pool.query(
61+
'<%- sql %>',<%- formattedParams %>
62+
(err, rows, fields) => {
63+
if (err) {
64+
throw err
65+
}
66+
res.sendStatus(204)
6667
}
67-
res.sendStatus(204)
68-
}
69-
)
70-
})
68+
)
69+
})
7170
<%
7271
}
7372
if (method.name === 'delete') {
7473
%>
75-
app.delete('<%- path %>', (req, res) => {
76-
pool.query(
77-
'<%- sql %>',<%- formattedParams %>
78-
(err, rows, fields) => {
79-
if (err) {
80-
throw err
74+
app.delete('<%- path %>', (req, res) => {
75+
pool.query(
76+
'<%- sql %>',<%- formattedParams %>
77+
(err, rows, fields) => {
78+
if (err) {
79+
throw err
80+
}
81+
res.sendStatus(204)
8182
}
82-
res.sendStatus(204)
83-
}
84-
)
85-
})
83+
)
84+
})
8685
<%
8786
}
8887
});
8988
});
9089
%>
91-
9290
}
9391

9492
exports.register = register;

0 commit comments

Comments
 (0)