const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;

mongoose.Promise = global.Promise;
mongoose.level = "F";


// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
  schema.options.usePushEach = true
});

const CategorySchema = new Schema({
  name: {
    type: String,
    unique: true,
    index: true,
    lowercase: true
  }
});

module.exports.getAllCategories = function (callback) {
  Category.find(callback)
}

module.exports.getCategoryById = function (id, callback) {
  Category.findById(id, callback);
}

module.exports = mongoose.model('Category', CategorySchema);
