Skip to content

Commit 4ba1011

Browse files
committed
Fix: don't send pg output directly to the client
Signed-off-by: Vladyslav Karpenko <[email protected]>
1 parent f18dc36 commit 4ba1011

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

JavaScript/b-transport/api/country.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ const country = db('country');
33
({
44
async read(id) {
55
console.log({ db });
6-
return country.read(id);
6+
const output = await country.read(id);
7+
return output.rows;
78
},
89

910
async find(mask) {
1011
const sql = 'SELECT * from country where name like $1';
11-
return country.query(sql, [mask]);
12+
const output = await country.query(sql, [mask]);
13+
return output.rows;
1214
},
1315
});

JavaScript/b-transport/api/user.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
({
22
async read(id) {
3-
return db('users').read(id, ['id', 'login']);
3+
const output = await db('users').read(id, ['id', 'login']);
4+
return output.rows;
45
},
56

67
async create({ login, password }) {
78
const passwordHash = await common.hash(password);
8-
return db('users').create({ login, password: passwordHash });
9+
const output = await db('users').create({ login, password: passwordHash });
10+
return output.rows;
911
},
1012

1113
async update(id, { login, password }) {
1214
const passwordHash = await common.hash(password);
13-
return db('users').update(id, { login, password: passwordHash });
15+
const output = await db('users').update(id, { login, password: passwordHash });
16+
return output.rows;
1417
},
1518

1619
async delete(id) {
17-
return db('users').delete(id);
20+
const output = await db('users').delete(id);
21+
return output.rows;
1822
},
1923

2024
async find(mask) {
2125
const sql = 'SELECT login from users where login like $1';
22-
return db('users').query(sql, [mask]);
26+
const output = await db('users').query(sql, [mask]);
27+
return output.rows;
2328
},
2429
});

JavaScript/b-transport/transport/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = (routing, port, console) => {
3232
if (!handler) return res.end('"Not found"');
3333
const { args } = await receiveArgs(req);
3434
console.log(`${socket.remoteAddress} ${method} ${url}`);
35-
const result = await handler(args);
35+
const result = await handler(...args);
3636
res.end(JSON.stringify(result));
3737
}).listen(port);
3838

JavaScript/c-commonjs/api/country.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ const country = db.crud('country');
66
module.exports = {
77
async read(id) {
88
console.log({ db });
9-
return country.read(id);
9+
const output = await country.read(id);
10+
return output.rows;
1011
},
1112

1213
async find(mask) {
1314
const sql = 'SELECT * from country where name like $1';
14-
return country.query(sql, [mask]);
15+
const output = await country.query(sql, [mask]);
16+
return output.rows;
1517
},
1618
};

JavaScript/c-commonjs/api/user.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,30 @@ const users = db.crud('users');
66

77
module.exports = {
88
async read(id) {
9-
return users.read(id, ['id', 'login']);
9+
const output = await users.read(id, ['id', 'login']);
10+
return output.rows;
1011
},
1112

1213
async create({ login, password }) {
1314
const passwordHash = await common.hash(password);
14-
return users.create({ login, password: passwordHash });
15+
const output = await users.create({ login, password: passwordHash });
16+
return output.rows;
1517
},
1618

1719
async update(id, { login, password }) {
1820
const passwordHash = await common.hash(password);
19-
return users.update(id, { login, password: passwordHash });
21+
const output = await users.update(id, { login, password: passwordHash });
22+
return output.rows;
2023
},
2124

2225
async delete(id) {
23-
return users.delete(id);
26+
const output = await users.delete(id);
27+
return output.rows;
2428
},
2529

2630
async find(mask) {
2731
const sql = 'SELECT login from users where login like $1';
28-
return users.query(sql, [mask]);
32+
const output = await users.query(sql, [mask]);
33+
return output.rows;
2934
},
3035
};

JavaScript/c-commonjs/transport/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = (routing, port, console) => {
3232
if (!handler) return res.end('"Not found"');
3333
const { args } = await receiveArgs(req);
3434
console.log(`${socket.remoteAddress} ${method} ${url}`);
35-
const result = await handler(args);
35+
const result = await handler(...args);
3636
res.end(JSON.stringify(result));
3737
}).listen(port);
3838

0 commit comments

Comments
 (0)