From 8a1f81d707b65d91f15e68f77dbdcafac85252e7 Mon Sep 17 00:00:00 2001 From: Alex Junior Date: Mon, 14 Mar 2022 23:16:53 -0300 Subject: [PATCH] Chore: Migrate REST API - getCommandPreview to Typescript (#3894) --- app/containers/MessageBox/index.tsx | 8 ++++---- app/definitions/rest/v1/commands.ts | 10 ++++++++++ app/definitions/rest/v1/index.ts | 4 +++- app/lib/rocketchat/services/restApi.ts | 4 +--- 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 app/definitions/rest/v1/commands.ts diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index c8c4160e..edbb76d5 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -638,12 +638,12 @@ class MessageBox extends Component { }, 1000); }; - setCommandPreview = async (command: any, name: string, params: any) => { + setCommandPreview = async (command: any, name: string, params: string) => { const { rid } = this.props; try { - const { success, preview } = await RocketChat.getCommandPreview(name, rid, params); - if (success) { - return this.setState({ commandPreview: preview?.items, showCommandPreview: true, command }); + const response = await RocketChat.getCommandPreview(name, rid, params); + if (response.success) { + return this.setState({ commandPreview: response.preview?.items, showCommandPreview: true, command }); } } catch (e) { log(e); diff --git a/app/definitions/rest/v1/commands.ts b/app/definitions/rest/v1/commands.ts new file mode 100644 index 00000000..2aa9dabd --- /dev/null +++ b/app/definitions/rest/v1/commands.ts @@ -0,0 +1,10 @@ +export type CommandsEndpoints = { + 'commands.preview': { + GET: (params: { command: string; roomId: string; params: string }) => { + preview: { + i18nTitle: string; + items: any; + }; + }; + }; +}; diff --git a/app/definitions/rest/v1/index.ts b/app/definitions/rest/v1/index.ts index 4e899f10..dc1cdcd0 100644 --- a/app/definitions/rest/v1/index.ts +++ b/app/definitions/rest/v1/index.ts @@ -16,6 +16,7 @@ import { TeamsEndpoints } from './teams'; import { E2eEndpoints } from './e2e'; import { SubscriptionsEndpoints } from './subscriptions'; import { VideoConferenceEndpoints } from './videoConference'; +import { CommandsEndpoints } from './commands'; export type Endpoints = ChannelsEndpoints & ChatEndpoints & @@ -34,4 +35,5 @@ export type Endpoints = ChannelsEndpoints & TeamsEndpoints & E2eEndpoints & SubscriptionsEndpoints & - VideoConferenceEndpoints; + VideoConferenceEndpoints & + CommandsEndpoints; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 30a896a4..38754af6 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -686,10 +686,8 @@ export const runSlashCommand = (command: string, roomId: string, params: any, tr tmid }); -export const getCommandPreview = (command: string, roomId: string, params: any): any => +export const getCommandPreview = (command: string, roomId: string, params: string) => // RC 0.65.0 - // TODO: missing definitions from server - // @ts-ignore sdk.get('commands.preview', { command, roomId,