Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: add _id and name options to JSON Schemas #25813

Merged
merged 8 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 32 additions & 38 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 @@ -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 }),
});
},
},
Expand All @@ -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 }),
});
},
},
Expand All @@ -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 }),
});
},
},
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 @@ -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.');
Expand All @@ -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 }),
});
},
},
Expand All @@ -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);

Expand All @@ -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,
Expand All @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@ export type ChannelsGetAllUserMentionsByChannelProps = PaginatedRequest<{ roomId
const channelsGetAllUserMentionsByChannelPropsSchema = {
type: 'object',
properties: {
roomId: { type: 'string' },
offset: { type: 'number' },
count: { type: 'number' },
sort: { type: 'string' },
query: { type: 'string' },
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'],

Expand Down
152 changes: 107 additions & 45 deletions packages/rest-typings/src/v1/channels/ChannelsHistoryProps.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,117 @@
import Ajv from 'ajv';

const ajv = new Ajv({ coerceTypes: true });
import type { PaginatedRequest } from '../../helpers/PaginatedRequest';

export type ChannelsHistoryProps = {
roomId: string;
latest?: string;
showThreadMessages?: 'false' | 'true';
oldest?: string;
unreads?: 'true' | 'false';
inclusive?: 'false' | 'true';
};
const ajv = new Ajv({ coerceTypes: true });

export type ChannelsHistoryProps = PaginatedRequest<
({ roomId: string } | { roomName: string }) & {
latest?: string;
showThreadMessages?: 'false' | 'true';
oldest?: string;
unreads?: 'true' | 'false';
inclusive?: 'false' | 'true';
}
>;
const channelsHistoryPropsSchema = {
type: 'object',
properties: {
roomId: {
type: 'string',
minLength: 1,
},
latest: {
type: 'string',
minLength: 1,
},
showThreadMessages: {
type: 'string',
enum: ['false', 'true'],
},
oldest: {
type: 'string',
minLength: 1,
},
inclusive: {
type: 'string',
enum: ['false', 'true'],
},
unreads: {
type: 'string',
enum: ['true', 'false'],
},
count: {
type: 'number',
},
offset: {
type: 'number',
oneOf: [
{
type: 'object',
properties: {
roomId: {
type: 'string',
minLength: 1,
},
latest: {
type: 'string',
minLength: 1,
nullable: true,
},
showThreadMessages: {
type: 'string',
enum: ['false', 'true'],
nullable: true,
},
oldest: {
type: 'string',
minLength: 1,
nullable: true,
},
inclusive: {
type: 'string',
enum: ['false', 'true'],
nullable: true,
},
unreads: {
type: 'string',
enum: ['true', 'false'],
nullable: true,
},
count: {
type: 'number',
nullable: true,
},
offset: {
type: 'number',
nullable: true,
},
sort: {
type: 'string',
nullable: true,
},
},
required: ['roomId'],
additionalProperties: false,
},
sort: {
type: 'string',
{
type: 'object',
properties: {
roomName: {
type: 'string',
minLength: 1,
},
latest: {
type: 'string',
minLength: 1,
nullable: true,
},
showThreadMessages: {
type: 'string',
enum: ['false', 'true'],
nullable: true,
},
oldest: {
type: 'string',
minLength: 1,
nullable: true,
},
inclusive: {
type: 'string',
enum: ['false', 'true'],
nullable: true,
},
unreads: {
type: 'string',
enum: ['true', 'false'],
nullable: true,
},
count: {
type: 'number',
nullable: true,
},
offset: {
type: 'number',
nullable: true,
},
sort: {
type: 'string',
nullable: true,
},
},
required: ['roomName'],
additionalProperties: false,
},
},
required: ['roomId'],
additionalProperties: false,
],
};

export const isChannelsHistoryProps = ajv.compile<ChannelsHistoryProps>(channelsHistoryPropsSchema);
Loading