Skip to content

Commit 02630d2

Browse files
committed
refactor: migrate rooms.delete endpoint to new API format
- Replace deprecated addRoute with chained .post() method - Add body validation using ajv.compile for roomId - Add response schemas for 200, 400, 401 status codes - Register types via ExtractRoutesFromAPI and declare module - Enable automatic OpenAPI spec generation for rooms.delete
1 parent eb366e7 commit 02630d2

File tree

2 files changed

+46
-27
lines changed

2 files changed

+46
-27
lines changed

apps/meteor/app/api/server/v1/rooms.ts

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,37 +121,58 @@ API.v1.addRoute(
121121
},
122122
);
123123

124-
API.v1.addRoute(
124+
const roomDeleteEndpoint = API.v1.post(
125125
'rooms.delete',
126126
{
127127
authRequired: true,
128+
body: ajv.compile<{ roomId: string }>({
129+
type: 'object',
130+
properties: {
131+
roomId: {
132+
type: 'string',
133+
description: 'The ID of the room to delete.',
134+
},
135+
},
136+
required: ['roomId'],
137+
additionalProperties: false,
138+
}),
139+
response: {
140+
200: ajv.compile<void>({
141+
type: 'object',
142+
properties: {
143+
success: {
144+
type: 'boolean',
145+
enum: [true],
146+
description: 'Indicates if the request was successful.',
147+
},
148+
},
149+
required: ['success'],
150+
additionalProperties: false,
151+
}),
152+
400: validateBadRequestErrorResponse,
153+
401: validateUnauthorizedErrorResponse,
154+
},
128155
},
129-
{
130-
async post() {
131-
const { roomId } = this.bodyParams;
132-
133-
if (!roomId) {
134-
return API.v1.failure("The 'roomId' param is required");
135-
}
156+
async function action() {
157+
const { roomId } = this.bodyParams;
136158

137-
const room = await Rooms.findOneById(roomId);
159+
const room = await Rooms.findOneById(roomId);
138160

139-
if (!room) {
140-
throw new MeteorError('error-invalid-room', 'Invalid room', {
141-
method: 'eraseRoom',
142-
});
143-
}
161+
if (!room) {
162+
throw new MeteorError('error-invalid-room', 'Invalid room', {
163+
method: 'eraseRoom',
164+
});
165+
}
144166

145-
if (room.teamMain) {
146-
throw new Meteor.Error('error-cannot-delete-team-channel', 'Cannot delete a team channel', {
147-
method: 'eraseRoom',
148-
});
149-
}
167+
if (room.teamMain) {
168+
throw new Meteor.Error('error-cannot-delete-team-channel', 'Cannot delete a team channel', {
169+
method: 'eraseRoom',
170+
});
171+
}
150172

151-
await eraseRoom(room, this.user);
173+
await eraseRoom(room, this.user);
152174

153-
return API.v1.success();
154-
},
175+
return API.v1.success();
155176
},
156177
);
157178

@@ -1098,7 +1119,9 @@ const roomInviteEndpoints = API.v1.post(
10981119
},
10991120
);
11001121

1101-
type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> & ExtractRoutesFromAPI<typeof roomInviteEndpoints>;
1122+
type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> &
1123+
ExtractRoutesFromAPI<typeof roomInviteEndpoints> &
1124+
ExtractRoutesFromAPI<typeof roomDeleteEndpoint>;
11021125

11031126
declare module '@rocket.chat/rest-typings' {
11041127
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface

packages/rest-typings/src/v1/rooms.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,6 @@ export type RoomsEndpoints = {
825825
};
826826
};
827827

828-
'/v1/rooms.delete': {
829-
POST: (params: { roomId: string }) => void;
830-
};
831-
832828
'/v1/rooms.get': {
833829
GET: (params: { updatedSince: string }) => {
834830
update: IRoom[];

0 commit comments

Comments
 (0)