Skip to content

Commit 2c23512

Browse files
authored
chore: migrate rooms.saveNotification endpoint to new API format w… (#38893)
1 parent 7367e3b commit 2c23512

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

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

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,29 +306,53 @@ API.v1.addRoute(
306306
},
307307
);
308308

309-
API.v1.addRoute(
310-
'rooms.saveNotification',
311-
{ authRequired: true },
312-
{
313-
async post() {
314-
const { roomId, notifications } = this.bodyParams;
309+
const saveNotificationBodySchema = ajv.compile<{
310+
roomId: string;
311+
notifications: Record<string, string>;
312+
}>({
313+
type: 'object',
314+
properties: {
315+
roomId: { type: 'string', minLength: 1 },
316+
notifications: {
317+
type: 'object',
318+
minProperties: 1,
319+
additionalProperties: { type: 'string' },
320+
},
321+
},
322+
required: ['roomId', 'notifications'],
323+
additionalProperties: false,
324+
});
315325

316-
if (!roomId) {
317-
return API.v1.failure("The 'roomId' param is required");
318-
}
326+
const saveNotificationResponseSchema = ajv.compile({
327+
type: 'object',
328+
properties: {
329+
success: { type: 'boolean', enum: [true] },
330+
},
331+
required: ['success'],
332+
additionalProperties: false,
333+
});
319334

320-
if (!notifications || Object.keys(notifications).length === 0) {
321-
return API.v1.failure("The 'notifications' param is required");
322-
}
335+
const roomsSaveNotificationEndpoint = API.v1.post(
336+
'rooms.saveNotification',
337+
{
338+
authRequired: true,
339+
body: saveNotificationBodySchema,
340+
response: {
341+
200: saveNotificationResponseSchema,
342+
400: validateBadRequestErrorResponse,
343+
401: validateUnauthorizedErrorResponse,
344+
},
345+
},
346+
async function action() {
347+
const { roomId, notifications } = this.bodyParams;
323348

324-
await Promise.all(
325-
Object.entries(notifications as Notifications).map(async ([notificationKey, notificationValue]) =>
326-
saveNotificationSettingsMethod(this.userId, roomId, notificationKey as NotificationFieldType, notificationValue),
327-
),
328-
);
349+
await Promise.all(
350+
Object.entries(notifications as Notifications).map(async ([notificationKey, notificationValue]) =>
351+
saveNotificationSettingsMethod(this.userId, roomId, notificationKey as NotificationFieldType, notificationValue),
352+
),
353+
);
329354

330-
return API.v1.success();
331-
},
355+
return API.v1.success({ success: true });
332356
},
333357
);
334358

@@ -1213,7 +1237,8 @@ export const roomEndpoints = API.v1
12131237

12141238
type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> &
12151239
ExtractRoutesFromAPI<typeof roomEndpoints> &
1216-
ExtractRoutesFromAPI<typeof roomDeleteEndpoint>;
1240+
ExtractRoutesFromAPI<typeof roomDeleteEndpoint> &
1241+
ExtractRoutesFromAPI<typeof roomsSaveNotificationEndpoint>;
12171242

12181243
declare module '@rocket.chat/rest-typings' {
12191244
// 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
@@ -800,10 +800,6 @@ export type RoomsEndpoints = {
800800
}) => { message: IMessage | null };
801801
};
802802

803-
'/v1/rooms.saveNotification': {
804-
POST: (params: { roomId: string; notifications: Notifications }) => void;
805-
};
806-
807803
'/v1/rooms.nameExists': {
808804
GET: (params: { roomName: string }) => {
809805
exists: boolean;

0 commit comments

Comments
 (0)