Last active
October 13, 2015 15:27
-
-
Save kinday/e02a6be9509a696120d6 to your computer and use it in GitHub Desktop.
Object literal shorthands and Boolean values
This file contains 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
import mongoose, { Schema } from 'mongoose'; | |
// Define helper for `required` property and never | |
// write `required: true` again. | |
// Why? It’s DRY and improves readability. | |
const required = true; | |
export default (function _createTaskModel() { | |
let model; | |
if (mongoose.modelNames().indexOf('Task') < 0) { | |
const schema = new Schema({ | |
type: { type: String, required, enum: ['base', 'promo'] }, | |
title: { type: String, required } | |
priority: Number, | |
score: { type: Number, required }, | |
published: { type: Boolean, required }, | |
}); | |
model = mongoose.model('Task', schema); | |
} else { | |
model = mongoose.model('Task'); | |
} | |
return model; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment