-
Notifications
You must be signed in to change notification settings - Fork 6
Feature/stefan/favorites #49
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve conflicts.
…into feature/stefan/favorites
controllers/shareController.js
Outdated
|
||
exports.getFavorites = async (req, res) => { | ||
try { | ||
const share = await req.db.Share.findById(req.param.ShareId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nu o sa mearga asta. Trebuie ObjectId(param.ShareId)
also use shareId
and findOne({_id: ..}) instead.
controllers/shareController.js
Outdated
favorites: user.favoriteCourses | ||
}) | ||
} else { | ||
return res.status(HttpStatus.Unathorized).json({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e cu litere mari UNATHORIZED
controllers/shareController.js
Outdated
try { | ||
let newFavoriteCourses = [] | ||
|
||
if (req.user) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this if. The requireAuth middleware do that.
controllers/shareController.js
Outdated
for (const course in req.body.coursesToAdd) { | ||
newFavoriteCourses.push(course) | ||
} | ||
for (const course in req.user.favoriteCourses) { | ||
newFavoriteCourses.push(course) | ||
} | ||
newFavoriteCourses = [new Set(newFavoriteCourses)] | ||
|
||
for (const course in req.body.coursesToRemove) { | ||
newFavoriteCourses.filter((item, index) => item !== course) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not work. you should first get the user: User.findOne({_id: ObjectId(req.user[idClaim])})
after add the new courses user.favoriteCourses = new Set(...user.favoriteCourses, ...body.coursesToAdd)
after filter them user.favoriteCourses.filter(course => coursesToRemove.includes(course))
controllers/shareController.js
Outdated
|
||
await req.db.User.updateOne( | ||
{ _id: ObjectId(req.user[idClaim]) }, | ||
{ password: newFavoriteCourses } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
password...?
controllers/shareController.js
Outdated
try { | ||
let newRecivers = [] | ||
|
||
if (req.user) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, no need for this if
controllers/shareController.js
Outdated
for (const reciverId in req.body.reciverToAdd) { | ||
newRecivers.push(reciverId) | ||
} | ||
for (const reciverId in req.share.recivers) { | ||
newRecivers.push(reciverId) | ||
} | ||
newRecivers = [new Set(newRecivers)] | ||
|
||
for (const reciverId in req.body.reciverToRemove) { | ||
newRecivers.filter((item, index) => item !== reciverId) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do same as below.
controllers/shareController.js
Outdated
for (const reciverId in req.body.reciverToRemove) { | ||
newRecivers.filter((item, index) => item !== reciverId) | ||
} | ||
const share = req.db.Share.find({ ownerId: req.user.id }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be done first and edit the share item
controllers/shareController.js
Outdated
} | ||
const share = req.db.Share.find({ ownerId: req.user.id }) | ||
await req.db.Share.updateOne( | ||
{ _id: share._id }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObjectId
models/share.js
Outdated
|
||
const shareSchema = new Schema( | ||
{ | ||
owner: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You used ownerId in controller
routes/index.js
Outdated
@@ -15,7 +16,7 @@ router.get('/', (req, res) => { | |||
}) | |||
|
|||
router.use('/auth', auth) | |||
|
|||
router.use('/share', share) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move after requireAuth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve comments.
Added routes to get shares and to add/remove courses from favorites