Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.post('/updateLabel', function(req, res) {
console.log("Body: " + req.body);
console.log("\tNew Label ID: " + req.body.newLabelId);
console.log("\tElement Label ID: " + req.body.elementLabelId);
// For now, we don't need the user id...
// console.log("\tUser ID: " + req.session.user.userId);
// var userId = req.session.user.userId;
var elementLabelId = req.body.elementLabelId;
var decision = req.body.newLabelId;
db.get('UPDATE elementLabels SET labelId = :decision WHERE elementLabelId = :elementLabelId',
[decision, elementLabelId])
.then(function() {
console.log("Update logged...");
res.end();
});
})
.then(function(pairs) {
if ( pairs.length > 0 ) {
var pairList = pairs.map(function(x) {
return x["pairId"]
});
console.log("Found candidiate pairs!");
// console.log(pairList);
var targetPair = getRandomElement(pairList);
console.log("Target Pair: " + targetPair);
return Promise.all([
targetPair,
db.get('SELECT el.elementId, el.elementText FROM \
elements el JOIN pairs pr ON pr.leftElement = el.elementId \
WHERE pr.pairId = ?', targetPair),
db.get('SELECT el.elementId, el.elementText FROM \
elements el JOIN pairs pr ON pr.rightElement = el.elementId \
WHERE pr.pairId = ?', targetPair)
]);
} else {
console.log("No pairs. Done!");
return Promise.resolve({ empty : true });
}
})
.then(function(tweets) {
var pairList = pairs.map(function(x) {
return x["pairId"]
});
console.log("Found candidiate pairs!");
// console.log(pairList);
var targetPair = getRandomElement(pairList);
console.log("Target Pair: " + targetPair);
return Promise.all([
targetPair,
db.get('SELECT el.elementId, el.elementText FROM \
elements el JOIN pairs pr ON pr.leftElement = el.elementId \
WHERE pr.pairId = ?', targetPair),
db.get('SELECT el.elementId, el.elementText FROM \
elements el JOIN pairs pr ON pr.rightElement = el.elementId \
WHERE pr.pairId = ?', targetPair)
]);
} else {
console.log("No pairs. Done!");
return Promise.resolve({ empty : true });
}
})
.then(function(tweets) {
app.get('/labelerView/:id', function (req, res) {
// Store the task ID in the session
var requestedTask = req.params.id
req.session.taskId = requestedTask
var currentUser = req.session.user
console.log("Current User Session: " + currentUser.screenname)
db.get('SELECT taskName, question FROM tasks WHERE taskId = ?', requestedTask)
.then(function(taskData) {
taskMap = {
taskId: requestedTask,
taskName: taskData.taskName,
question: taskData.question,
}
return Promise.all([
taskMap,
db.all('SELECT labelId, labelText FROM labels WHERE taskId = ?', requestedTask)
]);
})
.then(function(labelData) {
var taskData = labelData[0];
var labelList = labelData[1];
app.post('/item', function(req, res) {
console.log("Body: " + req.body);
console.log("\telement: " + req.body.element);
console.log("\tselected: " + req.body.selected);
console.log("\tUser ID: " + req.session.user.userId);
var elementId = req.body.element;
var userId = req.session.user.userId;
var decision = req.body.selected;
db.get('INSERT INTO elementLabels (elementId, userId, labelId) \
VALUES (:elementId, :userId, :decision)', [elementId, userId, decision])
.then(function() {
console.log("Decision logged...");
res.end();
});
})
app.post('/pair', function(req, res) {
console.log("Body: " + req.body);
console.log("\tpair: " + req.body.pair);
console.log("\tselected: " + req.body.selected);
console.log("\tUser ID: " + req.session.user.userId);
var pairId = req.body.pair;
var userId = req.session.user.userId;
var decision = req.body.selected;
db.get('INSERT INTO comparisons (pairId, userId, decision) \
VALUES (:pairId, :userId, :dec)', [pairId, userId, decision])
.then(function() {
console.log("Decision logged...");
res.end();
});
})
app.get('/taskStats/:taskId', function(req, res) {
var taskId = req.params.taskId
db.get("SELECT taskName, question, taskType FROM tasks WHERE taskId = ?", taskId)
.then(function(taskData) {
var taskDetails = {
taskInfo: taskData
};
if ( taskData.taskType == 1 ) {
var compDetails = db.all("SELECT c.decision, \
e1.elementId AS lId, e1.elementText AS lText, e1.externalId AS lExt, \
e2.elementId AS rId, e2.elementText AS rText, e2.externalId AS rExt \
FROM pairs p \
JOIN elements AS e1 ON e1.elementId = p.leftElement \
JOIN elements AS e2 ON e2.elementId = p.rightElement \
JOIN comparisons c ON p.pairId = c.pairId \
WHERE p.taskId = ?", taskId);