Created
March 3, 2021 21:17
-
-
Save markninja96/175ea1b12e4d6e52973c734c074c3647 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const mongoose = require("mongoose"); | |
| const Joi = require("joi"); | |
| const Schema = mongoose.Schema; | |
| const PostSchema = new Schema({ | |
| title: { | |
| type: String, | |
| required: true, | |
| }, | |
| imgUrl: { | |
| type: String, | |
| required: true, | |
| }, | |
| content: { | |
| type: String, | |
| required: true, | |
| }, | |
| creator: { | |
| type: mongoose.Schema.Types.ObjectId, | |
| ref: "User", | |
| }, | |
| }); | |
| const Post = mongoose.model("Post", PostSchema); | |
| function validatePost(post) { | |
| const schema = { | |
| title: Joi.string().required(), | |
| imgUrl: Joi.string().required(), | |
| content: Joi.string().required(), | |
| }; | |
| return Joi.validate(post, schema); | |
| } | |
| exports.Post = Post; | |
| exports.validatePost = validatePost; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment