Skip to content

Commit

Permalink
extra db security
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunpat committed Sep 1, 2018
1 parent eb4a0df commit 1331c5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/api/BellData.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ class BellData {

}

async createNewError(device_id, error, user) {
async createNewError(device_id, error) {

await this.query(
'INSERT INTO errors (device_id, error, user) VALUES (?, ?, ?)',
[device_id, error, user]
'INSERT INTO errors (device_id, error) VALUES (?, ?)',
[device_id, error]
);

}
Expand Down
14 changes: 6 additions & 8 deletions lib/api/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,18 @@ module.exports = async (path, postData) => {
if (typeof values.period === 'string' || (values.pathname === '/' && typeof values.period !== 'number'))
return responses.bad_data;

await bellData.createNewHit(values);
if (await bellData.getDeviceByDeviceId(device_id)) {
await bellData.createNewHit(values);
return responses.success;
}

return responses.success;
return responses.bad_data;
case '/write/error':

if (!device_id || typeof data.error !== 'string')
return responses.bad_data;

let user = await bellData.getUserByDeviceId(device_id);

if (user.error)
await bellData.createNewError(device_id, data.error, null);
else
await bellData.createNewError(device_id, data.error, user.email);
await bellData.createNewError(device_id, data.error);

return responses.success;
case '/update/preferences':
Expand Down

0 comments on commit 1331c5b

Please sign in to comment.