Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: don't send pg output directly to the client #16

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions JavaScript/b-transport/api/country.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const country = db('country');
({
async read(id) {
console.log({ db });
return country.read(id);
const output = await country.read(id);
return output.rows;
},

async find(mask) {
const sql = 'SELECT * from country where name like $1';
return country.query(sql, [mask]);
const output = await country.query(sql, [mask]);
return output.rows;
},
});
15 changes: 10 additions & 5 deletions JavaScript/b-transport/api/user.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
({
async read(id) {
return db('users').read(id, ['id', 'login']);
const output = await db('users').read(id, ['id', 'login']);
return output.rows;
},

async create({ login, password }) {
const passwordHash = await common.hash(password);
return db('users').create({ login, password: passwordHash });
const output = await db('users').create({ login, password: passwordHash });
return output.rows;
},

async update(id, { login, password }) {
const passwordHash = await common.hash(password);
return db('users').update(id, { login, password: passwordHash });
const output = await db('users').update(id, { login, password: passwordHash });
return output.rows;
},

async delete(id) {
return db('users').delete(id);
const output = await db('users').delete(id);
return output.rows;
},

async find(mask) {
const sql = 'SELECT login from users where login like $1';
return db('users').query(sql, [mask]);
const output = await db('users').query(sql, [mask]);
return output.rows;
},
});
2 changes: 1 addition & 1 deletion JavaScript/b-transport/transport/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = (routing, port, console) => {
if (!handler) return res.end('"Not found"');
const { args } = await receiveArgs(req);
console.log(`${socket.remoteAddress} ${method} ${url}`);
const result = await handler(args);
const result = await handler(...args);
res.end(JSON.stringify(result));
}).listen(port);

Expand Down
6 changes: 4 additions & 2 deletions JavaScript/c-commonjs/api/country.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const country = db.crud('country');
module.exports = {
async read(id) {
console.log({ db });
return country.read(id);
const output = await country.read(id);
return output.rows;
},

async find(mask) {
const sql = 'SELECT * from country where name like $1';
return country.query(sql, [mask]);
const output = await country.query(sql, [mask]);
return output.rows;
},
};
15 changes: 10 additions & 5 deletions JavaScript/c-commonjs/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@ const users = db.crud('users');

module.exports = {
async read(id) {
return users.read(id, ['id', 'login']);
const output = await users.read(id, ['id', 'login']);
return output.rows;
},

async create({ login, password }) {
const passwordHash = await common.hash(password);
return users.create({ login, password: passwordHash });
const output = await users.create({ login, password: passwordHash });
return output.rows;
},

async update(id, { login, password }) {
const passwordHash = await common.hash(password);
return users.update(id, { login, password: passwordHash });
const output = await users.update(id, { login, password: passwordHash });
return output.rows;
},

async delete(id) {
return users.delete(id);
const output = await users.delete(id);
return output.rows;
},

async find(mask) {
const sql = 'SELECT login from users where login like $1';
return users.query(sql, [mask]);
const output = await users.query(sql, [mask]);
return output.rows;
},
};
2 changes: 1 addition & 1 deletion JavaScript/c-commonjs/transport/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = (routing, port, console) => {
if (!handler) return res.end('"Not found"');
const { args } = await receiveArgs(req);
console.log(`${socket.remoteAddress} ${method} ${url}`);
const result = await handler(args);
const result = await handler(...args);
res.end(JSON.stringify(result));
}).listen(port);

Expand Down