1- var UserDAO = require ( "./user-dao" ) . UserDAO ;
1+ const UserDAO = require ( "./user-dao" ) . UserDAO ;
22
33/* The AllocationsDAO must be constructed with a connected database object */
4- function AllocationsDAO ( db ) {
4+ const AllocationsDAO = function ( db ) {
55
66 "use strict" ;
77
@@ -12,15 +12,14 @@ function AllocationsDAO(db) {
1212 return new AllocationsDAO ( db ) ;
1313 }
1414
15- var allocationsCol = db . collection ( "allocations" ) ;
16- var userDAO = new UserDAO ( db ) ;
15+ const allocationsCol = db . collection ( "allocations" ) ;
16+ const userDAO = new UserDAO ( db ) ;
1717
18-
19- this . update = function ( userId , stocks , funds , bonds , callback ) {
20- var parsedUserId = parseInt ( userId ) ;
18+ this . update = ( userId , stocks , funds , bonds , callback ) => {
19+ const parsedUserId = parseInt ( userId ) ;
2120
2221 // Create allocations document
23- var allocations = {
22+ const allocations = {
2423 userId : userId ,
2524 stocks : stocks ,
2625 funds : funds ,
@@ -31,13 +30,13 @@ function AllocationsDAO(db) {
3130 userId : parsedUserId
3231 } , allocations , {
3332 upsert : true
34- } , function ( err , result ) {
33+ } , ( err , result ) => {
3534
3635 if ( ! err ) {
3736
3837 console . log ( "Updated allocations" ) ;
3938
40- userDAO . getUserById ( userId , function ( err , user ) {
39+ userDAO . getUserById ( userId , ( err , user ) => {
4140
4241 if ( err ) return callback ( err , null ) ;
4342
@@ -55,10 +54,10 @@ function AllocationsDAO(db) {
5554 } ) ;
5655 } ;
5756
58- this . getByUserIdAndThreshold = function ( userId , threshold , callback ) {
59- var parsedUserId = parseInt ( userId ) ;
57+ this . getByUserIdAndThreshold = ( userId , threshold , callback ) => {
58+ const parsedUserId = parseInt ( userId ) ;
6059
61- function searchCriteria ( ) {
60+ const searchCriteria = ( ) => {
6261
6362 if ( threshold ) {
6463 /*
@@ -84,15 +83,15 @@ function AllocationsDAO(db) {
8483 } ;
8584 }
8685
87- allocationsCol . find ( searchCriteria ( ) ) . toArray ( function ( err , allocations ) {
86+ allocationsCol . find ( searchCriteria ( ) ) . toArray ( ( err , allocations ) => {
8887 if ( err ) return callback ( err , null ) ;
8988 if ( ! allocations . length ) return callback ( "ERROR: No allocations found for the user" , null ) ;
9089
91- var doneCounter = 0 ;
92- var userAllocations = [ ] ;
90+ let doneCounter = 0 ;
91+ const userAllocations = [ ] ;
9392
94- allocations . forEach ( function ( alloc ) {
95- userDAO . getUserById ( alloc . userId , function ( err , user ) {
93+ allocations . forEach ( ( alloc ) => {
94+ userDAO . getUserById ( alloc . userId , ( err , user ) => {
9695 if ( err ) return callback ( err , null ) ;
9796
9897 alloc . userName = user . userName ;
0 commit comments