feat(torrents): model torrent add Thumb Schema field

This commit is contained in:
OldHawk
2017-07-21 15:20:28 +08:00
parent f3d7cb7c8b
commit a79eeb6000
5 changed files with 35 additions and 17 deletions

View File

@@ -47,7 +47,7 @@ module.exports = {
enable: true
}
},
thumbsUpScore:{
thumbsUpScore: {
torrent: 10,
topic: 10
}

View File

@@ -105,7 +105,7 @@
mt-scale-by-param="{scale: 3, duration: '.5s'}"
mt-scale-start="false"
title="{{'FORUMS.TITLES.TOPIC_THUMBS_UP' | translate: ({number: vm.forumsConfig.thumbs_up_score}) }}"
>({{vm.topic._scoreList.length}})</i>
>({{vm.topic._thumbs.length}})</i>
</span>
</div>
@@ -128,12 +128,12 @@
</ol>
</div>
<div class="thumbs-up-list"
ng-if="vm.topic._scoreList.length && vm.forumsConfig.show_thumbs_up_user_list">
ng-if="vm.topic._thumbs.length && vm.forumsConfig.show_thumbs_up_user_list">
<div class="thumbs-header" translate="FORUMS.THUMBS_LIST_HEADER"
translate-values="{number: vm.topic._scoreList.length}"></div>
translate-values="{number: vm.topic._thumbs.length}"></div>
<div class="thumbs-users panel-collapsed" id="thumbs-{{vm.topic._id}}">
<span class="thumbs-item"
ng-repeat="sl in vm.topic._scoreList track by $index"
ng-repeat="sl in vm.topic._thumbs track by $index"
user-info="sl.user" info-name></span>
</div>
</div>
@@ -178,7 +178,7 @@
mt-scale-by-param="{scale: 3, duration: '.5s'}"
mt-scale-start="false"
title="{{'FORUMS.TITLES.TOPIC_THUMBS_UP' | translate: ({number: vm.forumsConfig.thumbs_up_score}) }}"
>({{rep._scoreList.length}})</i>
>({{rep._thumbs.length}})</i>
</span>
</div>
<div class="reply-floor">F{{ (vm.currentPage-1) * vm.itemsPerPage + $index + 1 }}</div>
@@ -199,12 +199,12 @@
</li>
</ol>
</div>
<div class="thumbs-up-list" ng-if="rep._scoreList.length && vm.forumsConfig.show_thumbs_up_user_list">
<div class="thumbs-up-list" ng-if="rep._thumbs.length && vm.forumsConfig.show_thumbs_up_user_list">
<div class="thumbs-header" translate="FORUMS.THUMBS_LIST_HEADER"
translate-values="{number: rep._scoreList.length}"></div>
translate-values="{number: rep._thumbs.length}"></div>
<div class="thumbs-users panel-collapsed" id="thumbs-{{rep._id}}">
<span class="thumbs-item"
ng-repeat="sl in rep._scoreList track by $index"
ng-repeat="sl in rep._thumbs track by $index"
user-info="sl.user" info-name></span>
</div>
</div>

View File

@@ -517,7 +517,7 @@ exports.thumbsUp = function (req, res) {
if (r._id.equals(req.query.replyId)) {
//check if already exist
exist = false;
r._scoreList.forEach(function (sr) {
r._thumbs.forEach(function (sr) {
if (sr.user._id.equals(req.user._id)) {
exist = true;
}
@@ -528,7 +528,7 @@ exports.thumbsUp = function (req, res) {
});
} else {
if (req.user.score >= thumbsUpScore.topic) {
r._scoreList.push(thumb);
r._thumbs.push(thumb);
r.user.update({
$inc: {score: thumbsUpScore.topic}
}).exec();
@@ -544,7 +544,7 @@ exports.thumbsUp = function (req, res) {
} else {
//check if already exist
exist = false;
topic._scoreList.forEach(function (sr) {
topic._thumbs.forEach(function (sr) {
if (sr.user._id.equals(req.user._id)) {
exist = true;
}
@@ -555,7 +555,7 @@ exports.thumbsUp = function (req, res) {
});
} else {
if (req.user.score >= thumbsUpScore.topic) {
topic._scoreList.push(thumb);
topic._thumbs.push(thumb);
topic.user.update({
$inc: {score: thumbsUpScore.topic}
}).exec();
@@ -937,10 +937,10 @@ exports.topicById = function (req, res, next, id) {
.populate('user', 'username displayName profileImageURL uploaded downloaded score')
.populate('lastUser', 'username displayName profileImageURL uploaded downloaded')
.populate('updatedBy', 'username displayName profileImageURL uploaded downloaded')
.populate('_scoreList.user', 'username displayName profileImageURL uploaded downloaded')
.populate('_thumbs.user', 'username displayName profileImageURL uploaded downloaded')
.populate('_replies.user', 'username displayName profileImageURL uploaded downloaded')
.populate('_replies.updatedBy', 'username displayName profileImageURL uploaded downloaded')
.populate('_replies._scoreList.user', 'username displayName profileImageURL uploaded downloaded')
.populate('_replies._thumbs.user', 'username displayName profileImageURL uploaded downloaded')
.exec(function (err, topic) {
if (err) {
return next(err);

View File

@@ -62,7 +62,7 @@ var ReplySchema = new Schema({
},
_attach: [AttachSchema],
_scoreList: [ThumbSchema],
_thumbs: [ThumbSchema],
updatedAt: {
type: Date
@@ -115,7 +115,7 @@ var TopicSchema = new Schema({
},
_replies: [ReplySchema],
_attach: [AttachSchema],
_scoreList: [ThumbSchema],
_thumbs: [ThumbSchema],
isTop: {
type: Boolean,

View File

@@ -35,6 +35,23 @@ var CommentSchema = new Schema({
}
});
/**
* Sub Thumb Schema
*/
var ThumbSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User'
},
score: {
type: Number,
default: 0
},
createdAt: {
type: Date,
default: Date.now
}
});
/**
* Torrent Schema
@@ -129,6 +146,7 @@ var TorrentSchema = new Schema({
type: Date,
default: Date.now
},
_thumbs: [ThumbSchema],
_other_torrents: [],
//resource info