{"size": 951, "ext": "js", "max_stars_repo_path": "backend/models/User.js", "max_stars_repo_name": "OmkarK45/blog-app", "max_stars_repo_stars_event_min_datetime": "2020-10-11T14:45:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-13T04:18:13.000Z", "max_issues_repo_path": "backend/models/User.js", "max_issues_repo_name": "OmkarK45/blog-app", "max_issues_repo_issues_event_min_datetime": "2021-09-07T07:08:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-07T10:46:53.000Z", "max_forks_repo_path": "backend/models/User.js", "max_forks_repo_name": "OmkarK45/blog-app", "max_forks_repo_forks_event_min_datetime": "2021-11-11T19:06:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T16:26:32.000Z"}
{"max_stars_count": 11, "max_issues_count": 1, "max_forks_count": 4, "avg_line_length": 16.6842105263, "max_line_length": 59, "alphanum_fraction": 0.570977918}
const mongoose = require("mongoose");
const Blog = require("../models/Blog").schema;
const Joi = require("@hapi/joi");

const userSchema = new mongoose.Schema({
  username: {
    type: String,
    required: true,
    min: 3,
    max: 256,
  },
  name: {
    type: String,
    require: true,
    min: 3,
    max: 256,
  },
  password: {
    type: String,
    required: true,
    min: 6,
    max: 1024,
  },
  email: {
    type: String,
    required: true,
    min: 5,
    max: 256,
  },
  avatar: {
    type: String,
    required: false,
  },
  socialMedia: [],
  blogs: [
    {
      type: mongoose.Schema.Types.ObjectId,
      ref: "Blog",
    },
  ],
  isAdmin: {
    type: Boolean,
    default: false,
  },
});

function validateUser(user) {
  const schema = {
    email: Joi.string().min(3).max(255).required().email(),
  };
  return schema.validate(user);

}

exports.validate = validateUser;
module.exports = mongoose.model("User", userSchema);
