/*jslint eqeq: true, indent: 2, node: true, plusplus: true, regexp: true, unparam: true, vars: true, nomen: true */
'use strict';

var Schema = require('mongoose').Schema;

/**
 * The article schema.
 */
var PostSchema = new Schema({
  type: {type: Number, 'default': 0},
  author: String,
  catalog: {type: String, ref: 'Catalog'},
  tags: [String],
  title: String,
  content: String,
  date: {type: Date, 'default': Date.now}
});

var statics = PostSchema.statics;

statics.listLatestPosts = function (param, cb) {
  var q = this.find();
  if (param) {
    if (param.start) {
      q.skip(param.start);
    }
    if (param.limit) {
      q.limit(param.limit);
    }
  }
  q.sort({date: 'desc'});
  if (cb) {
    return q.exec(cb);
  } else {
    return q;
  }
};

module.exports = PostSchema;

@@ -466,77 +466,1418 @@
 s;%0A%0A
-statics.listLatestPosts = function (param, cb) %7B%0A  var q = this.find(
+/**%0A * List latest posts by a range.%0A *%0A * @param %7Bstart: .., limit:..%7D structure.%0A * @param cb the optional callback%0A * @return mongoose#Query if cb is not specified.%0A */%0Astatics.listLatestPosts = function (param, cb) %7B%0A  var q = this.find();%0A  if (param) %7B%0A    if (param.start) %7B%0A      q.skip(param.start);%0A    %7D%0A    if (param.limit) %7B%0A      q.limit(param.limit);%0A    %7D%0A  %7D%0A  q.sort(%7Bdate: 'desc'%7D);%0A  if (cb) %7B%0A    return q.exec(cb);%0A  %7D else %7B%0A    return q;%0A  %7D%0A%7D;%0A%0A/**%0A * List posts by a specific tag(s).%0A *%0A * @param tags the list of tags or a single tag.%0A * @param param the %7Bstart: .., limit: ..%7D structure.%0A * @return mongoose#Query%0A */%0Astatics.listByTags = function (tags, param, cb) %7B%0A  if (typeof tags == 'string') %7B%0A    tags = %5Btags%5D;%0A  %7D%0A  var q = this.find(%7Btags: %7B$all: tags%7D%7D);%0A  if (param) %7B%0A    if (param.start) %7B%0A      q.skip(param.start);%0A    %7D%0A    if (param.limit) %7B%0A      q.limit(param.limit);%0A    %7D%0A  %7D%0A  q.sort(%7Bdate: 'desc'%7D);%0A  if (cb) %7B%0A    return q.exec(cb);%0A  %7D else %7B%0A    return q;%0A  %7D%0A%7D;%0A%0A/**%0A * List posts of a user by a specific tag(s).%0A *%0A * @param user the name of user.%0A * @param tags the list of tags or a single tag.%0A * @param param the %7Bstart: .., limit: ..%7D structure.%0A * @return mongoose#Query%0A */%0Astatics.listByUserTags = function (user, tags, param, cb) %7B%0A  if (typeof tags == 'string') %7B%0A    tags = %5Btags%5D;%0A  %7D%0A  var q = this.find(%7Btags: %7B$all: tags%7D, author: user%7D
 );%0A 

Add tag-related functions.