<commit_before>'use strict';

module.exports = function (sequelize, DataTypes) {
  var Bikeshed = sequelize.define('Bikeshed', {
    name: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: '',
      validate: {
        notEmpty: true
      }
    },
    body: {
      type: DataTypes.TEXT,
      allowNull: false,
      defaultValue: '',
      validate: {
        notEmpty: true
      }
    },
    status: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: 'incomplete',
      validate: {
        isIn: [['incomplete', 'open', 'closed']]
      }
    },
    size: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },

    openedAt: {
      type: DataTypes.DATE,
      allowNull: true
    },
    closedAt: {
      type: DataTypes.DATE,
      allowNull: true
    },

    // associations
    UserId: {
      type: DataTypes.INTEGER,
      allowNull: true
    }
  }, {
    // paranoid: true,
    classMethods: {
      associate: function associate (models) {
        models.Bikeshed.hasMany(models.Bike);
        models.Bikeshed.hasMany(models.Vote);
        models.Bikeshed.belongsTo(models.User);
      }
    },
    instanceMethods: {
    },
    validate: {
      statusSize: function statusSize () {
        if (this.get('status') === 'open' && this.get('size') < 2) {
          throw new Error('must have at least two bikes');
        }
      },
      statusTransition: function statusTransition () {
        var changes = {incomplete: 'open', open: 'closed'},
          previous = this.previous('status'), status = this.get('status');
        if (this.changed('status') && previous && status !== changes[previous]) {
          throw new Error(`unexpected status transition ${status}`);
        }
      }
    }
  });

  return Bikeshed;
};<commit_msg>add date validation<commit_after>'use strict';

var _ = require('lodash');

module.exports = function (sequelize, DataTypes) {
  var Bikeshed = sequelize.define('Bikeshed', {
    name: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: '',
      validate: {
        notEmpty: true
      }
    },
    body: {
      type: DataTypes.TEXT,
      allowNull: false,
      defaultValue: '',
      validate: {
        notEmpty: true
      }
    },
    status: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: 'incomplete',
      validate: {
        isIn: [['incomplete', 'open', 'closed']]
      }
    },
    size: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },

    openedAt: {
      type: DataTypes.DATE,
      allowNull: true
    },
    closedAt: {
      type: DataTypes.DATE,
      allowNull: true
    },

    // associations
    UserId: {
      type: DataTypes.INTEGER,
      allowNull: true
    }
  }, {
    // paranoid: true,
    classMethods: {
      associate: function associate (models) {
        models.Bikeshed.hasMany(models.Bike);
        models.Bikeshed.hasMany(models.Vote);
        models.Bikeshed.belongsTo(models.User);
      }
    },
    instanceMethods: {
    },
    validate: {
      statusSize: function statusSize () {
        if (this.get('status') === 'open' && this.get('size') < 2) {
          throw new Error('must have at least two bikes');
        }
      },
      statusTransition: function statusTransition () {
        var changes = {incomplete: 'open', open: 'closed'},
          previous = this.previous('status'), status = this.get('status');
        if (this.changed('status') && previous && status !== changes[previous]) {
          throw new Error(`unexpected status transition ${status}`);
        }
      },
      statusDate: function () {
        var status = this.get('status');
        if (status === 'open' && !_.isDate(this.get('openedAt'))) {
          throw new Error('must have openedAt date to open');
        } else if (status === 'closed' && !_.isDate(this.get('closedAt'))) {
          throw new Error('must have closedAt date to close');
        }
      }
    }
  });

  return Bikeshed;
};
{'fraction_non_alphanumeric': 0.14155588380108322, 'fraction_numerical': 0.0009847365829640572, 'mean_word_length': 2.085041761579347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6915482', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1213, 'n_words': 266}