Skip to content

Instantly share code, notes, and snippets.

@markninja96
Created March 3, 2021 21:17
Show Gist options
  • Select an option

  • Save markninja96/175ea1b12e4d6e52973c734c074c3647 to your computer and use it in GitHub Desktop.

Select an option

Save markninja96/175ea1b12e4d6e52973c734c074c3647 to your computer and use it in GitHub Desktop.
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