From f49957318e1cd62d49558dce9e401abb2c6c5fe8 Mon Sep 17 00:00:00 2001 From: Aric Lasry Date: Thu, 16 Nov 2023 00:07:15 +0100 Subject: [PATCH] Fix types --- front/lib/api/assistant/types.ts | 19 ------------------- .../conversations/[cId]/content_fragments.ts | 6 ++---- .../[cId]/content_fragment/index.ts | 19 ++++++++++++++++++- .../w/[wId]/assistant/conversations/index.ts | 3 ++- 4 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 front/lib/api/assistant/types.ts diff --git a/front/lib/api/assistant/types.ts b/front/lib/api/assistant/types.ts deleted file mode 100644 index f6bb8ba5c65c5..0000000000000 --- a/front/lib/api/assistant/types.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as t from "io-ts"; - -export const PostContentFragmentRequestBodySchema = t.type({ - title: t.string, - content: t.string, - url: t.union([t.string, t.null]), - contentType: t.union([ - t.literal("slack_thread_content"), - t.literal("file_attachment"), - ]), - context: t.type({ - timezone: t.string, - profilePictureUrl: t.union([t.string, t.null]), - }), -}); - -export type PostContentFragmentRequestBody = t.TypeOf< - typeof PostContentFragmentRequestBodySchema ->; diff --git a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/content_fragments.ts b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/content_fragments.ts index 7659cd8a2e6d4..fd1d7897582d1 100644 --- a/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/content_fragments.ts +++ b/front/pages/api/v1/w/[wId]/assistant/conversations/[cId]/content_fragments.ts @@ -16,8 +16,6 @@ export type PostContentFragmentsResponseBody = { contentFragment: ContentFragmentType; }; - - export const PostContentFragmentRequestBodySchema = t.type({ title: t.string, content: t.string, @@ -39,7 +37,6 @@ export type PostContentFragmentRequestBody = t.TypeOf< typeof PostContentFragmentRequestBodySchema >; - async function handler( req: NextApiRequest, res: NextApiResponse @@ -93,7 +90,8 @@ async function handler( }); } - const { content, title, url, contentType, context } = bodyValidation.right; + const { content, title, url, contentType, context } = + bodyValidation.right; if (content.length === 0 || content.length > 64 * 1024) { return apiError(req, res, { diff --git a/front/pages/api/w/[wId]/assistant/conversations/[cId]/content_fragment/index.ts b/front/pages/api/w/[wId]/assistant/conversations/[cId]/content_fragment/index.ts index 24f6b9a555a52..ffc388e104eac 100644 --- a/front/pages/api/w/[wId]/assistant/conversations/[cId]/content_fragment/index.ts +++ b/front/pages/api/w/[wId]/assistant/conversations/[cId]/content_fragment/index.ts @@ -7,12 +7,29 @@ import { getConversation, postNewContentFragment, } from "@app/lib/api/assistant/conversation"; -import { PostContentFragmentRequestBodySchema } from "@app/lib/api/assistant/types"; import { Authenticator, getSession } from "@app/lib/auth"; import { ReturnedAPIErrorType } from "@app/lib/error"; import { apiError, withLogging } from "@app/logger/withlogging"; import { ContentFragmentType } from "@app/types/assistant/conversation"; +export const PostContentFragmentRequestBodySchema = t.type({ + title: t.string, + content: t.string, + url: t.union([t.string, t.null]), + contentType: t.union([ + t.literal("slack_thread_content"), + t.literal("file_attachment"), + ]), + context: t.type({ + timezone: t.string, + profilePictureUrl: t.union([t.string, t.null]), + }), +}); + +export type PostContentFragmentRequestBody = t.TypeOf< + typeof PostContentFragmentRequestBodySchema +>; + export const PostMessagesRequestBodySchema = t.type({ content: t.string, mentions: t.array( diff --git a/front/pages/api/w/[wId]/assistant/conversations/index.ts b/front/pages/api/w/[wId]/assistant/conversations/index.ts index 0fd25a68e0c02..441788ee4144f 100644 --- a/front/pages/api/w/[wId]/assistant/conversations/index.ts +++ b/front/pages/api/w/[wId]/assistant/conversations/index.ts @@ -10,7 +10,6 @@ import { postNewContentFragment, } from "@app/lib/api/assistant/conversation"; import { postUserMessageWithPubSub } from "@app/lib/api/assistant/pubsub"; -import { PostContentFragmentRequestBodySchema } from "@app/lib/api/assistant/types"; import { Authenticator, getSession } from "@app/lib/auth"; import { ReturnedAPIErrorType } from "@app/lib/error"; import { apiError, withLogging } from "@app/logger/withlogging"; @@ -22,6 +21,8 @@ import { UserMessageType, } from "@app/types/assistant/conversation"; +import { PostContentFragmentRequestBodySchema } from "./[cId]/content_fragment"; + export const PostConversationsRequestBodySchema = t.type({ title: t.union([t.string, t.null]), visibility: t.union([