Last active
August 29, 2015 14:00
-
-
Save minipai/11309560 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require( 'mongoose' ) | |
, ObjectId = mongoose.Schema.Types.ObjectId | |
, Board = mongoose.model( 'Board' ) | |
, BoardAdmin = mongoose.model( 'BoardAdmin' ) | |
, Post = mongoose.model( 'Post' ) | |
exports.show = function(req, res) { | |
var data = {} | |
Board | |
.findOne({name: req.params.board}) | |
.exec() | |
.then(function(board) { | |
data.board = board | |
return BoardAdmin.findOne({_board: board._id, _user:req.user._id}).exec() | |
}) | |
.then(function(boardAdmin) { | |
return Post | |
.find( {_board: boardAdmin._name} ) | |
.where('_id').nin(boardAdmin.hidden_posts) | |
.exec() | |
}) | |
.then(function(posts) { | |
data.post = posts | |
res.render('content/boards/show', data) | |
}) | |
.then(null, function(err) { | |
console.log(err) | |
}) | |
.end() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var boardSchema = new Schema({ | |
name : { type: String, required: true, trim: true }, | |
title : { type: String, required: true, trim: true }, | |
post_count : { type: Number, default: 0 }, | |
updated_at : { type: Date, default: new Date() }, | |
master : { type: ObjectId } | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var boardAdminSchema = new Schema({ | |
_user : { type: ObjectId , ref: 'User' }, | |
_board : { type: ObjectId , required: true, ref: 'Board' }, | |
stared_posts : [ { type: ObjectId, ref: 'Post' } ], | |
hidden_posts : [ { type: ObjectId, ref: 'Post' } ], | |
blocked_users : [ { type: ObjectId, ref: 'Post' } ], | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var postSchema = new Schema({ | |
title : { type: String , required: true, trim: true }, | |
content : { type: String , required: true, trim: true }, | |
status : { type: String , trim: true }, | |
embed : { type: Object }, | |
comments : { type: Array, }, | |
_board : { type: String , required: true, ref: 'User' }, | |
_user : { type: ObjectId , required: true, ref: 'User' }, | |
_replyTo : { type: ObjectId , ref: 'Post' }, | |
_crossForm: { type: ObjectId , ref: 'Post' }, | |
updated_at: { type: Date, default: new Date() } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think u can merge two
then
calls into one: