Skip to content

Commit e77de6f

Browse files
committed
refactor: extract a variable
1 parent c7c1fce commit e77de6f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/templates/routes.js.ejs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ const register = (app, pool) => {
22

33
<%
44
endpoints.forEach(function(endpoint) {
5+
const path = endpoint.path;
56
const hasGetOne = endpoint.hasOwnProperty('get');
67
const hasGetMany = endpoint.hasOwnProperty('get_list');
78
if (hasGetOne || hasGetMany) {
89
const sql = hasGetOne ? endpoint.get : endpoint.get_list;
910
const params = extractParams(sql);
1011
%>
11-
app.get('<%- endpoint.path %>', (req, res) => {
12+
app.get('<%- path %>', (req, res) => {
1213
pool.query(
1314
<%- formatQuery(sql) %>,<%- params.length > 0 ? '\n ' + formatParams(params) + ',' : '' %>
1415
(err, rows, fields) => {
@@ -32,7 +33,7 @@ app.get('<%- endpoint.path %>', (req, res) => {
3233
if (endpoint.hasOwnProperty('post')) {
3334
const params = extractParams(endpoint.post);
3435
%>
35-
app.post('<%- endpoint.path %>', (req, res) => {
36+
app.post('<%- path %>', (req, res) => {
3637
pool.query(
3738
<%- formatQuery(endpoint.post) %>,<%- params.length > 0 ? '\n ' + formatParams(params) + ',' : '' %>
3839
(err, rows, fields) => {
@@ -48,7 +49,7 @@ app.post('<%- endpoint.path %>', (req, res) => {
4849
if (endpoint.hasOwnProperty('put')) {
4950
const params = extractParams(endpoint.put);
5051
%>
51-
app.put('<%- endpoint.path %>', (req, res) => {
52+
app.put('<%- path %>', (req, res) => {
5253
pool.query(
5354
<%- formatQuery(endpoint.put) %>,<%- params.length > 0 ? '\n ' + formatParams(params) + ',' : '' %>
5455
(err, rows, fields) => {
@@ -64,7 +65,7 @@ app.put('<%- endpoint.path %>', (req, res) => {
6465
if (endpoint.hasOwnProperty('delete')) {
6566
const params = extractParams(endpoint.delete);
6667
%>
67-
app.delete('<%- endpoint.path %>', (req, res) => {
68+
app.delete('<%- path %>', (req, res) => {
6869
pool.query(
6970
<%- formatQuery(endpoint.delete) %>,<%- params.length > 0 ? '\n ' + formatParams(params) + ',' : '' %>
7071
(err, rows, fields) => {

0 commit comments

Comments
 (0)