tracks visible for all
This commit is contained in:
parent
d3a1c9edcc
commit
1ab316c774
|
@ -36,8 +36,7 @@ TrackSchema.methods.toJSONFor = function(user){
|
|||
description: this.description,
|
||||
createdAt: this.createdAt,
|
||||
updatedAt: this.updatedAt,
|
||||
points: this.points,
|
||||
visibleForAll: user ? user.areTracksVisibleForAll : false,
|
||||
visibleForAll: this.author ? this.author.areTracksVisibleForAll : false,
|
||||
author: this.author.toProfileJSONFor(user)
|
||||
};
|
||||
};
|
||||
|
|
|
@ -47,6 +47,7 @@ UserSchema.methods.toAuthJSON = function(){
|
|||
token: this.generateJWT(),
|
||||
bio: this.bio,
|
||||
image: this.image,
|
||||
areTracksVisibleForAll: this.areTracksVisibleForAll,
|
||||
apiKey: this._id
|
||||
};
|
||||
};
|
||||
|
@ -79,9 +80,9 @@ UserSchema.methods.isFavorite = function(id){
|
|||
});
|
||||
};
|
||||
|
||||
//UserSchema.methods.areTracksVisibleForAll = function(id){
|
||||
// return this.areTracksVisibleForAll();
|
||||
//};
|
||||
UserSchema.methods.isTrackVisible = function(id){
|
||||
return this.areTracksVisibleForAll();
|
||||
};
|
||||
|
||||
|
||||
UserSchema.methods.follow = function(id){
|
||||
|
|
|
@ -188,12 +188,18 @@ router.get('/', auth.optional, function(req, res, next) {
|
|||
var tracksCount = results[1];
|
||||
var user = results[2];
|
||||
//console.log(tracks);
|
||||
|
||||
var retTracks = [];
|
||||
for (t of tracks) {
|
||||
console.log(t);
|
||||
if (t.author.areTracksVisibleForAll || t.author == user) {
|
||||
retTracks.push(t);
|
||||
}
|
||||
}
|
||||
return res.json({
|
||||
tracks: tracks.map(function(track){
|
||||
return track.toJSONFor(user);
|
||||
tracks: retTracks.map(function(track){
|
||||
return track.toJSONFor(user);
|
||||
}),
|
||||
tracksCount: tracksCount
|
||||
tracksCount: retTracks.length
|
||||
});
|
||||
});
|
||||
}).catch(next);
|
||||
|
|
|
@ -29,6 +29,9 @@ router.put('/user', auth.required, function(req, res, next){
|
|||
if(typeof req.body.user.image !== 'undefined'){
|
||||
user.image = req.body.user.image;
|
||||
}
|
||||
if(typeof req.body.user.areTracksVisibleForAll !== 'undefined'){
|
||||
user.areTracksVisibleForAll = req.body.user.areTracksVisibleForAll;
|
||||
}
|
||||
if(typeof req.body.user.password !== 'undefined'){
|
||||
user.setPassword(req.body.user.password);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue