From 17b0bd6806e16800548c7509665bdf6feddb43cd Mon Sep 17 00:00:00 2001 From: Alex Buglak Date: Wed, 6 Dec 2023 19:22:42 +0100 Subject: [PATCH] c-common api an ws fixes --- JavaScript/c-commonjs/api/user.js | 10 +++++----- JavaScript/c-commonjs/static/client.js | 2 +- JavaScript/c-commonjs/transport/ws.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/JavaScript/c-commonjs/api/user.js b/JavaScript/c-commonjs/api/user.js index b2e65b7..57843c4 100644 --- a/JavaScript/c-commonjs/api/user.js +++ b/JavaScript/c-commonjs/api/user.js @@ -6,25 +6,25 @@ const users = db.crud('users'); module.exports = { async read(id) { - return users.read(id, ['id', 'login']); + return await users.read(id, ['id', 'login']); }, async create({ login, password }) { const passwordHash = await common.hash(password); - return users.create({ login, password: passwordHash }); + return await users.create({ login, password: passwordHash }); }, async update(id, { login, password }) { const passwordHash = await common.hash(password); - return users.update(id, { login, password: passwordHash }); + return await users.update(id, { login, password: passwordHash }); }, async delete(id) { - return users.delete(id); + return await users.delete(id); }, async find(mask) { const sql = 'SELECT login from users where login like $1'; - return users.query(sql, [mask]); + return await users.query(sql, [mask]); }, }; diff --git a/JavaScript/c-commonjs/static/client.js b/JavaScript/c-commonjs/static/client.js index 1ad6f5d..ebe8c66 100644 --- a/JavaScript/c-commonjs/static/client.js +++ b/JavaScript/c-commonjs/static/client.js @@ -73,5 +73,5 @@ const scaffold = (url) => { } }); const data = await api.user.read(); - console.log({ data }); + console.dir({ data }); })(); diff --git a/JavaScript/c-commonjs/transport/ws.js b/JavaScript/c-commonjs/transport/ws.js index 0462317..c9665d6 100644 --- a/JavaScript/c-commonjs/transport/ws.js +++ b/JavaScript/c-commonjs/transport/ws.js @@ -26,7 +26,7 @@ module.exports = (routing, port, console) => { try { const result = await handler(...args); connection.send( - JSON.stringify(result.rows ? result.rows : result), { binary: false } + JSON.stringify(result), { binary: false } ); } catch (err) { console.error(err);