mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-22 12:41:11 +00:00
Load hive data on user retrieval
This commit is contained in:
parent
c1f4679686
commit
1e347d26e5
2 changed files with 23 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
var _ = require("lodash");
|
||||
var async = require("async");
|
||||
var mongoose = require("mongoose");
|
||||
var Profile = mongoose.model("Profile");
|
||||
|
@ -36,13 +37,12 @@ function User (user) {
|
|||
this.steam.id = this.getSteamId();
|
||||
this.hive.id = this.getHiveId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
User.prototype.getSteamId = () => {
|
||||
if (this.steam.url === null) return null;
|
||||
var urlId = this.steam.url.match(/\d*$/);
|
||||
if (!urlId) return null;
|
||||
if (!urlId || urlId[0].length === 0) return null;
|
||||
return steam.convertToText(urlId[0]);
|
||||
};
|
||||
|
||||
|
@ -75,11 +75,28 @@ User.find = (id, callback) => {
|
|||
if (error) return callback(error);
|
||||
if (response.statusCode !== 200) return callback(new Error("Unable to auth user against API"));
|
||||
let user = new User(body);
|
||||
Profile.findOrCreate(user, (error, profile) => {
|
||||
async.parallel([
|
||||
// Retrieve or create user profile from local store
|
||||
callback => {
|
||||
Profile.findOrCreate(user, (error, profile) => {
|
||||
if (error) return callback(error);
|
||||
user.profile = profile.toJson();
|
||||
return callback(null, profile);
|
||||
});
|
||||
},
|
||||
// Retrive Hive Stats
|
||||
callback => {
|
||||
hiveClient.getUserStats(user, (error, response, body) => {
|
||||
if (error || response.statusCode !== 200 || body.id === null) return callback();
|
||||
_.assign(user.hive, body);
|
||||
return callback(null, body);
|
||||
});
|
||||
}
|
||||
], function (error, result) {
|
||||
if (error) return callback(error);
|
||||
user.profile = profile.toJson();
|
||||
console.log(user);
|
||||
return callback(null, user);
|
||||
});
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -6,6 +6,6 @@ var assert = require("chai").assert;
|
|||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
describe("ENSL Client", function () {
|
||||
describe("Hive Client", function () {
|
||||
|
||||
});
|
Loading…
Reference in a new issue