Example #1
0
	set: function (key, value, cb) {
		dottie.set(this.session, key, value);

		this.controller.request.session = this.session;

		store.set(config.cookie.name + this.id, this.session, config.ttl || 172800, cb || noop);
	},
Example #2
0
 setJson: function (path, value) {
   if (db.getDialect() === 'postgres') {
     this.set(path, value)
   } else {
     const json = this.get('json')
     dottie.set(json, path.replace('json.', ''), value)
     this.set('json', json)
   }
 }
Example #3
0
    }).then(function(user) {
        if (!user) { 
            res.statusCode = 404;
            return res.json({ error: 'user not found'});
        }

        var temp = user.get({plain:true});

        if (!temp.dataMeta) { temp.dataMeta = {}; }

        D.set(temp, 'dataMeta.dataShop.shipping', req.body.data.dataShop.shipping);

        //pass the data into a module to append the flag to indicated complete shipping information
        //for them to start selling.
        user.shopStatus = require('../apps/shipping/isShippingDataComplete.js')(temp);

        return user.save({fields: (user.changed() || []).concat(['dataMeta'])});

    }).then(function(user) {
Example #4
0
  Instance.prototype.set = function(key, value, options) {
    var values
      , originalValue
      , keys
      , i
      , length;

    if (typeof key === 'object' && key !== null) {
      values = key;
      options = value || {};

      if (options.reset) {
        this.dataValues = {};
      }

      // If raw, and we're not dealing with includes or special attributes, just set it straight on the dataValues object
      if (options.raw && !(this.options && this.options.include) && !(options && options.attributes) && !this.Model._hasBooleanAttributes && !this.Model._hasDateAttributes) {
        if (Object.keys(this.dataValues).length) {
          this.dataValues = _.extend(this.dataValues, values);
        } else {
          this.dataValues = values;
        }
        // If raw, .changed() shouldn't be true
        this._previousDataValues = _.clone(this.dataValues);
      } else {
        // Loop and call set

        if (options.attributes) {
          keys = options.attributes;
          if (this.Model._hasVirtualAttributes) {
            keys = keys.concat(this.Model._virtualAttributes);
          }

          if (this.options.includeNames) {
            keys = keys.concat(this.options.includeNames);
          }

          for (i = 0, length = keys.length; i < length; i++) {
            if (values[keys[i]] !== undefined) {
              this.set(keys[i], values[keys[i]], options);
            }
          }
        } else {
          for (key in values) {
            this.set(key, values[key], options);
          }
        }

        if (options.raw) {
          // If raw, .changed() shouldn't be true
          this._previousDataValues = _.clone(this.dataValues);
        }
      }
    } else {
      if (!options)
        options = {};
      if (!options.raw) {
        originalValue = this.dataValues[key];
      }

      // If not raw, and there's a customer setter
      if (!options.raw && this._customSetters[key]) {
        this._customSetters[key].call(this, value, key);
      } else {
        // Check if we have included models, and if this key matches the include model names/aliases

        if (this.options && this.options.include && this.options.includeNames.indexOf(key) !== -1 && value) {
          // Pass it on to the include handler
          this._setInclude(key, value, options);
          return;
        } else {
          // Bunch of stuff we won't do when its raw
          if (!options.raw) {
            // If attribute is not in model definition, return
            if (!this._isAttribute(key)) {
              if (key.indexOf('.') > -1 && this.Model._isJsonAttribute(key.split('.')[0])) {
                Dottie.set(this.dataValues, key, value);
                this.changed(key, true);
              }
              return;
            }

            // If attempting to set primary key and primary key is already defined, return
            if (this.Model._hasPrimaryKeys && originalValue && this.Model._isPrimaryKey(key)) {
              return;
            }

            // If attempting to set read only attributes, return
            if (!this.isNewRecord && this.Model._hasReadOnlyAttributes && this.Model._isReadOnlyAttribute(key)) {
              return;
            }

            // Convert date fields to real date objects
            if (this.Model._hasDateAttributes && this.Model._isDateAttribute(key) && value !== null && value !== undefined && !(value instanceof Date) && !value._isSequelizeMethod) {
              value = new Date(value);
            }
          }

          // Convert boolean-ish values to booleans
          if (this.Model._hasBooleanAttributes && this.Model._isBooleanAttribute(key) && value !== null && value !== undefined && !value._isSequelizeMethod) {
            if (Buffer.isBuffer(value) && value.length === 1) {
              // Bit fields are returned as buffers
              value = value[0];
            }

            if (_.isString(value)) {
              // Only take action on valid boolean strings.
              value = (value === 'true') ? true : (value === 'false') ? false : value;

            } else if (_.isNumber(value)) {
              // Only take action on valid boolean integers.
              value = (value === 1) ? true : (value === 0) ? false : value;
            }
          }

          if (!options.raw && (primitives.indexOf(typeof value) === -1 || value !== originalValue)) {
            this._previousDataValues[key] = originalValue;
            this.changed(key, true);
          }
          this.dataValues[key] = value;
        }
      }
    }

    return this;
  };
Example #5
0
	del: function (key, cb) {
		dottie.set(this.session, key, undefined);

		store.del(key, cb || noop);
	},