Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Jun 13, 2022
1 parent 97dd07f commit 7d7a7b5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 97 deletions.
46 changes: 21 additions & 25 deletions apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down Expand Up @@ -297,10 +297,10 @@ API.v1.addRoute(
},
{
post() {
const { roomId } = this.bodyParams;
const { ...params } = this.bodyParams;

const findResult = findChannelByIdOrName({
params: { roomId },
params,
checkedArchived: false,
});

Expand Down Expand Up @@ -354,9 +354,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);

Expand All @@ -379,23 +379,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,
Expand All @@ -415,9 +411,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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelsGetAllUserMentionsByChannelProps>(
Expand Down
34 changes: 17 additions & 17 deletions packages/rest-typings/src/v1/channels/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] }
Expand Down Expand Up @@ -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;
Expand All @@ -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': {
Expand All @@ -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;
};
Expand All @@ -156,7 +156,7 @@ export type ChannelsEndpoints = {
mentions: IUser[];
}>;
};
'channels.moderators': {
'/v1/channels.moderators': {
GET: (params: { roomId: string } | { roomName: string }) => { moderators: Pick<IUser, '_id' | 'name' | 'username'>[] };
};
};

0 comments on commit 7d7a7b5

Please sign in to comment.