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 typings for /v1/webdav.getMyAccounts #25276

Merged
merged 5 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 9 additions & 11 deletions apps/meteor/app/api/server/lib/webdav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import type { IWebdavAccount } from '@rocket.chat/core-typings';

import { WebdavAccounts } from '../../../models/server/raw';

export async function findWebdavAccountsByUserId({ uid }: { uid: string }): Promise<{ accounts: IWebdavAccount[] }> {
return {
accounts: await WebdavAccounts.findWithUserId(uid, {
projection: {
_id: 1,
username: 1,
serverURL: 1,
name: 1,
},
}).toArray(),
};
export async function findWebdavAccountsByUserId({ uid }: { uid: string }): Promise<IWebdavAccount[]> {
return WebdavAccounts.findWithUserId(uid, {
projection: {
_id: 1,
username: 1,
serverURL: 1,
name: 1,
},
}).toArray();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ API.v1.addRoute(
'webdav.getMyAccounts',
{ authRequired: true },
{
get() {
return API.v1.success(Promise.await(findWebdavAccountsByUserId({ uid: this.userId })));
async get() {
return API.v1.success({
accounts: await findWebdavAccountsByUserId({ uid: this.userId }),
});
},
},
);
2 changes: 1 addition & 1 deletion packages/core-typings/src/IWebdavAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export interface IWebdavAccount extends IRocketChatRecord {
name: string;
}

export type IWebdavAccountPayload = Omit<IWebdavAccount, 'userId' | '_id' | '_updatedAt'>;
export type IWebdavAccountPayload = Pick<IWebdavAccount, 'serverURL' | 'username' | 'password' | 'name'>;
4 changes: 3 additions & 1 deletion packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type { StatisticsEndpoints } from './v1/statistics';
import type { TeamsEndpoints } from './v1/teams';
import type { UsersEndpoints } from './v1/users';
import type { VoipEndpoints } from './v1/voip';
import type { WebdavEndpoints } from './v1/webdav';

// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/interface-name-prefix
export interface Endpoints
Expand Down Expand Up @@ -58,7 +59,8 @@ export interface Endpoints
VoipEndpoints,
InvitesEndpoints,
E2eEndpoints,
CustomSoundEndpoint {}
CustomSoundEndpoint,
WebdavEndpoints {}

type OperationsByPathPattern<TPathPattern extends keyof Endpoints> = TPathPattern extends any
? OperationsByPathPatternAndMethod<TPathPattern>
Expand Down
9 changes: 9 additions & 0 deletions packages/rest-typings/src/v1/webdav.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { IWebdavAccount } from '@rocket.chat/core-typings';

export type WebdavEndpoints = {
'webdav.getMyAccounts': {
GET: () => {
accounts: Pick<IWebdavAccount, '_id' | 'username' | 'serverURL' | 'name'>[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about create a type to hold this variation? does make any sense sharing this on other place or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk actually, there is no other place using it.. 🤷‍♂️

};
};
};