{"size": 1247, "ext": "js", "max_stars_repo_path": "src/app/models/Doctor.js", "max_stars_repo_name": "FelipePbi/zhealth_doctor_beck-end", "max_stars_repo_stars_event_min_datetime": "2020-07-11T06:09:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-11T06:52:49.000Z", "max_issues_repo_path": "src/app/models/Doctor.js", "max_issues_repo_name": "FelipePbi/zhealth_doctor_beck-end", "max_issues_repo_issues_event_min_datetime": "2021-09-02T11:47:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-02T11:47:41.000Z", "max_forks_repo_path": "src/app/models/Doctor.js", "max_forks_repo_name": "FelipePbi/zhealth_doctor_beck-end", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 17.8142857143, "max_line_length": 54, "alphanum_fraction": 0.6246992783}
import mongoose from 'mongoose';
import bcrypt from 'bcrypt';
import uf_states_enum from '../enums/UfStateEnum';
import gender_enum from '../enums/GenderEnum';

const DoctorSchema = new mongoose.Schema({
  name: {
    type: String,
    trim: true,
    required: true,
  },
  email: {
    type: String,
    trim: true,
    unique: true,
    required: true,
    lowercase: true,
  },
  cpf: {
    type: String,
    required: true,
    maxlength: 11,
    unique: true,
  },
  crm: {
    type: Number,
    required: true,
    unique: true,
  },
  crm_state_registration: {
    type: String,
    enum: uf_states_enum,
    required: true,
  },
  gender: {
    type: String,
    enum: gender_enum,
    required: true,
  },
  date_of_birth: {
    type: Date,
    required: true,
  },
  password: {
    type: String,
    trim: true,
    minlength: 6,
    required: true,
  },
  createdAt: {
    type: Date,
    default: Date.now,
  },
});

DoctorSchema.pre('save', function cript(next) {
  this.password = bcrypt.hashSync(this.password, 8);
  next();
});

class DoctorClass {
  checkPassword(password) {
    return bcrypt.compare(password, this.password);
  }
}

DoctorSchema.loadClass(DoctorClass);

export default mongoose.model('Doctor', DoctorSchema);
