Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue#152 data folder es6 migration #167

Merged
merged 3 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/data/benefits-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ function BenefitsDAO(db) {
return new BenefitsDAO(db);
}

var usersCol = db.collection("users");
const usersCol = db.collection("users");

this.getAllNonAdminUsers = function(callback) {
this.getAllNonAdminUsers = (callback) => {
usersCol.find({
"isAdmin": {
$ne: true
}
}).toArray(function(err, users) {
}).toArray((err, users) => {
callback(null, users);
});
};

this.updateBenefits = function(userId, startDate, callback) {
this.updateBenefits = (userId, startDate, callback) => {
usersCol.update({
_id: parseInt(userId)
}, {
$set: {
benefitStartDate: startDate
}
},
function(err, result) {
(err, result) => {
if (!err) {
console.log("Updated benefits");
return callback(null, result);
Expand Down
22 changes: 11 additions & 11 deletions app/data/contributions-dao.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var UserDAO = require("./user-dao").UserDAO;
const UserDAO = require("./user-dao").UserDAO;

/* The ContributionsDAO must be constructed with a connected database object */
function ContributionsDAO(db) {
Expand All @@ -11,14 +11,14 @@ function ContributionsDAO(db) {
return new ContributionsDAO(db);
}

var contributionsDB = db.collection("contributions");
var userDAO = new UserDAO(db);
const contributionsDB = db.collection("contributions");
const userDAO = new UserDAO(db);

this.update = function(userId, preTax, afterTax, roth, callback) {
var parsedUserId = parseInt(userId);
this.update = (userId, preTax, afterTax, roth, callback) => {
const parsedUserId = parseInt(userId);

// Create contributions document
var contributions = {
const contributions = {
UlisesGascon marked this conversation as resolved.
Show resolved Hide resolved
userId: parsedUserId,
preTax: preTax,
afterTax: afterTax,
Expand All @@ -31,11 +31,11 @@ function ContributionsDAO(db) {
contributions, {
upsert: true
},
function(err, result) {
(err, result) => {
if (!err) {
console.log("Updated contributions");
// add user details
userDAO.getUserById(parsedUserId, function(err, user) {
userDAO.getUserById(parsedUserId, (err, user) => {

if (err) return callback(err, null);

Expand All @@ -53,11 +53,11 @@ function ContributionsDAO(db) {
);
};

this.getByUserId = function(userId, callback) {
this.getByUserId = (userId, callback) => {
contributionsDB.findOne({
userId: userId
},
function(err, contributions) {
(err, contributions) => {
if (err) return callback(err, null);

// Set defualt contributions if not set
Expand All @@ -68,7 +68,7 @@ function ContributionsDAO(db) {
};

// add user details
userDAO.getUserById(userId, function(err, user) {
userDAO.getUserById(userId, (err, user) => {

if (err) return callback(err, null);

Expand Down
12 changes: 6 additions & 6 deletions app/data/memos-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ function MemosDAO(db) {
return new MemosDAO(db);
}

var memosCol = db.collection("memos");
const memosCol = db.collection("memos");

this.insert = function(memo, callback) {
this.insert = (memo, callback) => {

// Create allocations document
var memos = {
const memos = {
memo: memo,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use shorter assignation here too ^^

timestamp: new Date()
};

memosCol.insert(memos, function(err, result) {
memosCol.insert(memos, (err, result) => {

if (!err) {
return callback(null, result);
Expand All @@ -30,11 +30,11 @@ function MemosDAO(db) {
});
};

this.getAllMemos = function(callback) {
this.getAllMemos = (callback) => {

memosCol.find({}).sort({
timestamp: -1
}).toArray(function(err, memos) {
}).toArray((err, memos) => {
if (err) return callback(err, null);
if (!memos) return callback("ERROR: No memos found", null);

Expand Down
12 changes: 6 additions & 6 deletions app/data/profile-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function ProfileDAO(db) {
return new ProfileDAO(db);
}

var users = db.collection("users");
const users = db.collection("users");

/* Fix for A6 - Sensitive Data Exposure

Expand Down Expand Up @@ -39,10 +39,10 @@ function ProfileDAO(db) {
};
*/

this.updateUser = function(userId, firstName, lastName, ssn, dob, address, bankAcc, bankRouting, callback) {
this.updateUser = (userId, firstName, lastName, ssn, dob, address, bankAcc, bankRouting, callback) => {

// Create user document
var user = {};
const user = {};
if (firstName) {
user.firstName = firstName;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ function ProfileDAO(db) {
}, {
$set: user
},
function(err, result) {
(err, result) => {
if (!err) {
console.log("Updated user profile");
return callback(null, user);
Expand All @@ -91,11 +91,11 @@ function ProfileDAO(db) {
);
};

this.getByUserId = function(userId, callback) {
this.getByUserId = (userId, callback) => {
users.findOne({
_id: parseInt(userId)
},
function(err, user) {
(err, user) => {
if (err) return callback(err, null);
/*
// Fix for A6 - Sensitive Data Exposure
Expand Down
6 changes: 4 additions & 2 deletions app/data/research-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ function ResearchDAO(db) {
return new ResearchDAO(db);
}

this.getBySymbol= function(symbol, callback) {
this.getBySymbol= (symbol, callback) =>{

function searchCriteria() {
const searchCriteria = () => {

if (symbol) {
console.log("in if symbol");
Expand All @@ -21,6 +21,8 @@ function ResearchDAO(db) {
};
}
}

return searchCriteria;
}
}

Expand Down
40 changes: 20 additions & 20 deletions app/data/user-dao.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var bcrypt = require("bcrypt-nodejs");
const bcrypt = require("bcrypt-nodejs");

/* The UserDAO must be constructed with a connected database object */
function UserDAO(db) {
Expand All @@ -12,12 +12,12 @@ function UserDAO(db) {
return new UserDAO(db);
}

var usersCol = db.collection("users");
const usersCol = db.collection("users");

this.addUser = function(userName, firstName, lastName, password, email, callback) {
this.addUser = (userName, firstName, lastName, password, email, callback) => {

// Create user document
var user = {
const user = {
userName: userName,
firstName: firstName,
lastName: lastName,
Expand All @@ -35,15 +35,15 @@ function UserDAO(db) {
user.email = email;
}

this.getNextSequence("userId", function(err, id) {
this.getNextSequence("userId", (err, id) => {
if (err) {
return callback(err, null);
}
console.log(typeof(id));

user._id = id;

usersCol.insert(user, function(err, result) {
usersCol.insert(user, (err, result) => {

if (!err) {
return callback(null, result.ops[0]);
Expand All @@ -54,18 +54,18 @@ function UserDAO(db) {
});
};

this.getRandomFutureDate = function() {
var today = new Date();
var day = (Math.floor(Math.random() * 10) + today.getDay()) % 29;
var month = (Math.floor(Math.random() * 10) + today.getMonth()) % 12;
var year = Math.ceil(Math.random() * 30) + today.getFullYear();
this.getRandomFutureDate = () => {
const today = new Date();
const day = (Math.floor(Math.random() * 10) + today.getDay()) % 29;
const month = (Math.floor(Math.random() * 10) + today.getMonth()) % 12;
const year = Math.ceil(Math.random() * 30) + today.getFullYear();
return year + "-" + ("0" + month).slice(-2) + "-" + ("0" + day).slice(-2);
};

this.validateLogin = function(userName, password, callback) {
this.validateLogin = (userName, password, callback) => {

// Helper function to compare passwords
function comparePassword(fromDB, fromUser) {
const comparePassword = (fromDB, fromUser) => {
return fromDB === fromUser;
/*
// Fix for A2-Broken Auth
Expand All @@ -75,21 +75,21 @@ function UserDAO(db) {
}

// Callback to pass to MongoDB that validates a user document
function validateUserDoc(err, user) {
const validateUserDoc = (err, user) => {

if (err) return callback(err, null);

if (user) {
if (comparePassword(password, user.password)) {
callback(null, user);
} else {
var invalidPasswordError = new Error("Invalid password");
const invalidPasswordError = new Error("Invalid password");
// Set an extra field so we can distinguish this from a db error
invalidPasswordError.invalidPassword = true;
callback(invalidPasswordError, null);
}
} else {
var noSuchUserError = new Error("User: " + user + " does not exist");
const noSuchUserError = new Error("User: " + user + " does not exist");
// Set an extra field so we can distinguish this from a db error
noSuchUserError.noSuchUser = true;
callback(noSuchUserError, null);
Expand All @@ -102,19 +102,19 @@ function UserDAO(db) {
};

// This is the good one, see the next function
this.getUserById = function(userId, callback) {
this.getUserById = (userId, callback) => {
usersCol.findOne({
_id: parseInt(userId)
}, callback);
};

this.getUserByUserName = function(userName, callback) {
this.getUserByUserName = (userName, callback) => {
usersCol.findOne({
userName: userName
}, callback);
};

this.getNextSequence = function(name, callback) {
this.getNextSequence = (name, callback) => {
db.collection("counters").findAndModify({
_id: name
}, [], {
Expand All @@ -124,7 +124,7 @@ function UserDAO(db) {
}, {
new: true
},
function(err, data) {
(err, data) => {
if (err) {
return callback(err, null);
}
Expand Down
2 changes: 1 addition & 1 deletion config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
// grunt db-reset:development
// That will create the local nodegoat data-store, or restore it to a clean state if it already exists.

// db: "mongodb://localhost:27017/nodegoat",
db: "mongodb://localhost:27017/nodegoat",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should remind commented ;-)


// If you want to use a MongoLab instance, just sign up for it, create a data-store, in this example we call it nodegoat.
// and again just run the grunt db-reset:development command
Expand Down