From 81c9e17aebc95f0939c5b636ca64af9d47dfc992 Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Sun, 18 Jun 2023 20:26:14 -0400 Subject: ex4.2 tackling complexity via modularity --- part4/blog/models/blog.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 part4/blog/models/blog.js (limited to 'part4/blog/models') 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) -- cgit v1.2.3