18 lines
508 B
JavaScript
18 lines
508 B
JavaScript
const mongoose = require("mongoose");
|
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
const CategorySchema = new Schema({
|
|
name: { type: String, required: true },
|
|
simpleName: { type: String, required: true },
|
|
description: { type: String, required: true },
|
|
});
|
|
|
|
// Virtual for author's URL
|
|
CategorySchema.virtual("url").get(function () {
|
|
// We don't use an arrow function as we'll need the this object
|
|
return `/${this.simpleName}`;
|
|
});
|
|
|
|
// Export model
|
|
module.exports = mongoose.model("Category", CategorySchema);
|