UNPKG

sheercms

Version:

Sheer Cliff CMS is a simple and powerful content management system (CMS) for Node JS.

49 lines (43 loc) 1.64 kB
var mongoose = require('mongoose'); var contentSchema = mongoose.Schema({ contentId: { type: mongoose.Schema.Types.ObjectId, index: true }, name: String, url: { type: String, index: true }, created: Date, modified: Date, createdBy: String, modifiedBy: String, startDate: Date, endDate: Date, author: String, language: String, status: String, //N=new, S=saved, P=published, M=published-modified, D=deleted templateId: mongoose.Schema.Types.ObjectId, typeId: mongoose.Schema.Types.ObjectId, branch: String, filePath: String, tags: [String], groupId: { type: mongoose.Schema.Types.ObjectId, index: true }, category: String, fields: mongoose.Schema.Types.Mixed }); var models = { Draft: mongoose.model('drafts', contentSchema), Published: mongoose.model('published', contentSchema), Backup: mongoose.model('backups', contentSchema) }; //Unique URL Validation models.Draft.schema.path('url').validate(function (value, respond) { if (this.isNew == true && this.base != 'block' && this.url && this.url.length > 0) { if (this.collection && this.collection.name == 'drafts') { models.Draft.findOne({ url: value }, function (err, page) { if (page) respond(false); else respond(true); }); } else respond(true); } else respond(true); }, 'A page with this URL already exists.'); module.exports = models;