Skip to content
Closed
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
89 changes: 60 additions & 29 deletions apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ export async function findRoomByIdOrName({
checkedArchived = true,
}: {
params:
| {
roomId?: string;
}
| {
roomName?: string;
};
| {
roomId?: string;
}
| {
roomName?: string;
};
checkedArchived?: boolean;
}): Promise<IRoom> {
if (
Expand Down Expand Up @@ -110,21 +110,51 @@ export async function findRoomByIdOrName({
return room;
}

API.v1.addRoute(
'rooms.nameExists',
const roomNameExistsEndpoint = API.v1.get('rooms.nameExists',
{
authRequired: true,
validateParams: isGETRoomsNameExists,
},
{
async get() {
const { roomName } = this.queryParams;

const room = await Rooms.findOneByName(roomName, { projection: { _id: 1 } });

return API.v1.success({ exists: !!room });
//required query validation using ajv
query: ajv.compile<{ roomName: string }>({
type: 'object',
properties: {
roomName: {
type: 'string',
description: 'The name of the room to check',
},
},
required: ['roomName'],
additionalProperties: false,
}),
//response validation
response: {
200: ajv.compile<{
exists: boolean,
success: true
}>({
type: 'object',
properties: {
exists: {
type: 'boolean',
},
success: {
type: 'boolean',
enum: [true],
},
},
required: ['exists', 'success'],
additionalProperties: false
}),
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse
},
},
async function action() {
const { roomName } = this.queryParams;
const room = await Rooms.findOneByName(roomName, {
projection: { _id: 1 },
});
return API.v1.success({ exists: !!room });
}
);

const roomDeleteEndpoint = API.v1.post(
Expand Down Expand Up @@ -970,21 +1000,21 @@ API.v1.addRoute(

type RoomsFavorite =
| {
roomId: string;
favorite: boolean;
}
roomId: string;
favorite: boolean;
}
| {
roomName: string;
favorite: boolean;
};
roomName: string;
favorite: boolean;
};

type RoomsLeave =
| {
roomId: string;
}
roomId: string;
}
| {
roomName: string;
};
roomName: string;
};

const isRoomGetRolesPropsSchema = {
type: 'object',
Expand Down Expand Up @@ -1377,9 +1407,10 @@ export const roomEndpoints = API.v1
);
type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> &
ExtractRoutesFromAPI<typeof roomDeleteEndpoint> &
ExtractRoutesFromAPI<typeof roomsSaveNotificationEndpoint>;
ExtractRoutesFromAPI<typeof roomsSaveNotificationEndpoint> &
ExtractRoutesFromAPI<typeof roomNameExistsEndpoint>;

declare module '@rocket.chat/rest-typings' {
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
interface Endpoints extends RoomEndpoints {}
interface Endpoints extends RoomEndpoints { }
}
6 changes: 0 additions & 6 deletions packages/rest-typings/src/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,12 +915,6 @@ export type RoomsEndpoints = {
};
};

'/v1/rooms.nameExists': {
GET: (params: { roomName: string }) => {
exists: boolean;
};
};

'/v1/rooms.get': {
GET: (params: { updatedSince: string }) => {
update: IRoom[];
Expand Down