-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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 1 commit
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 |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ import { | |
| findChannelAndPrivateAutocompleteWithPagination, | ||
| findRoomsAvailableForTeams, | ||
| } from '../lib/rooms'; | ||
| import { required } from 'zod/mini'; | ||
|
|
||
| export async function findRoomByIdOrName({ | ||
| params, | ||
|
|
@@ -311,25 +312,46 @@ API.v1.addRoute( | |
| }, | ||
| ); | ||
|
|
||
| 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 })>({ | ||
| 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); | ||
|
||
|
|
||
| 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.