Example #1
0
		self.done = function(oResult, oReq){
			$oResponse = u.omit(oReq,'method', 'params');
			$oResponse.result = oResult;
			if ( !u.isEmpty(oResult) || !u.isUndefined(oResult)){
				self.response.push($oResponse);
			}
			self.requestCount += 1;
		}
Example #2
0
		save: function() {
			var omit = this.settings['save-secret'] == 'no' ? 'shared-secret' : '';
			var settings = _.omit(this.settings, omit);

			localStorage.telepathyWeb = JSON.stringify({
				settings: settings
			});

			this._settings = this.settings;
		},
Example #3
0
								' where ?', [data], function(err, result){
			if ( err ) {
				ret.internal = err.toString();
				util.log(ret.internal);
				return callback(model, ret);
			}

			if ( result.length === 0 ) 
				return callback(model, ret);

			// though this should never happen ...
			if ( result.length > 1 )
				util.log('Excessive results; total ' + result.length);
		
			model.set(_.omit(result[0], 'password', '_typecast', 'parse'));
			return callback(model, ret);
		});
Example #4
0
exports.saveDoc = function(args, next) {
  assert(_.isObject(args), "Please pass in the document for saving as an object. Include the primary key for an UPDATE.");
  var sql, params = [];
  var pkName = this.primaryKeyName();
  var pkVal = args[pkName];

  // if there's a primary key, don't store it in the body as well
  params.push(JSON.stringify(_.omit(args, pkName)));

  if (pkVal) {
    sql = util.format("update %s set body = $1 where %s = $2 returning *;", this.fullname, pkName);
    params.push(pkVal);
  } else {
    sql = "insert into " + this.fullname + "(body) values($1) returning *;";
  }

  this.executeDocQuery(sql, params, {single : true}, next);
};
Example #5
0
			function(err, result){
				if ( err ){
					util.log(err);
					ret.internal = err.toString();
				}
				else if ( result.length == 0 )
					ret.login_errored = message.login_errored;
				else if ( !verifyPassword(data.password, result[0].password) )
					ret.login_errored = message.login_errored;

				if ( !ret.hasError() ){
					var last_login = moment().format('YYYY-MM-DD HH:mm:ss Z');

					model.set(_.omit(result[0], 'password', '_typecast', 'parse'));
					model.set('last_login', last_login);

					// write statistics
					db.getConnection().query('update ' + db.getConfig().database + '.users ' +
											'set last_login = ?, login_count = login_count + 1 ' +
											'where username = ? or email = ?', [last_login, data.login, data.login], 

											function(err, result){
												if ( err ){
													util.log(err);
													ret.internal = err.toString();
												}
												callback(model, ret);
											});
				} else {
					db.getConnection().query('update ' + db.getConfig().database + '.users ' +
											'set failed_login_count = failed_login_count + 1 ' +
											'where username = ? or email = ?', [data.login, data.login], 
											function(err, result){
												if ( err ){
													util.log(err);
													ret.internal = err.toString();
												}
												callback(model, ret);
											});
				}
			});		
Example #6
0
    },
    fun2: function(){
        
    }
};
console.log(_.functions(fun));//[ 'fun1', 'fun2' ]

// extend 复制对象的所有属性到目标对象上,覆盖已有属性
console.log(_.extend({name:'moe'}, {age:8})); //{ name: 'moe', age: 8 }

// default: 复制对象的所有属性到目标对象上,跳过已有属性
console.log(_.defaults({a:'a', b:'b'}, {a:'aa', c:'c'}));//{ a: 'a', b: 'b', c: 'c' }

// pick, omit返回一个对象的副本, 保留指定的属性或去掉指定的属性
console.log(_.pick({name:'tom', age:4}, 'name'));//{ name: 'tom' }
console.log(_.omit({name:'tom', age:4}, 'name'));//{ age: 4 }
// has 判断对象是否包含指定的属性名
console.log(_.has({a:1, b:2, c:3}, 'b')); //true
// isEqual: 判断两个对象是值相等
var moe = {name:'moe', b:[1,2,3]};
var clone = {name:'moe', b:[1,2,3]};
console.log(moe==clone);//false
console.log(_.isEqual(moe, clone));//true
//判断对象类型以下都为空
console.log(_.isEmpty({})); //如果object里没包含任何东西,将返回true
console.log(_.isArray([1,2,3]));
console.log(_.isObject({}));
console.log((function(){ return _.isArguments(arguments); })(1, 2, 3));
console.log(_.isFunction(console.log));
console.log(_.isString("moe"));
console.log(_.isNumber(8.4 * 5));
Example #7
0
import { Astro } from 'meteor/jagi:astronomy';
import { _ } from 'underscore';

const Model = {
  create(model) {
    const astroModel = _.omit(model, 'schema');
    astroModel.fields = model.schema;

    return Astro.Class.create(astroModel);
  }
};

export { Model };