diff --git a/.changeset/may-be-it-work.md b/.changeset/may-be-it-work.md new file mode 100644 index 0000000000000..aed98b60eb0a7 --- /dev/null +++ b/.changeset/may-be-it-work.md @@ -0,0 +1,6 @@ +--- +"@rocket.chat/meteor": minor +"@rocket.chat/rest-typings": minor +--- + +Add OpenAPI support for the Rocket.Chat rooms.hide API endpoints by migrating to a modern chained route definition syntax and utilizing shared AJV schemas for validation \ No newline at end of file diff --git a/apps/meteor/app/api/server/v1/rooms.ts b/apps/meteor/app/api/server/v1/rooms.ts index 835c6cc5fd65b..efc7d480688a2 100644 --- a/apps/meteor/app/api/server/v1/rooms.ts +++ b/apps/meteor/app/api/server/v1/rooms.ts @@ -14,7 +14,6 @@ import { isRoomsOpenProps, isRoomsMembersOrderedByRoleProps, isRoomsChangeArchivationStateProps, - isRoomsHideProps, isRoomsInviteProps, validateBadRequestErrorResponse, validateUnauthorizedErrorResponse, @@ -925,33 +924,22 @@ API.v1.addRoute( }, ); -API.v1.addRoute( - 'rooms.hide', - { authRequired: true, validateParams: isRoomsHideProps }, - { - async post() { - const { roomId } = this.bodyParams; - - if (!(await canAccessRoomIdAsync(roomId, this.userId))) { - return API.v1.unauthorized(); - } - - const user = await Users.findOneById(this.userId, { projections: { _id: 1 } }); - - if (!user) { - return API.v1.failure('error-invalid-user'); - } - - const modCount = await hideRoomMethod(this.userId, roomId); - - if (!modCount) { - return API.v1.failure('error-room-already-hidden'); - } +type RoomsHideProps = { + roomId: string; +}; - return API.v1.success(); +const roomsHideSchema = { + type: 'object', + properties: { + roomId: { + type: 'string', + minLength: 1, }, }, -); + required: ['roomId'], + additionalProperties: false, +}; + type RoomsFavorite = | { @@ -1026,6 +1014,7 @@ const isRoomsLeavePropsSchema = { const isRoomsFavoriteProps = ajv.compile(RoomsFavoriteSchema); const isRoomsLeaveProps = ajv.compile(isRoomsLeavePropsSchema); +const isRoomsHideProps = ajv.compile(roomsHideSchema); export const roomEndpoints = API.v1 .get( @@ -1233,7 +1222,42 @@ export const roomEndpoints = API.v1 return API.v1.success(); }, - ); + ) + .post( + 'rooms.hide', + { + authRequired: true, + body: isRoomsHideProps, + response: { + 200: ajv.compile({ + type:'object', + properties:{ + success:{type:'boolean', enum:[true]}, + }, + required:['success'], + additionalProperties:false, + }), + 400: validateBadRequestErrorResponse, + 401: validateUnauthorizedErrorResponse, + }, + }, + async function action(){ + const { roomId } = this.bodyParams; + + if (!(await canAccessRoomIdAsync(roomId, this.userId))) { + return API.v1.unauthorized('You do not have access to this room'); + } + + const modCount = await hideRoomMethod(this.userId, roomId); + + if (!modCount) { + return API.v1.failure('error-room-already-hidden'); + } + + return API.v1.success(); + + } + ) type RoomEndpoints = ExtractRoutesFromAPI & ExtractRoutesFromAPI & diff --git a/packages/rest-typings/src/v1/rooms.ts b/packages/rest-typings/src/v1/rooms.ts index 97b8d483f2212..e443be821ac5e 100644 --- a/packages/rest-typings/src/v1/rooms.ts +++ b/packages/rest-typings/src/v1/rooms.ts @@ -669,24 +669,6 @@ const membersOrderedByRoleRolePropsSchema = { export const isRoomsMembersOrderedByRoleProps = ajv.compile(membersOrderedByRoleRolePropsSchema); -type RoomsHideProps = { - roomId: string; -}; - -const roomsHideSchema = { - type: 'object', - properties: { - roomId: { - type: 'string', - minLength: 1, - }, - }, - required: ['roomId'], - additionalProperties: false, -}; - -export const isRoomsHideProps = ajv.compile(roomsHideSchema); - type RoomsInviteProps = { roomId: string; action: 'accept' | 'reject'; @@ -847,10 +829,6 @@ export type RoomsEndpoints = { }>; }; - '/v1/rooms.hide': { - POST: (params: RoomsHideProps) => void; - }; - '/v1/rooms.invite': { POST: (params: RoomsInviteProps) => void; };