[NEW] REST API endpoint rooms.favorite to favorite and unfavorite rooms#10342
[NEW] REST API endpoint rooms.favorite to favorite and unfavorite rooms#10342
rooms.favorite to favorite and unfavorite rooms#10342Conversation
| RocketChat.API.v1.addRoute('rooms.favorite/:roomId', { authRequired: true }, { | ||
| post() { | ||
| const { favorite } = this.bodyParams; | ||
| const { roomId } = this.urlParams; |
There was a problem hiding this comment.
Why is "roomId" in the url path and "favorite" in the body? Why not everything in the body? 🤔
Like:
https://rocket.chat/docs/developer-guides/rest-api/channels/invite/
https://rocket.chat/docs/developer-guides/rest-api/channels/leave/
...
There was a problem hiding this comment.
I tried to follow what was instructed here, but we can put it in the body, no problem
There was a problem hiding this comment.
If you'll notice the suggestion you linked to, both the roomId and the favoriting was in the query parameters and not the body or the url path.
| } | ||
| }); | ||
|
|
||
| RocketChat.API.v1.addRoute('rooms.favorite/:roomId', { authRequired: true }, { |
There was a problem hiding this comment.
Let's convert this to be like the other v1 items, where the data is passed into it via the body params. This way it can be either the room name or the id and so we're not changing on people.
Fix rooms.favorite endpoint, change params from url to body.
|
|
||
| RocketChat.API.v1.addRoute('rooms.favorite', { authRequired: true }, { | ||
| post() { | ||
| const { favorite, roomId } = this.bodyParams; |
There was a problem hiding this comment.
Let's make it so we also accept roomName like we do for channels. Like this method but allow it to accept any type of room and for features such as favorite, ensure they are part of that room (have a subscription). Especially since the toggleFavorite method doesn't check to ensure they have a subscription or are part of that room.
Rocket.Chat/packages/rocketchat-api/server/v1/channels.js
Lines 3 to 30 in a9aea36
Add support to roomName param in rooms.favorite endpoint
server/methods/toogleFavorite.js
Outdated
| const userSubscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, Meteor.userId()); | ||
| if (!userSubscription) { | ||
| throw new Meteor.Error('error-invalid-subscription', | ||
| 'Invalid subscription', |
There was a problem hiding this comment.
I think a better error would be "you can't favorite" a room you aren't part of... I need to test, but before this change what happens when you try to favorite a room that you aren't part of?
There was a problem hiding this comment.
The endpoint returns success, but no data is changed. =/
There was a problem hiding this comment.
This is a good change. Let's keep it how it is but change the Invalid subscription to You must be part of a room to favorite it?
graywolf336
left a comment
There was a problem hiding this comment.
Change the message returned from the toggleFavorite method then it'll be good to go in my opinion. 👍
Change the error message when in toggleFavorite method
Add more tests case, by roomId and roomName in /rooms.favorite endpoint
rooms.favorite to favorite and unfavorite rooms
Add rooms.favorite endpoint to favorite and unfavorite room, and tests.
Closes #10317.