-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.js
34 lines (31 loc) · 986 Bytes
/
seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Import User Scehma and Passport
const User=require("./models/users");
const passport=require("passport");
const LocalStrategy = require("passport-local");
//Create a new User obj
const newAdmin = new User({username: "admin",Name: "Aditya", isAdmin: true, userType: "admin"});
function seedDB(){
//find for admin
User.findOne({isAdmin: true},function (err, admin) {
//if error
if (err){
console.log(err);
} else{
//if found
if(admin){
console.log("Admin found" + JSON.stringify(admin));
}else{
//if not found
console.log("create admin ");
User.register(newAdmin, "secret",function (err, user) {
if (err){
console.log(err);
}else{
console.log(user);
}
});
}
}
});
}
module.exports = seedDB;