{"size": 2578, "ext": "js", "max_stars_repo_path": "api/controller/backadmin.js", "max_stars_repo_name": "sinabr/Node-Js-Express-Rest-API", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "api/controller/backadmin.js", "max_issues_repo_name": "sinabr/Node-Js-Express-Rest-API", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/controller/backadmin.js", "max_forks_repo_name": "sinabr/Node-Js-Express-Rest-API", "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": 22.6140350877, "max_line_length": 80, "alphanum_fraction": 0.5058184639}
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs')
const jwt = require('jsonwebtoken')

const User = require('../model/user')
const Admin = require('../model/admin')
const Category = require('../model/category')


exports.addAdmin = (req,res,next)=>{

    // var nickname = "sinbr"
    // var fname = "sina"
    // var lname = "barazandeh"
    // var email = "sinabr@sehub.ir"
    // var password = "admin_sina"
    
    var body = req.body
    var nickname = body.nickname
    var fname = body.fname
    var lname = body.lname
    var email = body.email
    var password = body.password

    bcrypt.hash(password , 10 , (err , hash)=>{
        console.log(hash)
        var admin = new Admin({
            _id:mongoose.Types.ObjectId(),
            nickname:nickname,
            lname:lname,
            fname:fname,
            email:email,
            password:hash
        })


        admin.save()
        .then(created=>{
            res.status(201).end()
        }).catch(err=>{console.log(err);res.status(500).send(err)})
    })


    
}


exports.sampleCategories = (req,res,next)=>{

    var catg01 = new Category({
        _id:mongoose.Types.ObjectId(),
        title:'Design'
    })

    catg01.save()
    .then(c1=>{
        var catg02 = new Category({
            _id:mongoose.Types.ObjectId(),
            title:'Architecture',
            parent:c1._id
        })

        catg02.save()
        .then(saved=>{
            Category.updateOne({_id:c1._id},{$push:{children:saved._id}}).exec()
            .then(updated=>{
                res.status(200).send("added")
            })
        })


        var catg03 = new Category({
            _id:mongoose.Types.ObjectId(),
            title:'Interface',
            parent:c1._id
        })


        catg03.save()
        .then(saved=>{
            Category.updateOne({_id:c1._id},{$push:{children:saved._id}}).exec()
            .then(updated=>{
                res.status(200).send("added")
            })
        })

        var catg04 = new Category({
            _id:mongoose.Types.ObjectId(),
            title:'Design Quality Analysis',
            parent:c1._id
        })


        catg04.save()
        .then(saved=>{
            Category.updateOne({_id:c1._id},{$push:{children:saved._id}}).exec()
            .then(updated=>{
                res.status(200).send("added")
            })
        })
    })

    // catg06 = new Category({
    //     _id:mongoose.Types.ObjectId(),
    //     title:'Construction'
    // })

    // catg06.save()
    // .then(c6=>{

    // })


}