update visibility

This commit is contained in:
hpcwoess 2020-08-28 21:50:53 +02:00
parent dbfe62df6a
commit 1e72349026
2 changed files with 11 additions and 6 deletions

View file

@ -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)
};
};

View file

@ -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 {