<commit_before>"use strict";

var mongoose = require('mongoose');
var Role = require('./role.model');
var User = require('./user.model');

//var Schema = mongoose.Shema;
var documentSchema = new mongoose.Schema({
  ownerId: {
    type: mongoose.Schema.Types.ObjectId,
    Ref: 'User',
    required: true
  },

  title: {
    type: String,
    required: true
  },

  content: {
    type: String,
    required: true,
    validate: /[a-zA-Z\^w]/
  },

  role: {
    type: String,
    Ref: 'Role'
  },

  dateCreated: {
    type: Date
  },

  lastModified: {
    type: Date
  }
});

//set dateCreated and lastmodified to current date before saving a document
documentSchema.pre("save", function(next) {

  var doc = this;
  var datetime = new Date();

  // format the output
  var month = datetime.getMonth() + 1;
  var day = datetime.getDate();
  var year = datetime.getFullYear();
  var hour = datetime.getHours();
  if (hour < 10) hour = "0" + hour;
  var min = datetime.getMinutes();
  if (min < 10) min = "0" + min;
  var sec = datetime.getSeconds();
  if (sec < 10) sec = "0" + sec;

  // put it all together
  var dateTimeString = year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec;
  doc.dateCreated = dateTimeString;
  doc.lastModified = dateTimeString;

  next();
});

// The mongoose API requires the model name and schema to create the model
module.exports = mongoose.model("Document", documentSchema);<commit_msg>refactor(models): modify createdAt field<commit_after>"use strict";

var mongoose = require('mongoose');
var Role = require('./role.model');
var User = require('./user.model');
var date = require('./../../seeds/dateHelper')();

// var Schema = mongoose.Shema;
var documentSchema = new mongoose.Schema({
  ownerId: {
    type: mongoose.Schema.Types.ObjectId,
    Ref: 'User',
    required: true
  },

  title: {
    type: String,
    required: true
  },

  content: {
    type: String,
    required: true,
    validate: /[a-zA-Z\^w]/
  },

  role: {
    type: String,
    Ref: 'Role'
  },

  createdAt: {
    type: String
  },

  lastModified: {
    type: Date,
    default: Date.now
  }
});

//set dateCreated and lastmodified to current date before saving a document
documentSchema.pre('save', function(next) {

  var doc = this;
  doc.createdAt = date;
  next();
});

// The mongoose API requires the model name and schema to create the model
module.exports = mongoose.model("Document", documentSchema);
{'fraction_non_alphanumeric': 0.1534369885433715, 'fraction_numerical': 0.004091653027823241, 'mean_word_length': 3.0480132450331126, 'pattern_counts': {'":': 0, '<': 6, '<?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': '6584680', 'n_tokens_mistral': 813, 'n_tokens_neox': 800, 'n_words': 231}