From e43766856e88ae8f99adb6b3d5220cfe2555a54b Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 22 Apr 2022 15:04:13 -0300 Subject: [PATCH 1/3] Add typings for /v1/webdav.getMyAccounts --- apps/meteor/app/api/server/lib/webdav.ts | 20 +++++++++---------- .../api/server/v1/{webdav.js => webdav.ts} | 6 ++++-- packages/core-typings/src/IWebdavAccount.ts | 16 +++++++-------- packages/rest-typings/src/index.ts | 4 +++- packages/rest-typings/src/v1/webdav.ts | 9 +++++++++ 5 files changed, 33 insertions(+), 22 deletions(-) rename apps/meteor/app/api/server/v1/{webdav.js => webdav.ts} (59%) create mode 100644 packages/rest-typings/src/v1/webdav.ts diff --git a/apps/meteor/app/api/server/lib/webdav.ts b/apps/meteor/app/api/server/lib/webdav.ts index 08efc12d9f9b..7f3701a7d695 100644 --- a/apps/meteor/app/api/server/lib/webdav.ts +++ b/apps/meteor/app/api/server/lib/webdav.ts @@ -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 { + return WebdavAccounts.findWithUserId(uid, { + projection: { + _id: 1, + username: 1, + serverURL: 1, + name: 1, + }, + }).toArray(); } diff --git a/apps/meteor/app/api/server/v1/webdav.js b/apps/meteor/app/api/server/v1/webdav.ts similarity index 59% rename from apps/meteor/app/api/server/v1/webdav.js rename to apps/meteor/app/api/server/v1/webdav.ts index e242c40f379b..4b2119dfcfec 100644 --- a/apps/meteor/app/api/server/v1/webdav.js +++ b/apps/meteor/app/api/server/v1/webdav.ts @@ -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 }), + }); }, }, ); diff --git a/packages/core-typings/src/IWebdavAccount.ts b/packages/core-typings/src/IWebdavAccount.ts index 51cafc02da05..bd53f0ce17e0 100644 --- a/packages/core-typings/src/IWebdavAccount.ts +++ b/packages/core-typings/src/IWebdavAccount.ts @@ -1,14 +1,14 @@ import type { IRocketChatRecord } from "./IRocketChatRecord"; export interface IWebdavAccount extends IRocketChatRecord { - userId: string; - serverURL: string; - username: string; - password: string; - name: string; + userId: string; + serverURL: string; + username: string; + password: string; + name: string; } -export type IWebdavAccountPayload = Omit< - IWebdavAccount, - "userId" | "_id" | "_updatedAt" +export type IWebdavAccountPayload = Pick< + IWebdavAccount, + '_id' | 'username' | 'serverURL' | 'name' >; diff --git a/packages/rest-typings/src/index.ts b/packages/rest-typings/src/index.ts index 1998762270c0..fef1cdaebbc1 100644 --- a/packages/rest-typings/src/index.ts +++ b/packages/rest-typings/src/index.ts @@ -28,6 +28,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"; type CommunityEndpoints = BannersEndpoints & ChatEndpoints & @@ -55,7 +56,8 @@ type CommunityEndpoints = BannersEndpoints & VoipEndpoints & InvitesEndpoints & E2eEndpoints & - CustomSoundEndpoint; + CustomSoundEndpoint & + WebdavEndpoints; export interface Endpoints extends CommunityEndpoints {} // type Endpoints = CommunityEndpoints; diff --git a/packages/rest-typings/src/v1/webdav.ts b/packages/rest-typings/src/v1/webdav.ts new file mode 100644 index 000000000000..7896548e02e2 --- /dev/null +++ b/packages/rest-typings/src/v1/webdav.ts @@ -0,0 +1,9 @@ +import type { IWebdavAccountPayload } from "@rocket.chat/core-typings"; + +export type WebdavEndpoints = { + 'webdav.getMyAccounts': { + GET: () => { + accounts: IWebdavAccountPayload[]; + }; + }; +}; From 3ae9839d2f91bba14709b1678034cc7dd6fe682a Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 22 Apr 2022 16:14:05 -0300 Subject: [PATCH 2/3] Revert changes of method payload --- packages/core-typings/src/IWebdavAccount.ts | 2 +- packages/rest-typings/src/v1/webdav.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core-typings/src/IWebdavAccount.ts b/packages/core-typings/src/IWebdavAccount.ts index bd53f0ce17e0..e6154af2c089 100644 --- a/packages/core-typings/src/IWebdavAccount.ts +++ b/packages/core-typings/src/IWebdavAccount.ts @@ -10,5 +10,5 @@ export interface IWebdavAccount extends IRocketChatRecord { export type IWebdavAccountPayload = Pick< IWebdavAccount, - '_id' | 'username' | 'serverURL' | 'name' + 'serverURL' | 'username' | 'password' | 'name' >; diff --git a/packages/rest-typings/src/v1/webdav.ts b/packages/rest-typings/src/v1/webdav.ts index 7896548e02e2..394bc4cee5ac 100644 --- a/packages/rest-typings/src/v1/webdav.ts +++ b/packages/rest-typings/src/v1/webdav.ts @@ -1,9 +1,9 @@ -import type { IWebdavAccountPayload } from "@rocket.chat/core-typings"; +import type { IWebdavAccount } from "@rocket.chat/core-typings"; export type WebdavEndpoints = { 'webdav.getMyAccounts': { GET: () => { - accounts: IWebdavAccountPayload[]; + accounts: Pick[]; }; }; }; From 1c6554f8be8a60797dcf358d009bc2ad4653f594 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Tue, 26 Apr 2022 09:23:55 -0300 Subject: [PATCH 3/3] Fix lint --- packages/core-typings/src/IWebdavAccount.ts | 5 +---- packages/rest-typings/src/index.ts | 4 ++-- packages/rest-typings/src/v1/webdav.ts | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/core-typings/src/IWebdavAccount.ts b/packages/core-typings/src/IWebdavAccount.ts index a37825e67909..f1a834be7dc5 100644 --- a/packages/core-typings/src/IWebdavAccount.ts +++ b/packages/core-typings/src/IWebdavAccount.ts @@ -8,7 +8,4 @@ export interface IWebdavAccount extends IRocketChatRecord { name: string; } -export type IWebdavAccountPayload = Pick< - IWebdavAccount, - 'serverURL' | 'username' | 'password' | 'name' ->; +export type IWebdavAccountPayload = Pick; diff --git a/packages/rest-typings/src/index.ts b/packages/rest-typings/src/index.ts index 352e67a1f0bb..d49e08fa4886 100644 --- a/packages/rest-typings/src/index.ts +++ b/packages/rest-typings/src/index.ts @@ -29,7 +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"; +import type { WebdavEndpoints } from './v1/webdav'; // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/interface-name-prefix export interface Endpoints @@ -60,7 +60,7 @@ export interface Endpoints InvitesEndpoints, E2eEndpoints, CustomSoundEndpoint, - WebdavEndpoints {} + WebdavEndpoints {} type OperationsByPathPattern = TPathPattern extends any ? OperationsByPathPatternAndMethod diff --git a/packages/rest-typings/src/v1/webdav.ts b/packages/rest-typings/src/v1/webdav.ts index 394bc4cee5ac..51a810b9ce15 100644 --- a/packages/rest-typings/src/v1/webdav.ts +++ b/packages/rest-typings/src/v1/webdav.ts @@ -1,4 +1,4 @@ -import type { IWebdavAccount } from "@rocket.chat/core-typings"; +import type { IWebdavAccount } from '@rocket.chat/core-typings'; export type WebdavEndpoints = { 'webdav.getMyAccounts': {