update visibility
This commit is contained in:
parent
dbfe62df6a
commit
1e72349026
|
@ -9,6 +9,7 @@ var TrackSchema = new mongoose.Schema({
|
|||
title: String,
|
||||
description: String,
|
||||
body: String,
|
||||
visible: Boolean,
|
||||
numEvents: {type: Number, default: 0},
|
||||
comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }],
|
||||
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
||||
|
@ -37,6 +38,7 @@ TrackSchema.methods.toJSONFor = function(user){
|
|||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
visibleForAll: this.author ? this.author.areTracksVisibleForAll : false,
|
||||
visible: this.visible,
|
||||
author: this.author.toProfileJSONFor(user)
|
||||
};
|
||||
};
|
||||
|
|
|
@ -180,7 +180,7 @@ router.get('/', auth.optional, function(req, res, next) {
|
|||
.skip(Number(offset))
|
||||
.sort({createdAt: 'desc'})
|
||||
.populate('author')
|
||||
.where('visibleForAll || author == user')
|
||||
.where('visible').equals(true)
|
||||
.exec(),
|
||||
Track.countDocuments(query).exec(),
|
||||
req.payload ? User.findById(req.payload.id) : null,
|
||||
|
@ -191,10 +191,10 @@ router.get('/', auth.optional, function(req, res, next) {
|
|||
//console.log(tracks);
|
||||
var retTracks = [];
|
||||
for (t of tracks) {
|
||||
console.log(t);
|
||||
if (t.author.areTracksVisibleForAll || t.author == user) {
|
||||
//console.log(t);
|
||||
//if (t.author.areTracksVisibleForAll || t.author == user) {
|
||||
retTracks.push(t);
|
||||
}
|
||||
//}
|
||||
}
|
||||
return res.json({
|
||||
tracks: retTracks.map(function(track){
|
||||
|
@ -277,6 +277,7 @@ router.post('/', auth.required, function(req, res, next) {
|
|||
track.trackData = trackData._id;
|
||||
|
||||
track.author = user;
|
||||
track.visible = track.author.areTracksVisibleForAll;
|
||||
trackData.save(function (err){
|
||||
if(err){
|
||||
console.log("failed to save trackData");
|
||||
|
@ -422,10 +423,12 @@ router.put('/:track', auth.required, function(req, res, next) {
|
|||
}
|
||||
|
||||
if(typeof req.body.track.tagList !== 'undefined'){
|
||||
req.track.tagList = req.body.track.tagList
|
||||
req.track.tagList = req.body.track.tagList;
|
||||
}
|
||||
req.track.visible = req.body.track.visible;
|
||||
console.log("saving track");
|
||||
|
||||
req.body.track.save().then(function(track){
|
||||
req.track.save().then(function(track){
|
||||
return res.json({track: track.toJSONFor(user)});
|
||||
}).catch(next);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue