/** * User: hlogeon * Date: 31.07.13 * Time: 23:36 * TODO: continue creating this * read http://maritz.imtqy.com/nohm/ */ var nohm = require('nohm').Nohm; var redis = require('redis').createClient(); nohm.setClient(redis); nohm.model('User', { properties: { balance: { type: "integer", defaultValue: 0, index: false }, ad_id: { type: "string", index: true }, bonus_games_pending: { type: "boolean", index: false }, chips: { type: "integer", defaultValue: 0 }, source: { type: "string" }, spins_count: { type: "integer", defaultValue: 0 }, mute: { type: "boolean", defaultValue: false }, sound: { type: "boolean", defaultValue: false }, charges_base: { type: "boolean", defaultValue: false }, parent_ref: { type: "string", index: true }, sid: { type: "string", index: true }, bonus_to: { type: "integer", defaultValue: 0 }, points_count: { type: "integer" }, parent_id:{ type: "string", index: true }, invitation_accepted: { type: "string" }, ref_type: { type: "string", index: true }, spins_temporary: { type: "integer" }, enter_date: { type: "integer" }, free_spins: { type: "integer" }, screen: { type: "string" }, last_game: { type: "string" }, startOffer: { type: "boolean", index: true }, last_activity: { type: "integer" }, win_turn: { type: "integer" }, double_game_pending: { type: "integer" }, level: { type: "integer", index: true }, last_spin: { type: "integer" }, uid: { type: "string", index: true }, status: { type: "string" }, bonus_games_temporary: { type: "integer", defaultValue: 0 }, browser: { type: "string" }, builded: { type: string, } }, methods: { getContryFlag: function () { return 'http://example.com/flag_'+this.p('country')+'.png'; }, updateBalance: function (value){ var balance = this.p('balance'); this.p('balance', balance+value); this.save(); }, updateChips: function(value){ var chips = this.p("chips"); this.p("chips", chips+value); this.save(); }, incrSpins: function(){ var spins = this.p('spins_count'); this.p('spins_count', spins+1); this.save(); }, swichMute: function(){ var mute = this.p('mute'); this.p('mute', !mute); this.save(); }, swichSound: function(){ var sound = this.p('sound'); this.p('sound', !sound); this.save(); }, setPointsCount: function (value){ this.p('points_count', value); this.save(); return value; }, incrPointsCount: function(){ var count = this.p('points_count'); this.p('points_count', count+1); this.save(); }, incrSpinsTmp: function(){ var tmp = this.p('spins_temporary'); this.p('spins_temporary', tmp+1); this.save(); }, incrFreeSpins: function(){ var spins = this.p('free_spins'); this.p('free_spins', spins+1); this.save(); }, incrLevel: function(){ var level = this.p('level'); this.p('level', level+1); this.save(); return this.p('level'); } } }); var user = nohm.factory('User'); exports.user = user;
var user = require('./UserTest').user; app.get('/', function (req, res) { // var activeUser = nohm.factory('User'); activeUser.save(function(errs){ if(errs){ // , res.json(errs); } else{ // , res.json(activeUser.allProperties()); } }); // -? app.get('/findUser', function (req, res) { var id = req.body.id; // user.load(id, function(err, aUser){ if(err){ // , ! res.json(err); } else{ // , - , ! console.log(aUser.getCountryFlag()); res.json(aUser.allProperties); } }) });
Source: https://habr.com/ru/post/188630/
All Articles