diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/account.js | 21 | ||||
-rw-r--r-- | models/blogPost.js | 24 | ||||
-rw-r--r-- | models/cmmnt.js | 15 | ||||
-rw-r--r-- | models/user.js | 11 |
4 files changed, 71 insertions, 0 deletions
diff --git a/models/account.js b/models/account.js new file mode 100644 index 0000000..d6f43b4 --- /dev/null +++ b/models/account.js @@ -0,0 +1,21 @@ +const mongoose = require("mongoose"); + +const AccountSchema = new mongoose.Schema({ + name: String, + email: String, + author: { + id: { + type: mongoose.Schema.Types.ObjectId, + ref: "User", + }, + username: String, + }, + posts: [ + { + type: mongoose.Schema.Types.ObjectId, + ref: "blogPost", + }, + ], +}); + +module.exports = new mongoose.model("Account", AccountSchema);
\ No newline at end of file diff --git a/models/blogPost.js b/models/blogPost.js new file mode 100644 index 0000000..70b4e7a --- /dev/null +++ b/models/blogPost.js @@ -0,0 +1,24 @@ +const mongoose = require('mongoose'); + +//Schema Setup +const blogpostSchema = new mongoose.Schema({ + title: String, + image: String, + body: String, + tag: String, + author: { + id: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User' + }, + username: String + }, + comments: [ + { + type: mongoose.Schema.Types.ObjectId, + ref: 'Cmmnt' + } + ] +}); + +module.exports = new mongoose.model('Post', blogpostSchema); diff --git a/models/cmmnt.js b/models/cmmnt.js new file mode 100644 index 0000000..4373e8a --- /dev/null +++ b/models/cmmnt.js @@ -0,0 +1,15 @@ +const mongoose = require('mongoose'); + +//Schema Setup +const cmmntSchema = new mongoose.Schema({ + text: String, + author: { + id: { + type: mongoose.Schema.Types.ObjectId, + ref: 'User' + }, + username: String + } +}); + +module.exports = new mongoose.model('Cmmnt', cmmntSchema); diff --git a/models/user.js b/models/user.js new file mode 100644 index 0000000..49dedf0 --- /dev/null +++ b/models/user.js @@ -0,0 +1,11 @@ +const mongoose = require("mongoose"), + passportLocalMongoose = require("passport-local-mongoose"); + +const UserSchema = new mongoose.Schema({ + username: String, + password: String, +}); + +UserSchema.plugin(passportLocalMongoose); + +module.exports = mongoose.model("User", UserSchema);
\ No newline at end of file |