77 ajv ,
88 validateUnauthorizedErrorResponse ,
99 validateBadRequestErrorResponse ,
10- validateForbiddenErrorResponse ,
1110 isDmFileProps ,
1211 isDmMemberProps ,
1312 isDmMessagesProps ,
@@ -31,6 +30,7 @@ import { settings } from '../../../settings/server';
3130import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser' ;
3231import type { ExtractRoutesFromAPI } from '../ApiClass' ;
3332import { API } from '../api' ;
33+ import type { TypedAction } from '../definition' ;
3434import { addUserToFileObj } from '../helpers/addUserToFileObj' ;
3535import { composeRoomWithLastMessage } from '../helpers/composeRoomWithLastMessage' ;
3636import { getPaginationItems } from '../helpers/getPaginationItems' ;
@@ -124,42 +124,45 @@ const isDmDeleteProps = ajv.compile<DmDeleteProps>({
124124 ] ,
125125} ) ;
126126
127- const imEndpoints = API . v1 . post (
128- [ 'dm.delete' , 'im.delete' ] ,
129- {
130- authRequired : true ,
131- body : isDmDeleteProps ,
132- response : {
133- 400 : validateBadRequestErrorResponse ,
134- 401 : validateUnauthorizedErrorResponse ,
135- 200 : ajv . compile < void > ( {
136- type : 'object' ,
137- properties : {
138- success : {
139- type : 'boolean' ,
140- enum : [ true ] ,
141- } ,
127+ const dmDeleteEndpointsProps = {
128+ authRequired : true ,
129+ body : isDmDeleteProps ,
130+ response : {
131+ 400 : validateBadRequestErrorResponse ,
132+ 401 : validateUnauthorizedErrorResponse ,
133+ 200 : ajv . compile < void > ( {
134+ type : 'object' ,
135+ properties : {
136+ success : {
137+ type : 'boolean' ,
138+ enum : [ true ] ,
142139 } ,
143- required : [ 'success' ] ,
144- additionalProperties : false ,
145- } ) ,
146- } ,
140+ } ,
141+ required : [ 'success' ] ,
142+ additionalProperties : false ,
143+ } ) ,
147144 } ,
145+ } as const ;
148146
147+ const dmDeleteAction = < Path extends string > ( _path : Path ) : TypedAction < typeof dmDeleteEndpointsProps , Path > =>
149148 async function action ( ) {
150149 const { room } = await findDirectMessageRoom ( this . bodyParams , this . userId ) ;
151150
152151 const canAccess =
153152 ( await canAccessRoomIdAsync ( room . _id , this . userId ) ) || ( await hasPermissionAsync ( this . userId , 'view-room-administration' ) ) ;
153+
154154 if ( ! canAccess ) {
155155 throw new Meteor . Error ( 'error-not-allowed' , 'Not allowed' ) ;
156156 }
157157
158158 await eraseRoom ( room . _id , this . userId ) ;
159159
160160 return API . v1 . success ( ) ;
161- } ,
162- ) ;
161+ } ;
162+
163+ const dmEndpoints = API . v1
164+ . post ( 'im.delete' , dmDeleteEndpointsProps , dmDeleteAction ( 'im.delete' ) )
165+ . post ( 'dm.delete' , dmDeleteEndpointsProps , dmDeleteAction ( 'dm.delete' ) ) ;
163166
164167API . v1 . addRoute (
165168 [ 'dm.close' , 'im.close' ] ,
@@ -641,9 +644,9 @@ API.v1.addRoute(
641644 } ,
642645) ;
643646
644- export type ImEndpoints = ExtractRoutesFromAPI < typeof imEndpoints > ;
647+ export type DmEndpoints = ExtractRoutesFromAPI < typeof dmEndpoints > ;
645648
646649declare module '@rocket.chat/rest-typings' {
647650 // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
648- interface Endpoints extends ImEndpoints { }
651+ interface Endpoints extends DmEndpoints { }
649652}
0 commit comments