Initial refactor (routes and utils to respective folders)

This commit is contained in:
Joe-Dowd
2020-03-19 23:20:33 +00:00
parent f6826b60b0
commit 5c3d18b0e2
18 changed files with 1094 additions and 982 deletions

36
src/routes/getUsername.js Normal file
View File

@@ -0,0 +1,36 @@
var db = require('../databases/databases.js').db;
var getHash = require('../utils/getHash.js');
module.exports = function getUsername (req, res) {
let userID = req.query.userID;
if (userID == undefined) {
//invalid request
res.sendStatus(400);
return;
}
//hash the userID
userID = getHash(userID);
try {
let row = db.prepare("SELECT userName FROM userNames WHERE userID = ?").get(userID);
if (row !== undefined) {
res.send({
userName: row.userName
});
} else {
//no username yet, just send back the userID
res.send({
userName: userID
});
}
} catch (err) {
console.log(err);
res.sendStatus(500);
return;
}
}