@@ -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
12141238type RoomEndpoints = ExtractRoutesFromAPI < typeof roomEndpoints > &
12151239 ExtractRoutesFromAPI < typeof roomEndpoints > &
1216- ExtractRoutesFromAPI < typeof roomDeleteEndpoint > ;
1240+ ExtractRoutesFromAPI < typeof roomDeleteEndpoint > &
1241+ ExtractRoutesFromAPI < typeof roomsSaveNotificationEndpoint > ;
12171242
12181243declare module '@rocket.chat/rest-typings' {
12191244 // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
0 commit comments