Files
headup_api/models/mongo/QCM.js
T
2024-01-11 16:54:27 +01:00

24 lines
666 B
JavaScript

var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var slug = require('slug');
var QCMSchema = new mongoose.Schema({
name: { type: String, lowercase: true, unique: true },
categories: [
{ type: mongoose.Schema.Types.ObjectId, ref: 'QCMCategory' }
]
}, {timestamps: true, toJSON: {virtuals: true}});
QCMSchema.plugin(uniqueValidator, { message: 'is already taken' });
QCMSchema.methods.toJSONFor = function(){
return {
name: this.name,
categories: this.categories,
createdAt: this.createdAt,
updatedAt: this.updatedAt
};
};
mongoose.model('QCM', QCMSchema);