Skip to content

Instantly share code, notes, and snippets.

@kinday
Last active Oct 13, 2015
Embed
What would you like to do?
Object literal shorthands and Boolean values
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