<commit_before>"use strict";

const valid_uri = require("valid-url").isUri;
const mongoose  = require("mongoose");
mongoose.Promise = global.Promise;

const Schema = mongoose.Schema;

module.exports = mongoose.model("Shortlink", new Schema({

  path: {
    type: String,
    required: true,
    minlength: 1,
    index: true,
    unique: true
  },

  url: {
    type: String,
    required: true,
    validate: {
      validator: (v) => {
        return (valid_uri(v) !== undefined);
      },
      message: "{VALUE} is not a valid URI"
    }
  },

  created: {
    type: Date,
    default: Date.now
  },

  updated: {
    type: Date,
    default: Date.now
  },

  status_code: {
    type: Number,
    default: 301
  }

}));<commit_msg>Add validation rule for status_code<commit_after>"use strict";

const valid_uri = require("valid-url").isUri;
const mongoose  = require("mongoose");
mongoose.Promise = global.Promise;

const Schema = mongoose.Schema;

module.exports = mongoose.model("Shortlink", new Schema({

  path: {
    type: String,
    required: true,
    minlength: 1,
    index: true,
    unique: true
  },

  url: {
    type: String,
    required: true,
    validate: {
      validator: (v) => {
        return (valid_uri(v) !== undefined);
      },
      message: "{VALUE} is not a valid URI"
    }
  },

  created: {
    type: Date,
    default: Date.now
  },

  updated: {
    type: Date,
    default: Date.now
  },

  status_code: {
    type: Number,
    validate: {
      validator: (v) => {
        return (!isNaN(parseFloat(v)) && isFinite(v));
      },
      message: "{VALUE} must be a valid http status code (i.e. a number)"
    },
    default: 301
  }

}));
{'fraction_non_alphanumeric': 0.14711137581893985, 'fraction_numerical': 0.004764740917212627, 'mean_word_length': 2.5073068893528183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '868442', 'n_tokens_mistral': 581, 'n_tokens_neox': 572, 'n_words': 144}