@@ -120,61 +120,6 @@ API.v1.addRoute(
120120 } ,
121121) ;
122122
123- const roomDeleteEndpoint = API . v1 . post (
124- 'rooms.delete' ,
125- {
126- authRequired : true ,
127- body : ajv . compile < { roomId : string } > ( {
128- type : 'object' ,
129- properties : {
130- roomId : {
131- type : 'string' ,
132- description : 'The ID of the room to delete.' ,
133- } ,
134- } ,
135- required : [ 'roomId' ] ,
136- additionalProperties : false ,
137- } ) ,
138- response : {
139- 200 : ajv . compile < void > ( {
140- type : 'object' ,
141- properties : {
142- success : {
143- type : 'boolean' ,
144- enum : [ true ] ,
145- description : 'Indicates if the request was successful.' ,
146- } ,
147- } ,
148- required : [ 'success' ] ,
149- additionalProperties : false ,
150- } ) ,
151- 400 : validateBadRequestErrorResponse ,
152- 401 : validateUnauthorizedErrorResponse ,
153- } ,
154- } ,
155- async function action ( ) {
156- const { roomId } = this . bodyParams ;
157-
158- const room = await Rooms . findOneById ( roomId ) ;
159-
160- if ( ! room ) {
161- throw new MeteorError ( 'error-invalid-room' , 'Invalid room' , {
162- method : 'eraseRoom' ,
163- } ) ;
164- }
165-
166- if ( room . teamMain ) {
167- throw new Meteor . Error ( 'error-cannot-delete-team-channel' , 'Cannot delete a team channel' , {
168- method : 'eraseRoom' ,
169- } ) ;
170- }
171-
172- await eraseRoom ( room , this . user ) ;
173-
174- return API . v1 . success ( ) ;
175- } ,
176- ) ;
177-
178123API . v1 . addRoute (
179124 'rooms.get' ,
180125 { authRequired : true } ,
@@ -305,56 +250,6 @@ API.v1.addRoute(
305250 } ,
306251) ;
307252
308- const saveNotificationBodySchema = ajv . compile < {
309- roomId : string ;
310- notifications : Record < string , string > ;
311- } > ( {
312- type : 'object' ,
313- properties : {
314- roomId : { type : 'string' , minLength : 1 } ,
315- notifications : {
316- type : 'object' ,
317- minProperties : 1 ,
318- additionalProperties : { type : 'string' } ,
319- } ,
320- } ,
321- required : [ 'roomId' , 'notifications' ] ,
322- additionalProperties : false ,
323- } ) ;
324-
325- const saveNotificationResponseSchema = ajv . compile ( {
326- type : 'object' ,
327- properties : {
328- success : { type : 'boolean' , enum : [ true ] } ,
329- } ,
330- required : [ 'success' ] ,
331- additionalProperties : false ,
332- } ) ;
333-
334- const roomsSaveNotificationEndpoint = API . v1 . post (
335- 'rooms.saveNotification' ,
336- {
337- authRequired : true ,
338- body : saveNotificationBodySchema ,
339- response : {
340- 200 : saveNotificationResponseSchema ,
341- 400 : validateBadRequestErrorResponse ,
342- 401 : validateUnauthorizedErrorResponse ,
343- } ,
344- } ,
345- async function action ( ) {
346- const { roomId, notifications } = this . bodyParams ;
347-
348- await Promise . all (
349- Object . entries ( notifications as Notifications ) . map ( async ( [ notificationKey , notificationValue ] ) =>
350- saveNotificationSettingsMethod ( this . userId , roomId , notificationKey as NotificationFieldType , notificationValue ) ,
351- ) ,
352- ) ;
353-
354- return API . v1 . success ( { success : true } ) ;
355- } ,
356- ) ;
357-
358253API . v1 . addRoute (
359254 'rooms.cleanHistory' ,
360255 { authRequired : true , validateParams : isRoomsCleanHistoryProps } ,
@@ -1028,6 +923,36 @@ const RoomsMuteUnmuteUserSchema = {
1028923
1029924const isRoomsMuteUnmuteUserProps = ajv . compile < RoomsMuteUnmuteUser > ( RoomsMuteUnmuteUserSchema ) ;
1030925
926+ type SaveNotificationBody = {
927+ roomId : string ;
928+ notifications : Record < string , string > ;
929+ } ;
930+
931+ const saveNotificationBodySchema = {
932+ type : 'object' ,
933+ properties : {
934+ roomId : { type : 'string' , minLength : 1 } ,
935+ notifications : {
936+ type : 'object' ,
937+ minProperties : 1 ,
938+ additionalProperties : { type : 'string' } ,
939+ } ,
940+ } ,
941+ required : [ 'roomId' , 'notifications' ] ,
942+ additionalProperties : false ,
943+ } ;
944+
945+ const isSaveNotificationBodyProps = ajv . compile < SaveNotificationBody > ( saveNotificationBodySchema ) ;
946+
947+ const saveNotificationResponseSchema = ajv . compile ( {
948+ type : 'object' ,
949+ properties : {
950+ success : { type : 'boolean' , enum : [ true ] } ,
951+ } ,
952+ required : [ 'success' ] ,
953+ additionalProperties : false ,
954+ } ) ;
955+
1031956export const roomEndpoints = API . v1
1032957 . get (
1033958 'rooms.roles' ,
@@ -1171,6 +1096,29 @@ export const roomEndpoints = API.v1
11711096 }
11721097 } ,
11731098 )
1099+ . post (
1100+ 'rooms.saveNotification' ,
1101+ {
1102+ authRequired : true ,
1103+ body : isSaveNotificationBodyProps ,
1104+ response : {
1105+ 200 : saveNotificationResponseSchema ,
1106+ 400 : validateBadRequestErrorResponse ,
1107+ 401 : validateUnauthorizedErrorResponse ,
1108+ } ,
1109+ } ,
1110+ async function action ( ) {
1111+ const { roomId, notifications } = this . bodyParams ;
1112+
1113+ await Promise . all (
1114+ Object . entries ( notifications as Notifications ) . map ( async ( [ notificationKey , notificationValue ] ) =>
1115+ saveNotificationSettingsMethod ( this . userId , roomId , notificationKey as NotificationFieldType , notificationValue ) ,
1116+ ) ,
1117+ ) ;
1118+
1119+ return API . v1 . success ( { success : true } ) ;
1120+ } ,
1121+ )
11741122 . post (
11751123 'rooms.favorite' ,
11761124 {
@@ -1203,6 +1151,60 @@ export const roomEndpoints = API.v1
12031151 return API . v1 . success ( ) ;
12041152 } ,
12051153 )
1154+ . post (
1155+ 'rooms.delete' ,
1156+ {
1157+ authRequired : true ,
1158+ body : ajv . compile < { roomId : string } > ( {
1159+ type : 'object' ,
1160+ properties : {
1161+ roomId : {
1162+ type : 'string' ,
1163+ description : 'The ID of the room to delete.' ,
1164+ } ,
1165+ } ,
1166+ required : [ 'roomId' ] ,
1167+ additionalProperties : false ,
1168+ } ) ,
1169+ response : {
1170+ 200 : ajv . compile < void > ( {
1171+ type : 'object' ,
1172+ properties : {
1173+ success : {
1174+ type : 'boolean' ,
1175+ enum : [ true ] ,
1176+ description : 'Indicates if the request was successful.' ,
1177+ } ,
1178+ } ,
1179+ required : [ 'success' ] ,
1180+ additionalProperties : false ,
1181+ } ) ,
1182+ 400 : validateBadRequestErrorResponse ,
1183+ 401 : validateUnauthorizedErrorResponse ,
1184+ } ,
1185+ } ,
1186+ async function action ( ) {
1187+ const { roomId } = this . bodyParams ;
1188+
1189+ const room = await Rooms . findOneById ( roomId ) ;
1190+
1191+ if ( ! room ) {
1192+ throw new MeteorError ( 'error-invalid-room' , 'Invalid room' , {
1193+ method : 'eraseRoom' ,
1194+ } ) ;
1195+ }
1196+
1197+ if ( room . teamMain ) {
1198+ throw new Meteor . Error ( 'error-cannot-delete-team-channel' , 'Cannot delete a team channel' , {
1199+ method : 'eraseRoom' ,
1200+ } ) ;
1201+ }
1202+
1203+ await eraseRoom ( room , this . user ) ;
1204+
1205+ return API . v1 . success ( ) ;
1206+ } ,
1207+ )
12061208 . post (
12071209 'rooms.leave' ,
12081210 {
@@ -1296,10 +1298,7 @@ export const roomEndpoints = API.v1
12961298 } ,
12971299 ) ;
12981300
1299- type RoomEndpoints = ExtractRoutesFromAPI < typeof roomEndpoints > &
1300- ExtractRoutesFromAPI < typeof roomEndpoints > &
1301- ExtractRoutesFromAPI < typeof roomDeleteEndpoint > &
1302- ExtractRoutesFromAPI < typeof roomsSaveNotificationEndpoint > ;
1301+ type RoomEndpoints = ExtractRoutesFromAPI < typeof roomEndpoints > ;
13031302
13041303declare module '@rocket.chat/rest-typings' {
13051304 // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
0 commit comments