-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
639cdeb
commit 4aaa223
Showing
3 changed files
with
123 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
const userSchema = require('../schemas/users'); | ||
const mongoose = require("mongoose") | ||
|
||
let user; | ||
let promise = new Promise(async function(resolve, reject){ | ||
|
||
try{ | ||
user = await userSchema.create( | ||
{ | ||
name: "Waqas 3", | ||
email: "waqas@gmail.com", | ||
password: "123456" | ||
} | ||
); | ||
}catch (exception){ | ||
reject(exception); //reject the promise | ||
} | ||
|
||
//runs when the user is created | ||
if(user){ | ||
resolve(user);//resolve the promise | ||
//create user schema | ||
const users = mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
lowercase: true | ||
}, | ||
password: { | ||
type: String, | ||
required: true, | ||
minLength: 6 | ||
}, | ||
createdAt: { | ||
type: Date, | ||
default: () => Date.now() | ||
}, | ||
updatedAt: { | ||
type: Date, | ||
default: () => Date.now() | ||
} | ||
|
||
}); | ||
|
||
//once the promise is returned | ||
promise.then( | ||
result => {console.log(result)}, //result = user | ||
error => {console.log(error)} //error = exception | ||
); | ||
/** | ||
* | ||
* create user model - similar to eloquent models | ||
* first argument : name of the model | ||
* second argument : schema object | ||
*/ | ||
module.exports = mongoose.model('User', users); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.