This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This function is boilerplate for replicating how Amazon Kinesis events are | |
| // passed to Lambda for processing. | |
| // | |
| // payloadString - The String to package | |
| // | |
| // Returns an Object as the data would be passed to Lambda | |
| function packageEvent(payloadString) { | |
| var encodedPayload = new Buffer(payloadString).toString('base64') | |
| return { | |
| "Records": [{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.firebase = function (req, res) { | |
| if(req.user) { | |
| var generator = new FirebaseTokenGenerator(process.env.FIREBASE_SECRET); | |
| var token = generator.createToken({uid: req.user.id}); | |
| res.send(token); | |
| } else { | |
| res.send(401, {error: "You must be logged in to perform this operation"}); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function authenticateFirebase(token) { | |
| // firebaseUrl is poopulated by gulp via config | |
| var firebaseUrl = 'https://amber-inferno-2148.firebaseio.com/'; | |
| var myFirebaseRef = new Firebase(firebaseUrl); | |
| myFirebaseRef.authWithCustomToken(token, function(error, authData) { | |
| if (error) { | |
| console.log("Login Failed!", error); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This API method returns a limited number of objects based on the limit, but | |
| // it relies on the query parameters to define the pagination filtes (currently | |
| // managed in Angular) | |
| // | |
| // Because it has to make three separate queries, we make use of Mongoose-Q to | |
| // manage the promises in a way that is performant and readable | |
| UserService.prototype.find = function(params, callback) { | |
| // First we parse the parameters | |
| var query = buildUserQuery(params); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Then we will create a return object to which the functions below can add. | |
| var returnObject = {}; | |
| // As we define each database query and its processing logic, the return value | |
| getNextFewUsers = User | |
| .find(query) | |
| .where('deleted').ne(true) | |
| .sort(sort) | |
| .limit(limit) | |
| .populate('company') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // And boom goes the dynamite. | |
| Q.all([ | |
| getNextFewUsers, | |
| getConsultantCount, | |
| getCompanyCount | |
| ]) | |
| .then(function() { | |
| callback(null, returnObject) | |
| }) | |
| .catch(function(err) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UserService.prototype.find = function (params, callback) { | |
| /* | |
| Need: | |
| - sort | |
| - search | |
| */ | |
| var query = {}, | |
| sort = params.sort || 'displayName', | |
| options = { | |
| 'sort': (params.descending ? '-' : '') + sort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UserService.prototype.saveUser = function(user, newUser, callback) { | |
| user.save(function(err) { | |
| if (err) { | |
| log(err); | |
| callback(err, user); | |
| } else { | |
| searchly.indexConsultant(user, function(err, data) { | |
| if (err) log(err); | |
| if (newUser) { | |
| processNewUser(user, callback); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UserSchema.methods.toJSON = function () { | |
| var obj = this.toObject(); | |
| delete obj.password; | |
| return obj; | |
| }; | |
| UserSchema.methods.toCompleteJSON = function () { | |
| var obj = this.toObject(); | |
| delete obj.password; | |
| obj.isNewUser = this.isNewUser() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This post-save hook middleware allows us to publish create and update events | |
| // to which the mediator service can subscribe. | |
| UserSchema.post('save', function (doc) { | |
| // Determine the current event | |
| var eventName = (this.wasNew) ? "user:create" : "user:update"; | |
| if (doc.deleted) {eventName = 'user:delete'} | |
| // Create an authenticate a Firebase ref and update accordingly | |
| var firebaseRef, userRef; |