diff --git a/apps/meteor/app/api/server/v1/channels.ts b/apps/meteor/app/api/server/v1/channels.ts index e1ab4da8e8d9..484c2a077081 100644 --- a/apps/meteor/app/api/server/v1/channels.ts +++ b/apps/meteor/app/api/server/v1/channels.ts @@ -129,9 +129,9 @@ API.v1.addRoute( }, { get() { - const { roomId, unreads, oldest, latest, showThreadMessages, inclusive } = this.queryParams; + const { unreads, oldest, latest, showThreadMessages, inclusive, ...params } = this.queryParams; const findResult = findChannelByIdOrName({ - params: { roomId }, + params, checkedArchived: false, }); @@ -184,13 +184,13 @@ API.v1.addRoute( }, { post() { - const { roomId, joinCode } = this.bodyParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const { joinCode, ...params } = this.bodyParams; + const findResult = findChannelByIdOrName({ params }); Meteor.call('joinRoom', findResult._id, joinCode); return API.v1.success({ - channel: findChannelByIdOrName({ params: { roomId }, userId: this.userId }), + channel: findChannelByIdOrName({ params, userId: this.userId }), }); }, }, @@ -204,15 +204,15 @@ API.v1.addRoute( }, { post() { - const { roomId /* userId */ } = this.bodyParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const { ...params /* userId */ } = this.bodyParams; + const findResult = findChannelByIdOrName({ params }); const user = this.getUserFromParams(); Meteor.call('removeUserFromRoom', { rid: findResult._id, username: user.username }); return API.v1.success({ - channel: findChannelByIdOrName({ params: { roomId }, userId: this.userId }), + channel: findChannelByIdOrName({ params, userId: this.userId }), }); }, }, @@ -226,15 +226,15 @@ API.v1.addRoute( }, { post() { - const { roomId } = this.bodyParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const { ...params } = this.bodyParams; + const findResult = findChannelByIdOrName({ params }); Meteor.runAsUser(this.userId, () => { Meteor.call('leaveRoom', findResult._id); }); return API.v1.success({ - channel: findChannelByIdOrName({ params: { roomId }, userId: this.userId }), + channel: findChannelByIdOrName({ params, userId: this.userId }), }); }, }, @@ -297,10 +297,10 @@ API.v1.addRoute( }, { post() { - const { roomId } = this.bodyParams; + const { ...params } = this.bodyParams; const findResult = findChannelByIdOrName({ - params: { roomId }, + params, checkedArchived: false, }); @@ -329,9 +329,7 @@ API.v1.addRoute( }, { post() { - const { roomId } = this.bodyParams; - - const findResult = findChannelByIdOrName({ params: { roomId } }); + const findResult = findChannelByIdOrName({ params: this.bodyParams }); if (findResult.ro === this.bodyParams.readOnly) { return API.v1.failure('The channel read only setting is the same as what it would be changed to.'); @@ -340,7 +338,7 @@ API.v1.addRoute( Meteor.call('saveRoomSettings', findResult._id, 'readOnly', this.bodyParams.readOnly); return API.v1.success({ - channel: findChannelByIdOrName({ params: { roomId }, userId: this.userId }), + channel: findChannelByIdOrName({ params: this.bodyParams, userId: this.userId }), }); }, }, @@ -354,9 +352,9 @@ API.v1.addRoute( }, { post() { - const { roomId, announcement } = this.bodyParams; + const { announcement, ...params } = this.bodyParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const findResult = findChannelByIdOrName({ params }); Meteor.call('saveRoomSettings', findResult._id, 'roomAnnouncement', announcement); @@ -379,23 +377,19 @@ API.v1.addRoute( const { offset, count } = this.getPaginationItems(); const { sort } = this.parseJsonQuery(); - const mentions = Meteor.runAsUser(this.userId, () => - Meteor.call('getUserMentionsByChannel', { - roomId, - options: { - sort: sort || { ts: 1 }, - skip: offset, - limit: count, - }, - }), - ); - - const allMentions = Meteor.runAsUser(this.userId, () => - Meteor.call('getUserMentionsByChannel', { - roomId, - options: {}, - }), - ); + const mentions = Meteor.call('getUserMentionsByChannel', { + roomId, + options: { + sort: sort || { ts: 1 }, + skip: offset, + limit: count, + }, + }); + + const allMentions = Meteor.call('getUserMentionsByChannel', { + roomId, + options: {}, + }); return API.v1.success({ mentions, @@ -415,9 +409,9 @@ API.v1.addRoute( }, { get() { - const { roomId } = this.queryParams; + const { ...params } = this.queryParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const findResult = findChannelByIdOrName({ params }); const moderators = Subscriptions.findByRoomIdAndRoles(findResult._id, ['moderator'], { fields: { u: 1 }, diff --git a/packages/rest-typings/src/v1/channels/ChannelsGetAllUserMentionsByChannelProps.ts b/packages/rest-typings/src/v1/channels/ChannelsGetAllUserMentionsByChannelProps.ts index 32f1eea0d646..b022674974d5 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsGetAllUserMentionsByChannelProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsGetAllUserMentionsByChannelProps.ts @@ -4,65 +4,34 @@ import type { PaginatedRequest } from '../../helpers/PaginatedRequest'; const ajv = new Ajv({ coerceTypes: true }); -export type ChannelsGetAllUserMentionsByChannelProps = PaginatedRequest<{ roomId: string } | { roomName: string }>; +export type ChannelsGetAllUserMentionsByChannelProps = PaginatedRequest<{ roomId: string }>; const channelsGetAllUserMentionsByChannelPropsSchema = { - oneOf: [ - { - type: 'object', - properties: { - roomId: { - type: 'string', - }, - offset: { - type: 'number', - nullable: true, - }, - count: { - type: 'number', - nullable: true, - }, - sort: { - type: 'string', - nullable: true, - }, - query: { - type: 'string', - nullable: true, - }, - }, - required: ['roomId'], - - additionalProperties: false, + type: 'object', + properties: { + roomId: { + type: 'string', }, - { - type: 'object', - properties: { - roomName: { - type: 'string', - }, - offset: { - type: 'number', - nullable: true, - }, - count: { - type: 'number', - nullable: true, - }, - sort: { - type: 'string', - nullable: true, - }, - query: { - type: 'string', - nullable: true, - }, - }, - required: ['roomName'], - - additionalProperties: false, + offset: { + type: 'number', + nullable: true, + }, + count: { + type: 'number', + nullable: true, }, - ], + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['roomId'], + + additionalProperties: false, }; export const isChannelsGetAllUserMentionsByChannelProps = ajv.compile( diff --git a/packages/rest-typings/src/v1/channels/channels.ts b/packages/rest-typings/src/v1/channels/channels.ts index 9d87f7a5f899..12c85a1c597d 100644 --- a/packages/rest-typings/src/v1/channels/channels.ts +++ b/packages/rest-typings/src/v1/channels/channels.ts @@ -12,12 +12,12 @@ import type { ChannelsSetAnnouncementProps } from './ChannelsSetAnnouncementProp import type { ChannelsUnarchiveProps } from './ChannelsUnarchiveProps'; export type ChannelsEndpoints = { - 'channels.files': { + '/v1/channels.files': { GET: (params: PaginatedRequest<{ roomId: string } | { roomName: string }>) => PaginatedResult<{ files: IUpload[]; }>; }; - 'channels.members': { + '/v1/channels.members': { GET: ( params: PaginatedRequest< { roomId: string; filter?: string; status?: string[] } | { roomName: string; filter?: string; status?: string[] } @@ -73,10 +73,10 @@ export type ChannelsEndpoints = { team: ITeam; }; }; - 'channels.info': { + '/v1/channels.info': { GET: (params: { roomId: string } | { roomName: string }) => { channel: IRoom }; }; - 'channels.counters': { + '/v1/channels.counters': { GET: (params: { roomId: string } | { roomName: string }) => { joined: boolean; members: number; @@ -87,42 +87,42 @@ export type ChannelsEndpoints = { userMentions: number; }; }; - 'channels.join': { + '/v1/channels.join': { POST: (params: { roomId: string; joinCode?: string } | { roomName: string; joinCode?: string }) => { channel: IRoom; }; }; - 'channels.close': { + '/v1/channels.close': { POST: (params: { roomId: string } | { roomName: string }) => {}; }; - 'channels.kick': { + '/v1/channels.kick': { POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; '/v1/channels.delete': { POST: (params: ChannelsDeleteProps) => void; }; - 'channels.leave': { + '/v1/channels.leave': { POST: (params: { roomId: string } | { roomName: string }) => {}; }; - 'channels.addModerator': { + '/v1/channels.addModerator': { POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; - 'channels.removeModerator': { + '/v1/channels.removeModerator': { POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; - 'channels.addOwner': { + '/v1/channels.addOwner': { POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; - 'channels.removeOwner': { + '/v1/channels.removeOwner': { POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; - 'channels.addLeader': { + '/v1/channels.addLeader': { POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; - 'channels.removeLeader': { + '/v1/channels.removeLeader': { POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; - 'channels.roles': { + '/v1/channels.roles': { GET: (params: { roomId: string } | { roomName: string }) => { roles: IGetRoomRoles[] }; }; '/v1/channels.messages': { @@ -133,7 +133,7 @@ export type ChannelsEndpoints = { '/v1/channels.open': { POST: (params: ChannelsOpenProps) => void; }; - 'channels.setReadOnly': { + '/v1/channels.setReadOnly': { POST: (params: { roomId: string; readOnly: boolean } | { roomName: string; readOnly: boolean }) => { channel: IRoom; }; @@ -156,7 +156,7 @@ export type ChannelsEndpoints = { mentions: IUser[]; }>; }; - 'channels.moderators': { + '/v1/channels.moderators': { GET: (params: { roomId: string } | { roomName: string }) => { moderators: Pick[] }; }; };