forked from cnodejs/nodeclub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopic.js
45 lines (40 loc) · 1.34 KB
/
topic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var mongoose = require('mongoose');
var BaseModel = require("./base_model");
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var config = require('../config');
var _ = require('lodash');
var TopicSchema = new Schema({
title: { type: String },
content: { type: String },
author_id: { type: ObjectId },
top: { type: Boolean, default: false }, // 置顶帖
good: {type: Boolean, default: false}, // 精华帖
lock: {type: Boolean, default: false}, // 被锁定主题
reply_count: { type: Number, default: 0 },
visit_count: { type: Number, default: 0 },
collect_count: { type: Number, default: 0 },
create_at: { type: Date, default: Date.now },
update_at: { type: Date, default: Date.now },
last_reply: { type: ObjectId },
last_reply_at: { type: Date, default: Date.now },
content_is_html: { type: Boolean },
tab: {type: String},
deleted: {type: Boolean, default: false},
});
TopicSchema.plugin(BaseModel);
TopicSchema.index({create_at: -1});
TopicSchema.index({top: -1, last_reply_at: -1});
TopicSchema.index({author_id: 1, create_at: -1});
TopicSchema.virtual('tabName').get(function () {
var tab = this.tab;
var pair = _.find(config.tabs, function (_pair) {
return _pair[0] === tab;
});
if (pair) {
return pair[1];
} else {
return '';
}
});
mongoose.model('Topic', TopicSchema);