Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log("OLD ARR");
// console.log(JSONval);
var JSONarr = JSON.parse(results[i].JSON); // Turn the JSON String into an Array
console.log(JSONarr);
JSONarr.wallid = dest; // change the array to include the new destination
console.log("NEW ARR");
console.log(JSONarr);
JSONval = JSON.stringify(JSONarr); // turn the JSON array back into a string
// insert the note into the database witha new wallID
client.query("INSERT INTO `note` VALUES(?,?)", [newGuid, JSONval], callback);
};
//create wall
var wallStr = JSON.stringify({notes: noteGuids, createdAt: new Date().getTime()});
console.log(noteGuids);
client.query("INSERT INTO `wall` VALUES(?,?)", [dest, wallStr], callback);
// return with the dest
callback();
}
], callback);
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
var newGuid = guidGenerator(); // get a new GUID
noteGuids.push(newGuid); // write the note GUID to an array
var JSONval = results[i].JSON; // JSON contains the WALLID as a STRING
console.log("OLD ARR");
// console.log(JSONval);
var JSONarr = JSON.parse(results[i].JSON); // Turn the JSON String into an Array
console.log(JSONarr);
JSONarr.wallid = dest; // change the array to include the new destination
console.log("NEW ARR");
console.log(JSONarr);
JSONval = JSON.stringify(JSONarr); // turn the JSON array back into a string
// insert the note into the database witha new wallID
client.query("INSERT INTO `note` VALUES(?,?)", [newGuid, JSONval], callback);
};
//create wall
var wallStr = JSON.stringify({notes: noteGuids, createdAt: new Date().getTime()});
console.log(noteGuids);
client.query("INSERT INTO `wall` VALUES(?,?)", [dest, wallStr], callback);
// return with the dest
callback();
}
], callback);
function (callback)
{
// Get the data from MySQL
client.query("SELECT * FROM `primarywall`.`wall` WHERE `wallID` = ?", [wallid], callback)
},
exports.createUser = function (userId, password, fullname, callback)
{
var salt = bcrypt.gen_salt_sync(10);
var hash = bcrypt.encrypt_sync(password, salt);
var userJSON = JSON.stringify({password: hash, fullname: fullname, dateRegistered:new Date().getTime()});
client.query("INSERT INTO `primarywall`.`user` VALUES(?,?)", [userId, userJSON], function (err, results, fields)
{
var success=err == null;
if(err)
{
//mysql problem
console.error("MYSQL_ERROR: " + JSON.stringify(err));
}
if(callback) callback(success);
});
}
exports.createDomain = function (domain, owner, callback)
{
var domainJSON=JSON.stringify({owner:[owner]});
client.query("INSERT INTO`primarywall`.`domain` VALUES (?,?)", [domain, domainJSON], function (err, results, fields)
{
var success=err == null;
if(err)
{
//mysql problem
console.error("MYSQL_ERROR: " + JSON.stringify(err));
}
if(callback) callback(success);
});
}
exports.checkIfDomainExists = function (domain, callback)
{
client.query("SELECT * FROM `primarywall`.`domain` WHERE `domainID` = ?", [domain], function (err, results, fields)
{
var success=err == null;
if(err)
{
//mysql problem
console.error("MYSQL_ERROR: " + JSON.stringify(err));
}
callback(success, results.length==1);
});
}
exports.getUserSession = function (sessionID, callback)
{
client.query("SELECT JSON FROM `primarywall`.`session` WHERE sessionID = ?", [sessionID], function (err, results, fields)
{
var success=err == null;
var sessionObject = null;
if (success && results.length == 1)
{
sessionObject = JSON.parse(results[0].JSON);
}
else if(err)
{
//mysql problem
console.error("MYSQL_ERROR: " + JSON.stringify(err));
}
callback(success, sessionObject);
function(callback)
{
client.query("SELECT * FROM `primarywall`.`user` WHERE `UserID` = ?", [userId], function (err, results, fields)
{
if(err)
{
callback(err);
return;
}
userObj = JSON.parse(results[0].JSON);
callback(null);
});
},
function(callback)
else
{
var sql = "SELECT JSON FROM `primarywall`.`note` WHERE ";
for(var i=0;i
function(callback){
client.query("SELECT * FROM `wall` WHERE `wallID` = ?", [source], callback);
},
//if it exists load it into, else create a empty table entry