Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var ibmdb = require('ibm_db');
ibmdb.open("DATABASE=SAMPLE;HOSTNAME=localhost;UID=db2inst1;PWD=db2inst1-pwd;PORT=50000;PROTOCOL=TCPIP", function (err,conn) {
if (err) return console.log(err);
conn.query('select * from DB2INST1.VSTAFAC2', function (err, data) {
if (err) console.log(err);
else console.log(data);
conn.close(function () {
console.log('done');
});
});
});
router.post('/createUser', function (req, res, next) {
ibmdb.open(_this.connectionString, function (err, conn) {
conn.prepare("insert into SAMPLE.UserData (LastName, FirstName, Location, Email, Password, Age) VALUES (?, ?, ?, ?, ?, ?)", function (err, stmt) {
if (err) {
console.log(err);
return conn.closeSync();
}
console.log(req.body.lastName);
stmt.execute([req.body.lastName, req.body.firstName, req.body.location, req.body.email, passwordhash.generate(req.body.password), req.body.age], function (err, result) {
if (err)
console.log(err);
else {
res.json({
message: "sucessful"
});
result.closeSync();
}
conn.close(function (err) { });
router.get('/listFlightsByID/:id', (req, res, next) => {
ibmdb.open(this.connectionString, function (err, conn) {
conn.prepare('SELECT * FROM SAMPLE.FlightsData WHERE ID=?', function (err, stmt) {
if (err) {
console.log('errorr', err);
}
stmt.execute([req.params.id], function (err, result) {
result.fetch(function (err, data) {
if (err) {
console.error(err);
res.status(401).json({ message: "Server error" });
result.closeSync();
}
else {
if (data) {
res.json({
data,
message: true
router.post('/book', this.ensureToken, (req, res, next) => {
ibmdb.open(this.connectionString, function (err, conn) {
conn.prepare("insert into SAMPLE.Booking (TS, Checkin, UserID, FlightID) VALUES (CURRENT TIMESTAMP, '0', ?, ?)", function (err, stmt) {
if (err) {
console.log(err);
return conn.closeSync();
}
console.log(req.body.lastName);
stmt.execute([req.body.UserID, req.body.FlightID], function (err, result) {
if (err)
console.log(err);
else {
res.json({
message: "sucessful"
});
result.closeSync();
}
conn.close(function (err) { });
router.get('/checkin/:bookid/:userid', this.ensureToken, (req, res, next) => {
ibmdb.open(this.connectionString, function (err, conn) {
conn.prepare("UPDATE SAMPLE.Booking SET Checkin = '1' WHERE FlightID = ? AND UserID=? "
, function (err, stmt) {
if (err) {
console.log('errorr', err);
res.json({
message: true
});
}
stmt.execute([req.params.bookid, req.params.userid], function (err, result) {
console.log(req.params.bookid, req.params.userid)
if (err) {
console.log('error', err)
res.json({
message: true
});
}
router.get('/checkin/:bookid/:userid', this.ensureToken, (req, res, next) => {
ibmdb.open(this.connectionString, function (err, conn) {
conn.prepare("UPDATE SAMPLE.Booking SET Checkin = '1' WHERE FlightID = ? AND UserID=? ", function (err, stmt) {
if (err) {
console.log('errorr', err);
res.json({
message: true
});
}
stmt.execute([req.params.bookid, req.params.userid], function (err, result) {
console.log(req.params.bookid, req.params.userid);
if (err) {
console.log('error', err);
res.json({
message: true
});
}
else {
router.post('/login', (req, res, next) => {
ibmdb.open(this.connectionString, function (err, conn) {
conn.prepare('SELECT * FROM SAMPLE.UserData WHERE Email=?', function (err, stmt) {
if (err) {
console.log(err);
}
stmt.execute([req.body.email], function (err, result) {
result.fetch(function (err, data) {
if (err) {
console.error(err);
res.status(401).json({ message: "Server error" });
result.closeSync();
}
else {
console.log(JSON.stringify(data));
if (!data) {
res.status(401).json({ message: "Please signup, no email exists" });
}
router.post('/createUser', (req, res, next) => {
this.firstName = req.body.firstName;
this.lastName = req.body.lastName;
this.age = req.body.age;
this.email = req.body.email;
this.password = req.body.password;
this.location = req.body.location;
this.password = passwordhash.generate(this.password);
ibmdb.open(this.connectionString, function (err, conn) {
conn.prepare("insert into UsersTable (LastName, FirstName, Location, Email, Password, Age) VALUES (?, ?, ?, ?, ?, ?)", function (err, stmt) {
if (err) {
//could not prepare for some reason
console.log(err);
return conn.closeSync();
}
//Bind and Execute the statment asynchronously
stmt.execute([this.lastName, this.firstName, this.location, this.email, this.password, this.age], function (err, result) {
if (err) console.log(err);
else{
res.json({
message: "sucessful"
});
result.closeSync();
}
//Close the connection
router.post("/createUser", (req, res, next) => {
ibmdb.open(this.connectionString, function(err, conn) {
conn.prepare(
"insert into SAMPLE.UserData (LastName, FirstName, Location, Email, Password, Age, Tier) VALUES (?, ?, ?, ?, ?, ?, ?)",
function(err, stmt) {
if (err) {
console.log(err);
return conn.closeSync();
}
stmt.execute(
[
req.body.lastName,
req.body.firstName,
req.body.location,
req.body.email,
passwordhash.generate(req.body.password),
req.body.age,
req.body.tier
client = new Promise(function(resolve, reject) {
ibmdb.open(connectionString, function(err, conn) {
if (err) reject(err);
else resolve(conn);
});
});