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: convert invites, misc and subscriptions to TS and create definitions #25350

Merged
merged 36 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8c8b3d2
chore: convert invites, misc and subscriptions to TS and create defin…
felipe-rod123 Apr 30, 2022
4a3de19
Merge remote-tracking branch 'origin/develop' into chore/convert-ts-a…
ggazzo May 17, 2022
0eb60a3
..
ggazzo May 17, 2022
0ce3efb
fix lint
felipe-rod123 May 18, 2022
49c2558
fix lint
felipe-rod123 May 18, 2022
01c258e
lint
ggazzo May 21, 2022
89017c8
fix ts
ggazzo May 24, 2022
0529517
improve typings
ggazzo May 24, 2022
bc0bf0c
Merge remote-tracking branch 'origin/develop' into chore/convert-ts-a…
ggazzo May 25, 2022
ee0a20f
finish pull request
ggazzo May 25, 2022
63153f2
CI
ggazzo May 30, 2022
6e4ee16
Fix Ci
ggazzo May 30, 2022
0589cf7
add JSON Schema to misc.ts and fix subscriptions.ts
felipe-rod123 May 30, 2022
da05e81
fix subscriptions and invites validateParams
felipe-rod123 Jun 1, 2022
2171160
Fix Review
ggazzo Jun 1, 2022
74661e2
move json schemas to rest-typings
felipe-rod123 Jun 1, 2022
69b78b2
fix: remove _deletedAt option
felipe-rod123 Jun 3, 2022
c65b728
Merge branch 'develop' into chore/convert-ts-and-create-endpoints
felipe-rod123 Jun 4, 2022
4792783
..
ggazzo Jun 6, 2022
7f49b76
..
ggazzo Jun 6, 2022
3766455
..
ggazzo Jun 6, 2022
79b59c0
fix /directory
ggazzo Jun 6, 2022
a0a40c5
fix spotlight
ggazzo Jun 6, 2022
a730908
Fix svg
ggazzo Jun 6, 2022
f95beb4
..
ggazzo Jun 6, 2022
8fc115f
..
ggazzo Jun 6, 2022
f90f872
..
ggazzo Jun 7, 2022
29da686
..
ggazzo Jun 7, 2022
2265954
..
ggazzo Jun 7, 2022
bb350be
fix meteor call
ggazzo Jun 7, 2022
e2207ec
fiz subscriptions
ggazzo Jun 7, 2022
3482cbe
Merge remote-tracking branch 'origin/develop' into chore/convert-ts-a…
ggazzo Jun 7, 2022
8e94144
fix useInviteToken
ggazzo Jun 7, 2022
0fd5f70
..
ggazzo Jun 7, 2022
a894feb
Update packages/rest-typings/src/index.ts
ggazzo Jun 7, 2022
c0e2d56
Apply suggestions from code review
ggazzo Jun 7, 2022
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
16 changes: 15 additions & 1 deletion apps/meteor/app/api/server/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type PartialThis = {
};

type ActionThis<TMethod extends Method, TPathPattern extends PathPattern, TOptions> = {
readonly requestIp: string;
urlParams: UrlParams<TPathPattern>;
// TODO make it unsafe
readonly queryParams: TMethod extends 'GET'
Expand Down Expand Up @@ -110,16 +111,29 @@ type ActionThis<TMethod extends Method, TPathPattern extends PathPattern, TOptio
};
/* @deprecated */
getUserFromParams(): IUser;
/* @deprecated */
getUserInfo(me: IUser): TOptions extends { authRequired: true }
? IUser & {
email?: string;
settings: {
profile: {};
preferences: unknown;
};
avatarUrl: string;
}
: undefined;
insertUserObject<T>({ object, userId }: { object: { [key: string]: unknown }; userId: string }): { [key: string]: unknown } & T;
composeRoomWithLastMessage(room: IRoom, userId: string): IRoom;
} & (TOptions extends { authRequired: true }
? {
readonly user: IUser;
readonly userId: string;
readonly token: string;
}
: {
readonly user: null;
readonly userId: null;
readonly userId: undefined;
readonly token?: string;
});

export type ResultFor<TMethod extends Method, TPathPattern extends PathPattern> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint-disable react-hooks/rules-of-hooks */
import { IInvite } from '@rocket.chat/core-typings';
import { isFindOrCreateInviteParams, isUseInviteTokenProps, isValidateInviteTokenProps } from '@rocket.chat/rest-typings';

import { API } from '../api';
import { findOrCreateInvite } from '../../../invites/server/functions/findOrCreateInvite';
import { removeInvite } from '../../../invites/server/functions/removeInvite';
Expand All @@ -7,24 +11,28 @@ import { validateInviteToken } from '../../../invites/server/functions/validateI

API.v1.addRoute(
'listInvites',
{ authRequired: true },
{
get() {
const result = Promise.await(listInvites(this.userId));
authRequired: true,
},
{
async get() {
const result = await listInvites(this.userId);
return API.v1.success(result);
},
},
);

API.v1.addRoute(
'findOrCreateInvite',
{ authRequired: true },
{
post() {
authRequired: true,
validateParams: isFindOrCreateInviteParams,
},
{
async post() {
const { rid, days, maxUses } = this.bodyParams;
const result = Promise.await(findOrCreateInvite(this.userId, { rid, days, maxUses }));

return API.v1.success(result);
return API.v1.success((await findOrCreateInvite(this.userId, { rid, days, maxUses })) as IInvite);
},
},
);
Expand All @@ -33,44 +41,44 @@ API.v1.addRoute(
'removeInvite/:_id',
{ authRequired: true },
{
delete() {
async delete() {
const { _id } = this.urlParams;
const result = Promise.await(removeInvite(this.userId, { _id }));

return API.v1.success(result);
return API.v1.success(await removeInvite(this.userId, { _id }));
},
},
);

API.v1.addRoute(
'useInviteToken',
{ authRequired: true },
{
post() {
authRequired: true,
validateParams: isUseInviteTokenProps,
},
{
async post() {
const { token } = this.bodyParams;
// eslint-disable-next-line react-hooks/rules-of-hooks
const result = Promise.await(useInviteToken(this.userId, token));

return API.v1.success(result);
return API.v1.success(await useInviteToken(this.userId, token));
},
},
);

API.v1.addRoute(
'validateInviteToken',
{ authRequired: false },
{
post() {
authRequired: false,
validateParams: isValidateInviteTokenProps,
},
{
async post() {
const { token } = this.bodyParams;

let valid = true;
try {
Promise.await(validateInviteToken(token));
} catch (e) {
valid = false;
return API.v1.success({ valid: Boolean(await validateInviteToken(token)) });
} catch (_) {
return API.v1.success({ valid: false });
}

return API.v1.success({ valid });
},
},
);
Loading