Skip to content

Instantly share code, notes, and snippets.

@kinday
Last active October 13, 2015 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinday/e02a6be9509a696120d6 to your computer and use it in GitHub Desktop.
Save kinday/e02a6be9509a696120d6 to your computer and use it in GitHub Desktop.
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