@@ -285,30 +285,54 @@ API.v1.addRoute(
285285 } ,
286286) ;
287287
288- API . v1 . addRoute (
289- 'rooms.saveNotification' ,
290- { authRequired : true } ,
291- {
292- async post ( ) {
293- const { roomId, notifications } = this . bodyParams ;
294-
295- if ( ! roomId ) {
296- return API . v1 . failure ( "The 'roomId' param is required" ) ;
297- }
298-
299- if ( ! notifications || Object . keys ( notifications ) . length === 0 ) {
300- return API . v1 . failure ( "The 'notifications' param is required" ) ;
301- }
302-
303- await Promise . all (
304- Object . entries ( notifications as Notifications ) . map ( async ( [ notificationKey , notificationValue ] ) =>
305- saveNotificationSettingsMethod ( this . userId , roomId , notificationKey as NotificationFieldType , notificationValue ) ,
306- ) ,
307- ) ;
308-
309- return API . v1 . success ( ) ;
310- } ,
311- } ,
288+ const saveNotificationBodySchema = ajv . compile < {
289+ roomId : string ;
290+ notifications : Record < string , unknown > ;
291+ } > ( {
292+ type : 'object' ,
293+ properties : {
294+ roomId : { type : 'string' } ,
295+ notifications : {
296+ type : 'object' ,
297+ minProperties : 1 ,
298+ additionalProperties : true ,
299+ } ,
300+ } ,
301+ required : [ 'roomId' , 'notifications' ] ,
302+ additionalProperties : false ,
303+ } ) ;
304+
305+ const saveNotificationResponseSchema = ajv . compile ( {
306+ type : 'object' ,
307+ properties : {
308+ success : { type : 'boolean' , enum : [ true ] } ,
309+ } ,
310+ required : [ 'success' ] ,
311+ additionalProperties : false ,
312+ } ) ;
313+
314+ API . v1 . post (
315+ 'rooms.saveNotification' ,
316+ {
317+ authRequired : true ,
318+ body : saveNotificationBodySchema ,
319+ response : {
320+ 200 : saveNotificationResponseSchema ,
321+ 400 : validateBadRequestErrorResponse ,
322+ 401 : validateUnauthorizedErrorResponse ,
323+ } ,
324+ } ,
325+ async function action ( ) {
326+ const { roomId, notifications } = this . bodyParams ;
327+
328+ await Promise . all (
329+ Object . entries ( notifications as Notifications ) . map ( async ( [ notificationKey , notificationValue ] ) =>
330+ saveNotificationSettingsMethod ( this . userId , roomId , notificationKey as NotificationFieldType , notificationValue ) ,
331+ ) ,
332+ ) ;
333+
334+ return API . v1 . success ( ) ;
335+ } ,
312336) ;
313337
314338API . v1 . addRoute (
0 commit comments