23 lines
668 B
JavaScript
23 lines
668 B
JavaScript
var mongoose = require('mongoose');
|
|
var uniqueValidator = require('mongoose-unique-validator');
|
|
var slug = require('slug');
|
|
|
|
var QCMCategorySchema = new mongoose.Schema({
|
|
num: number,
|
|
name: { type: String, lowercase: true, unique: true },
|
|
questions: []
|
|
}, {timestamps: true, toJSON: {virtuals: true}});
|
|
|
|
QCMCategorySchema.plugin(uniqueValidator, { message: 'is already taken' });
|
|
|
|
QCMCategorySchema.methods.toJSONFor = function(){
|
|
return {
|
|
num: this.num,
|
|
name: this.name,
|
|
questions: this.questions,
|
|
createdAt: this.createdAt,
|
|
updatedAt: this.updatedAt
|
|
};
|
|
};
|
|
|
|
mongoose.model('QCMCategory', QCMCategorySchema); |