Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/migrate-rooms-changeArchivationState-endpoint.md
Original file line number Diff line number Diff line change
@@ -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.
67 changes: 47 additions & 20 deletions apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
isRoomsCleanHistoryProps,
isRoomsOpenProps,
isRoomsMembersOrderedByRoleProps,
isRoomsChangeArchivationStateProps,
isRoomsHideProps,
isRoomsInviteProps,
validateBadRequestErrorResponse,
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -1041,6 +1021,18 @@ const isRoomsLeavePropsSchema = {

const isRoomsFavoriteProps = ajv.compile<RoomsFavorite>(RoomsFavoriteSchema);
const isRoomsLeaveProps = ajv.compile<RoomsLeave>(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<Pick<IUser, '_id' | 'username' | 'name'>, '_id' | 'username'>[];
Expand Down Expand Up @@ -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<typeof roomEndpoints> &
ExtractRoutesFromAPI<typeof roomDeleteEndpoint> &
Expand Down
25 changes: 0 additions & 25 deletions packages/rest-typings/src/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,6 @@ const RoomsAdminRoomsGetRoomSchema = {

export const isRoomsAdminRoomsGetRoomProps = ajv.compile<RoomsAdminRoomsGetRoomProps>(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<RoomsChangeArchivationStateProps>(RoomsChangeArchivationStateSchema);

type RoomsSaveRoomSettingsProps = {
rid: string;
roomAvatar?: string;
Expand Down Expand Up @@ -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 } };
};
Expand Down