{"size": 1137, "ext": "js", "max_stars_repo_path": "models/post.js", "max_stars_repo_name": "Dreaprince/Greenish-Blog-Backend", "max_stars_repo_stars_event_min_datetime": "2021-09-19T18:51:16.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-19T18:51:16.000Z", "max_issues_repo_path": "models/post.js", "max_issues_repo_name": "Dreaprince/Greenish-Blog-Backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/post.js", "max_forks_repo_name": "Dreaprince/Greenish-Blog-Backend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.9473684211, "max_line_length": 55, "alphanum_fraction": 0.5030782762}
const Joi = require('joi');
const mongoose = require('mongoose');


const postSchema = new mongoose.Schema({
    user: { 
        type: new mongoose.Schema({
          name: {
            type: String,
            required: true,
            minlength: 5,
            maxlength: 50
          }   
        }),  
        required: true
      },
     title: {
         type: String,
         required: true,
         minlength: 5,
         maxlength: 250
     },
     img: {
       type: String
     },
     desc: {
        type: String,
        required: true,
        maxlength: 250
    },
    likes: {
       type: Array,
       default: []
    }
}, {
    timestamps: true
});


const Post = mongoose.model('Post', postSchema);


const validatePost = (post) => {
    const schema = Joi.object({
        userId: Joi.objectId().required(),
        title: Joi.string().min(5).max(250).required(),
        img: Joi.string().required(),
        desc: Joi.string().max(250).required(),
        likes: Joi.array(),
        comment: Joi.array()
    })
      return schema.validate(post);
}

exports.Post = Post;
exports.validate = validatePost;
