-
Notifications
You must be signed in to change notification settings - Fork 13.8k
refactor: migrate rooms.favorite endpoint to new OpenAPI pattern with AJV validation #38929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
18b6d0f
d4cb375
9381755
528a5d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Migrated rooms.favorite endpoint to new OpenAPI pattern with AJV validation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,7 @@ | |
| import { getPaginationItems } from '../helpers/getPaginationItems'; | ||
| import { getUserFromParams } from '../helpers/getUserFromParams'; | ||
| import { MultipartUploadHandler } from '../lib/MultipartUploadHandler'; | ||
| import { | ||
| findAdminRoom, | ||
| findAdminRooms, | ||
| findAdminRoomsAutocomplete, | ||
|
|
@@ -64,6 +64,7 @@ | |
| findChannelAndPrivateAutocompleteWithPagination, | ||
| findRoomsAvailableForTeams, | ||
| } from '../lib/rooms'; | ||
| import { required } from 'zod/mini'; | ||
|
Check failure on line 67 in apps/meteor/app/api/server/v1/rooms.ts
|
||
|
|
||
| export async function findRoomByIdOrName({ | ||
| params, | ||
|
|
@@ -311,25 +312,46 @@ | |
| }, | ||
| ); | ||
|
|
||
| API.v1.addRoute( | ||
| 'rooms.favorite', | ||
| { authRequired: true }, | ||
| { | ||
| async post() { | ||
| const { favorite } = this.bodyParams; | ||
| export const roomsFavoriteEndpoint = API.v1.post('rooms.favorite', { | ||
| authRequired: true, | ||
| body: ajv.compile<{ favorite: boolean} & ({ roomId: string} | { roomName: string })>({ | ||
|
Check failure on line 317 in apps/meteor/app/api/server/v1/rooms.ts
|
||
| type: 'object', | ||
| properties: { | ||
| roomId: { type: 'string', minLength: 1 }, | ||
| roomName: { type: 'string', minLength: 1 }, | ||
| favorite: { type: 'boolean' }, | ||
| }, | ||
| oneOf: [ | ||
| { required: ['roomId', 'favorite'] }, | ||
| { required: ['roomName', 'favorite'] }, | ||
| ], | ||
| additionalProperties: false | ||
| }), | ||
| response: { | ||
| 200: ajv.compile({ | ||
| type: 'object', | ||
| properties: { success: { type: 'boolean', enum: [true] } }, | ||
| required: ['success'], | ||
| additionalProperties: false, | ||
| }), | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| } | ||
| }, | ||
| async function action() { | ||
| const { favorite } = this.bodyParams; | ||
| const room = await findRoomByIdOrName({ params: this.bodyParams }); | ||
|
|
||
| if (!this.bodyParams.hasOwnProperty('favorite')) { | ||
| return API.v1.failure("The 'favorite' param is required"); | ||
| } | ||
| await toggleFavoriteMethod(this.userId, room._id, favorite); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The old endpoint did not go through If archiving a room should not prevent it from being un-favorited, pass 🐛 Proposed fix- const room = await findRoomByIdOrName({ params: this.bodyParams });
+ const room = await findRoomByIdOrName({ params: this.bodyParams, checkedArchived: false });#!/bin/bash
# Check what the old rooms.favorite addRoute handler did before this PR (git blame / old code search)
rg -n 'rooms\.favorite' apps/meteor/app/api/server/v1/rooms.ts
rg -n 'toggleFavorite' apps/meteor/app/api/server/v1/rooms.ts🤖 Prompt for AI Agents |
||
|
|
||
| const room = await findRoomByIdOrName({ params: this.bodyParams }); | ||
| return API.v1.success(); | ||
| }); | ||
|
|
||
| await toggleFavoriteMethod(this.userId, room._id, favorite); | ||
| type RoomsFavoriteEndpoint = ExtractRoutesFromAPI<typeof roomsFavoriteEndpoint>; | ||
|
|
||
| return API.v1.success(); | ||
| }, | ||
| }, | ||
| ); | ||
| declare module '@rocket.chat/rest-typings' { | ||
| interface Endpoints extends RoomsFavoriteEndpoint {} | ||
| } | ||
|
|
||
| API.v1.addRoute( | ||
| 'rooms.cleanHistory', | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.