chore: use ObjectId.equals instead of toString() comparison
This commit is contained in:
parent
56145565df
commit
2ffb9b7851
|
@ -42,7 +42,7 @@ class Track extends mongoose.Model {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user._id.toString() === this.author._id.toString()) {
|
if (user._id.equals(this.author._id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -303,7 +303,7 @@ router.put(
|
||||||
busboy(),
|
busboy(),
|
||||||
auth.required,
|
auth.required,
|
||||||
wrapRoute(async (req, res) => {
|
wrapRoute(async (req, res) => {
|
||||||
if (req.track.author._id.toString() !== req.user.id.toString()) {
|
if (!req.track.author._id.equals(req.user.id)) {
|
||||||
return res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ router.delete(
|
||||||
'/:track',
|
'/:track',
|
||||||
auth.required,
|
auth.required,
|
||||||
wrapRoute(async (req, res) => {
|
wrapRoute(async (req, res) => {
|
||||||
if (req.track.author._id.toString() === req.user.id.toString()) {
|
if (req.track.author._id.equals(req.user.id)) {
|
||||||
await TrackData.findByIdAndDelete(req.track.trackData);
|
await TrackData.findByIdAndDelete(req.track.trackData);
|
||||||
await req.track.remove();
|
await req.track.remove();
|
||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
|
@ -411,7 +411,7 @@ router.delete(
|
||||||
'/:track/comments/:comment',
|
'/:track/comments/:comment',
|
||||||
auth.required,
|
auth.required,
|
||||||
wrapRoute(async (req, res) => {
|
wrapRoute(async (req, res) => {
|
||||||
if (req.comment.author.toString() === req.user.id.toString()) {
|
if (req.comment.author.equals(req.user.id)) {
|
||||||
req.track.comments.remove(req.comment._id);
|
req.track.comments.remove(req.comment._id);
|
||||||
await req.track.save();
|
await req.track.save();
|
||||||
await Comment.find({ _id: req.comment._id }).remove();
|
await Comment.find({ _id: req.comment._id }).remove();
|
||||||
|
@ -433,6 +433,7 @@ router.get(
|
||||||
|
|
||||||
// console.log("requestTrackData"+req.track);
|
// console.log("requestTrackData"+req.track);
|
||||||
const trackData = await TrackData.findById(req.track.trackData);
|
const trackData = await TrackData.findById(req.track.trackData);
|
||||||
|
|
||||||
// console.log({trackData: trackData});
|
// console.log({trackData: trackData});
|
||||||
return res.json({ trackData: trackData });
|
return res.json({ trackData: trackData });
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue