<commit_before>import Promise from 'bluebird';
import _ from 'lodash';
import debugLib from 'debug';
import slugify from 'limax';
import { Op } from 'sequelize';

import CustomDataTypes from './DataTypes';
import { maxInteger } from '../constants/math';
import { capitalize, pluralize, days, formatCurrency } from '../lib/utils';

const debug = debugLib('tier');

export default function(Sequelize, DataTypes) {
  const { models } = Sequelize;

  const Tier = Sequelize.define(
    'Tier',
    {
      id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },

      CollectiveId: {
        type: DataTypes.INTEGER,
        references: {
          model: 'Collectives',
          key: 'id',
        },
        onDelete: 'SET NULL',
        onUpdate: 'CASCADE',
      },

      // human readable way to uniquely access a tier for a given collective or collective/event combo
      slug: {
        type: DataTypes.STRING,
        set(slug) {
          if (slug && slug.toLowerCase) {
            this.setDataValue('slug', slugify(slug));
          }
        },
      },

      name: {
        type: DataTypes.STRING,
        allowNull: false,
        set(name) {
          if (!this.getDataValue('slug')) {
            this.slug = name;
          }
          this.setDataValue('name', name);
        },
      },

      type: {
        type: DataTypes.STRING, // TIER, TICKET, DONATION, SERVICE, PRODUCT, MEMBERSHIP
        defaultValue: 'TIER',
      },

      description: DataTypes.STRING,

      longDescription: {
        type: DataTypes.TEXT,
        validate: {
          // Max length for arround 1_000_000 characters ~4MB of text
          len: [0, 1000000],
        },
      },

      button: DataTypes.STRING,

      amount: {
        type: DataTypes.INTEGER, // In cents
        validate: {
          min: 0,
        },
      },

      presets: {
        type: DataTypes.ARRAY(DataTypes.INTEGER),<commit_msg>chore(Tier): Add strip_tags to longDescription<commit_after>import Promise from 'bluebird';
import _ from 'lodash';
import debugLib from 'debug';
import slugify from 'limax';
import { Op } from 'sequelize';

import CustomDataTypes from './DataTypes';
import { maxInteger } from '../constants/math';
import { capitalize, pluralize, days, formatCurrency, strip_tags } from '../lib/utils';

const debug = debugLib('tier');

export default function(Sequelize, DataTypes) {
  const { models } = Sequelize;

  const Tier = Sequelize.define(
    'Tier',
    {
      id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },

      CollectiveId: {
        type: DataTypes.INTEGER,
        references: {
          model: 'Collectives',
          key: 'id',
        },
        onDelete: 'SET NULL',
        onUpdate: 'CASCADE',
      },

      // human readable way to uniquely access a tier for a given collective or collective/event combo
      slug: {
        type: DataTypes.STRING,
        set(slug) {
          if (slug && slug.toLowerCase) {
            this.setDataValue('slug', slugify(slug));
          }
        },
      },

      name: {
        type: DataTypes.STRING,
        allowNull: false,
        set(name) {
          if (!this.getDataValue('slug')) {
            this.slug = name;
          }
          this.setDataValue('name', name);
        },
      },

      type: {
        type: DataTypes.STRING, // TIER, TICKET, DONATION, SERVICE, PRODUCT, MEMBERSHIP
        defaultValue: 'TIER',
      },

      description: DataTypes.STRING,

      longDescription: {
        type: DataTypes.TEXT,
        validate: {
          // Max length for arround 1_000_000 characters ~4MB of text
          len: [0, 1000000],
        },
        set(content) {
          if (!content) {
            this.setDataValue('longDescription', null);
          } else {
            this.setDataValue('longDescription', strip_tags(content));
          }
        },
      },

      button: DataTypes.STRING,

      amount: {
        type: DataTypes.INTEGER, // In cents
        validate: {
          min: 0,
        },
      },

      presets: {
        type: DataTypes.ARRAY(DataTypes.INTEGER),
{'fraction_non_alphanumeric': 0.12037258180081203, 'fraction_numerical': 0.008120372581800811, 'mean_word_length': 1.8882758620689655, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5409956', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1225, 'n_words': 304}