Skip to content

Commit

Permalink
refactor: Use logical OR operator when checking callback parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dunak-debug committed Sep 20, 2021
1 parent 466f230 commit 51ac8d1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ const safeCallback = (callback, result, resource, query) => {

global.exports('execute', (query, parameters, cb, resource = GetInvokingResource()) => {
execute(query, parameters, resource).then((result) =>
safeCallback(typeof parameters === 'function' ? parameters : cb, result, resource, query));
safeCallback(cb || parameters, result, resource, query));
});

global.exports('insert', (query, parameters, cb, resource = GetInvokingResource()) => {
execute(query, parameters, resource).then((result) =>
safeCallback(typeof parameters === 'function' ? parameters : cb, result && result.insertId, resource, query));
safeCallback(cb || parameters, result && result.insertId, resource, query));
});

global.exports('update', (query, parameters, cb, resource = GetInvokingResource()) => {
execute(query, parameters, resource).then((result) =>
safeCallback(typeof parameters === 'function' ? parameters : cb, result && result.affectedRows, resource, query));
safeCallback(cb || parameters, result && result.affectedRows, resource, query));
});

global.exports('fetch', (query, parameters, cb, resource = GetInvokingResource()) => {
execute(query, parameters, resource).then((result) =>
safeCallback(typeof parameters === 'function' ? parameters : cb, result, resource, query));
safeCallback(cb || parameters, result, resource, query));
});

global.exports('single', (query, parameters, cb, resource = GetInvokingResource()) => {
execute(query, parameters, resource).then((result) =>
safeCallback(typeof parameters === 'function' ? parameters : cb, result && result[0], resource, query));
safeCallback(cb || parameters, result && result[0], resource, query));
});

global.exports('scalar', (query, parameters, cb, resource = GetInvokingResource()) => {
execute(query, parameters, resource).then((result) =>
safeCallback(typeof parameters === 'function' ? parameters : cb, result && result[0] && Object.values(result[0])[0], resource, query));
safeCallback(cb || parameters, result && result[0] && Object.values(result[0])[0], resource, query));
});

if (!GetResourceMetadata(GetCurrentResourceName(), 'server_script', 1)) {
Expand Down

0 comments on commit 51ac8d1

Please sign in to comment.