diff --git a/.changeset/migrate-rooms-changeArchivationState-endpoint.md b/.changeset/migrate-rooms-changeArchivationState-endpoint.md new file mode 100644 index 0000000000000..ad134ac0a5933 --- /dev/null +++ b/.changeset/migrate-rooms-changeArchivationState-endpoint.md @@ -0,0 +1,6 @@ +--- +'@rocket.chat/meteor': minor +'@rocket.chat/rest-typings': minor +--- + +Migrates `rooms.changeArchivationState` to the chained API pattern and removes its dedicated manual validator export from rest-typings in favor of endpoint-local schema definition. \ 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 bb4278bbb70fb..cf50875fad6f5 100644 --- a/apps/meteor/app/api/server/v1/rooms.ts +++ b/apps/meteor/app/api/server/v1/rooms.ts @@ -16,7 +16,6 @@ import { isRoomsCleanHistoryProps, isRoomsOpenProps, isRoomsMembersOrderedByRoleProps, - isRoomsChangeArchivationStateProps, isRoomsHideProps, isRoomsInviteProps, validateBadRequestErrorResponse, @@ -716,25 +715,6 @@ API.v1.addRoute( }, ); -API.v1.addRoute( - 'rooms.changeArchivationState', - { authRequired: true, validateParams: isRoomsChangeArchivationStateProps }, - { - async post() { - const { rid, action } = this.bodyParams; - - let result; - if (action === 'archive') { - result = await executeArchiveRoom(this.userId, rid); - } else { - result = await executeUnarchiveRoom(this.userId, rid); - } - - return API.v1.success({ result }); - }, - }, -); - API.v1.addRoute( 'rooms.export', { authRequired: true, validateParams: isRoomsExportProps }, @@ -1041,6 +1021,18 @@ const isRoomsLeavePropsSchema = { const isRoomsFavoriteProps = ajv.compile(RoomsFavoriteSchema); const isRoomsLeaveProps = ajv.compile(isRoomsLeavePropsSchema); +const isRoomsChangeArchivationStateProps = ajv.compile<{ + rid: string; + action?: string; +}>({ + type: 'object', + properties: { + rid: { type: 'string' }, + action: { type: 'string', nullable: true }, + }, + required: ['rid'], + additionalProperties: false, +}); const roomsBannedUsersResponseSchema = ajv.compile<{ success: true; bannedUsers: RequiredField, '_id' | 'username'>[]; @@ -1374,6 +1366,41 @@ export const roomEndpoints = API.v1 total, }); }, + ) + .post( + 'rooms.changeArchivationState', + { + authRequired: true, + body: isRoomsChangeArchivationStateProps, + response: { + 200: ajv.compile<{ + success: true; + result: unknown; + }>({ + type: 'object', + properties: { + success: { type: 'boolean', enum: [true] }, + result: {}, + }, + required: ['success', 'result'], + additionalProperties: false, + }), + 400: validateBadRequestErrorResponse, + 401: validateUnauthorizedErrorResponse, + }, + }, + async function action() { + const { rid, action } = this.bodyParams; + + let result; + if (action === 'archive') { + result = await executeArchiveRoom(this.userId, rid); + } else { + result = await executeUnarchiveRoom(this.userId, rid); + } + + return API.v1.success({ result }); + }, ); type RoomEndpoints = ExtractRoutesFromAPI & ExtractRoutesFromAPI & diff --git a/packages/rest-typings/src/v1/rooms.ts b/packages/rest-typings/src/v1/rooms.ts index 273cc76869d7f..89a72baeeee2e 100644 --- a/packages/rest-typings/src/v1/rooms.ts +++ b/packages/rest-typings/src/v1/rooms.ts @@ -330,25 +330,6 @@ const RoomsAdminRoomsGetRoomSchema = { export const isRoomsAdminRoomsGetRoomProps = ajv.compile(RoomsAdminRoomsGetRoomSchema); -type RoomsChangeArchivationStateProps = { rid: string; action?: string }; - -const RoomsChangeArchivationStateSchema = { - type: 'object', - properties: { - rid: { - type: 'string', - }, - action: { - type: 'string', - nullable: true, - }, - }, - required: ['rid'], - additionalProperties: false, -}; - -export const isRoomsChangeArchivationStateProps = ajv.compile(RoomsChangeArchivationStateSchema); - type RoomsSaveRoomSettingsProps = { rid: string; roomAvatar?: string; @@ -886,12 +867,6 @@ export type RoomsEndpoints = { }; }; - '/v1/rooms.changeArchivationState': { - POST: (params: RoomsChangeArchivationStateProps) => { - success: boolean; - }; - }; - '/v1/rooms.media/:rid': { POST: (params: { file: File }) => { file: { url: string } }; };