Skip to content

Commit

Permalink
Chore: Add typings for /v1/webdav.getMyAccounts (#25276)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
  • Loading branch information
sampaiodiego and ggazzo committed May 4, 2022
1 parent c53409f commit 4a47110
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
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'>;
3 changes: 3 additions & 0 deletions packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import type { TeamsEndpoints } from './v1/teams';
import type { UsersEndpoints } from './v1/users';
import type { VideoConferenceEndpoints } from './v1/videoConference';
import type { VoipEndpoints } from './v1/voip';
import type { WebdavEndpoints } from './v1/webdav';
import type { OAuthAppsEndpoint } from './v1/oauthapps';

// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/interface-name-prefix
export interface Endpoints
extends BannersEndpoints,
Expand Down Expand Up @@ -61,6 +63,7 @@ export interface Endpoints
InvitesEndpoints,
E2eEndpoints,
CustomSoundEndpoint,
WebdavEndpoints,
OAuthAppsEndpoint {}

type OperationsByPathPattern<TPathPattern extends keyof Endpoints> = TPathPattern extends any
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'>[];
};
};
};

0 comments on commit 4a47110

Please sign in to comment.