@@ -19,6 +19,11 @@ import {
1919 isPOSTLivechatRoomCloseByUserParams ,
2020 isPOSTLivechatRoomsCloseAll ,
2121 isPOSTLivechatRoomsCloseAllSuccessResponse ,
22+ POSTLivechatRemoveRoomSuccess ,
23+ isPOSTLivechatRemoveRoomParams ,
24+ validateBadRequestErrorResponse ,
25+ validateUnauthorizedErrorResponse ,
26+ validateForbiddenErrorResponse ,
2227} from '@rocket.chat/rest-typings' ;
2328import { check } from 'meteor/check' ;
2429
@@ -438,32 +443,61 @@ API.v1.addRoute(
438443 } ,
439444) ;
440445
441- const livechatRoomsEndpoints = API . v1 . post (
442- 'livechat/rooms.removeAllClosedRooms' ,
443- {
444- response : {
445- 200 : isPOSTLivechatRoomsCloseAllSuccessResponse ,
446+ const livechatRoomsEndpoints = API . v1
447+ . post (
448+ 'livechat/rooms.delete' ,
449+ {
450+ response : {
451+ 200 : POSTLivechatRemoveRoomSuccess ,
452+ 400 : validateBadRequestErrorResponse ,
453+ 401 : validateUnauthorizedErrorResponse ,
454+ 403 : validateForbiddenErrorResponse ,
455+ } ,
456+ authRequired : true ,
457+ permissionsRequired : [ 'remove-closed-livechat-room' ] ,
458+ body : isPOSTLivechatRemoveRoomParams ,
446459 } ,
447- authRequired : true ,
448- permissionsRequired : [ 'remove-closed-livechat-rooms' ] ,
449- body : isPOSTLivechatRoomsCloseAll ,
450- } ,
451- async function action ( ) {
452- livechatLogger . info ( `User ${ this . userId } is removing all closed rooms` ) ;
460+ async function action ( ) {
461+ const { roomId } = this . bodyParams ;
462+
463+ try {
464+ await removeOmnichannelRoom ( roomId ) ;
465+ return API . v1 . success ( ) ;
466+ } catch ( error : unknown ) {
467+ if ( error instanceof Meteor . Error ) {
468+ return API . v1 . failure ( error . reason ) ;
469+ }
470+
471+ return API . v1 . failure ( 'error-removing-room' ) ;
472+ }
473+ } ,
474+ )
475+ . post (
476+ 'livechat/rooms.removeAllClosedRooms' ,
477+ {
478+ response : {
479+ 200 : isPOSTLivechatRoomsCloseAllSuccessResponse ,
480+ } ,
481+ authRequired : true ,
482+ permissionsRequired : [ 'remove-closed-livechat-rooms' ] ,
483+ body : isPOSTLivechatRoomsCloseAll ,
484+ } ,
485+ async function action ( ) {
486+ livechatLogger . info ( `User ${ this . userId } is removing all closed rooms` ) ;
453487
454- const params = this . bodyParams ;
488+ const params = this . bodyParams ;
455489
456- const extraQuery = await callbacks . run ( 'livechat.applyRoomRestrictions' , { } , { userId : this . userId } ) ;
457- const promises : Promise < void > [ ] = [ ] ;
458- await LivechatRooms . findClosedRooms ( params ?. departmentIds , { } , extraQuery ) . forEach ( ( { _id } : IOmnichannelRoom ) => {
459- promises . push ( removeOmnichannelRoom ( _id ) ) ;
460- } ) ;
461- await Promise . all ( promises ) ;
490+ const extraQuery = await callbacks . run ( 'livechat.applyRoomRestrictions' , { } , { userId : this . userId } ) ;
491+ const promises : Promise < void > [ ] = [ ] ;
492+ await LivechatRooms . findClosedRooms ( params ?. departmentIds , { } , extraQuery ) . forEach ( ( { _id } : IOmnichannelRoom ) => {
493+ promises . push ( removeOmnichannelRoom ( _id ) ) ;
494+ } ) ;
495+ await Promise . all ( promises ) ;
462496
463- livechatLogger . info ( `User ${ this . userId } removed ${ promises . length } closed rooms` ) ;
464- return API . v1 . success ( { removedRooms : promises . length } ) ;
465- } ,
466- ) ;
497+ livechatLogger . info ( `User ${ this . userId } removed ${ promises . length } closed rooms` ) ;
498+ return API . v1 . success ( { removedRooms : promises . length } ) ;
499+ } ,
500+ ) ;
467501
468502type LivechatRoomsEndpoints = ExtractRoutesFromAPI < typeof livechatRoomsEndpoints > ;
469503
0 commit comments