Skip to content

Commit 53d19a1

Browse files
refactor: reuse existing withUserIdProps instead of duplicating schema compilation
1 parent 4387f34 commit 53d19a1

File tree

1 file changed

+3
-38
lines changed

1 file changed

+3
-38
lines changed

apps/meteor/app/api/server/v1/groups.ts

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import { getUserFromParams, getUserListFromParams } from '../helpers/getUserFrom
3939
import { ExtractRoutesFromAPI } from '../ApiClass';
4040
import { validateBadRequestErrorResponse } from '@rocket.chat/rest-typings';
4141
import { validateUnauthorizedErrorResponse } from '@rocket.chat/rest-typings';
42+
import { withUserIdProps } from '@rocket.chat/rest-typings/dist/v1/groups/BaseProps';
43+
4244

4345
async function getRoomFromParams(params: { roomId?: string } | { roomName?: string }): Promise<IRoom> {
4446
if (
@@ -897,51 +899,14 @@ API.v1.addRoute(
897899

898900

899901

900-
type GroupsBaseProps = { roomId: string; roomName?: string } | { roomId?: string; roomName: string };
901-
const withGroupBaseProperties = (properties: Record<string, any> = {}, required: string[] = []) => ({
902-
oneOf: [
903-
{
904-
type: 'object',
905-
properties: {
906-
roomId: {
907-
type: 'string',
908-
},
909-
...properties,
910-
},
911-
required: ['roomId'].concat(required),
912-
additionalProperties: false,
913-
},
914-
{
915-
type: 'object',
916-
properties: {
917-
roomName: {
918-
type: 'string',
919-
},
920-
...properties,
921-
},
922-
required: ['roomName'].concat(required),
923-
additionalProperties: false,
924-
},
925-
],
926-
});
927902

928-
type WithUserId = GroupsBaseProps & { userId: string };
929-
const withUserIdSchema = withGroupBaseProperties(
930-
{
931-
userId: {
932-
type: 'string',
933-
},
934-
},
935-
['userId'],
936-
);
937-
export const GroupsRemoveModeratorProps = ajv.compile<WithUserId>(withUserIdSchema);
938903

939904

940905
const groupsEndpoints = API.v1.post(
941906
"groups.removeModerator",
942907
{
943908
authRequired:true,
944-
body: GroupsRemoveModeratorProps,
909+
body: withUserIdProps,
945910
response:{
946911
400:validateBadRequestErrorResponse,
947912
401:validateUnauthorizedErrorResponse,

0 commit comments

Comments
 (0)