@@ -15,10 +15,9 @@ import {
1515 isRoomsChangeArchivationStateProps ,
1616 isRoomsHideProps ,
1717} from '@rocket.chat/rest-typings' ;
18- import Ajv from 'ajv ' ;
18+ import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv ' ;
1919import { Meteor } from 'meteor/meteor' ;
2020
21-
2221import { isTruthy } from '../../../../lib/isTruthy' ;
2322import { omit } from '../../../../lib/utils/omit' ;
2423import * as dataExport from '../../../../server/lib/dataExport' ;
@@ -374,23 +373,78 @@ API.v1.addRoute(
374373 } ,
375374) ;
376375
377- API . v1 . addRoute (
376+ API . v1 . post (
378377 'rooms.favorite' ,
379- { authRequired : true } ,
380378 {
381- async post ( ) {
382- const { favorite } = this . bodyParams ;
379+ authRequired : true ,
380+ body : ajv . compile < {
381+ favorite : boolean ;
382+ roomId ?: string ;
383+ roomName ?: string ;
384+ } > ( {
385+ type : 'object' ,
386+ properties : {
387+ favorite : { type : 'boolean' } ,
388+ roomId : { type : 'string' } ,
389+ roomName : { type : 'string' } ,
390+ } ,
391+ required : [ 'favorite' ] ,
392+ additionalProperties : false ,
393+ } ) ,
394+ response : {
395+ 200 : ajv . compile ( {
396+ type : 'object' ,
397+ properties : {
398+ success : {
399+ type : 'boolean' ,
400+ description : 'Indicates if the request was successful.' ,
401+ } ,
402+ } ,
403+ required : [ 'success' ] ,
404+ additionalProperties : false ,
405+ } ) ,
406+ 400 : ajv . compile ( {
407+ type : 'object' ,
408+ properties : {
409+ error : { type : 'string' } ,
410+ errorType : { type : 'string' } ,
411+ success : {
412+ type : 'boolean' ,
413+ enum : [ 'false' ] ,
414+ description : 'Indicates if the request was successful.' ,
415+ } ,
416+ } ,
417+ required : [ 'error' , 'errorType' , 'success' ] ,
418+ additionalProperties : false ,
419+ } ) ,
420+ 401 : ajv . compile ( {
421+ type : 'object' ,
422+ properties : {
423+ status : { type : 'string' } ,
424+ message : { type : 'string' } ,
425+ success : {
426+ type : 'boolean' ,
427+ enum : [ 'false' ] ,
428+ description : 'Indicates if the request was successful.' ,
429+ } ,
430+ } ,
431+ required : [ 'message' , 'status' , 'success' ] ,
432+ additionalProperties : false ,
433+ } ) ,
434+ } ,
435+ } ,
436+ async function ( ) {
437+ const { favorite } = this . bodyParams ;
383438
384- if ( ! this . bodyParams . hasOwnProperty ( 'favorite' ) ) {
385- return API . v1 . failure ( "The 'favorite' param is required" ) ;
386- }
439+ if ( ! this . bodyParams . hasOwnProperty ( 'favorite' ) ) {
440+ return API . v1 . failure ( "The 'favorite' param is required" ) ;
441+ }
387442
388- const room = await findRoomByIdOrName ( { params : this . bodyParams } ) ;
443+ const room = await findRoomByIdOrName ( { params : this . bodyParams } ) ;
389444
390- await toggleFavoriteMethod ( this . userId , room . _id , favorite ) ;
445+ await toggleFavoriteMethod ( this . userId , room . _id , favorite ) ;
391446
392- return API . v1 . success ( ) ;
393- } ,
447+ return API . v1 . success ( ) ;
394448 } ,
395449) ;
396450
0 commit comments