{"size": 983, "ext": "js", "max_stars_repo_path": "Schema/user.js", "max_stars_repo_name": "JayZhu173655/personal-blogs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Schema/user.js", "max_issues_repo_name": "JayZhu173655/personal-blogs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Schema/user.js", "max_forks_repo_name": "JayZhu173655/personal-blogs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.914893617, "max_line_length": 56, "alphanum_fraction": 0.502543235}
const {Schema} = require("./config.js");

const UserSchema = new Schema({
    username: String,
    password: String,
    role: {
        type: String,
        default: 1
    },
    avatar: {
        type: String,
        default: "/avatar/default.jpg"
    },
    articleNum: Number,
    commentNum: Number
},{versionKey: false,
    timestamps: {
        createdAt: "created"
    }
});


UserSchema.post("remove", doc => {
    const Article = require("../Models/article.js")
    const Comment = require("../Models/comment.js")

    const {_id} = doc
    

   
    // 把用户所有文章删除
    Article.find({author: _id})
        .then(data => {
            data.forEach(v => v.remove())
        })

    // 删除用户所有评论
    Comment.find({from: _id})
        .then(data => {
            data.forEach(v => v.remove())
        })
        
        //console.log(doc)
        //console.log(Article.find({author: authorId}))
   
})
module.exports = UserSchema;