aboutsummaryrefslogtreecommitdiff
path: root/part4/blog/models
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2023-06-18 20:26:14 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2023-06-18 20:26:14 -0400
commit81c9e17aebc95f0939c5b636ca64af9d47dfc992 (patch)
tree98388d586729b513eee9f975a5819cc6078874e2 /part4/blog/models
parent13ca52505d4a247f72c5fad8161dc497da6da368 (diff)
ex4.2 tackling complexity via modularity
Diffstat (limited to 'part4/blog/models')
-rw-r--r--part4/blog/models/blog.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/part4/blog/models/blog.js b/part4/blog/models/blog.js
new file mode 100644
index 0000000..28a68e9
--- /dev/null
+++ b/part4/blog/models/blog.js
@@ -0,0 +1,19 @@
+const mongoose = require('mongoose')
+
+const blogSchema = new mongoose.Schema({
+ title: String,
+ author: String,
+ url: String,
+ likes: Number
+})
+
+blogSchema.set('toJSON', {
+ transform: (document, returnedObject) => {
+ returnedObject.id = returnedObject._id.toString()
+ delete returnedObject._id
+ delete returnedObject.__v
+ }
+})
+
+
+module.exports = mongoose.model('Blog', blogSchema)