refactor: remove obsolete code
This commit is contained in:
parent
acef648c33
commit
ee77be1380
File diff suppressed because it is too large
Load Diff
|
@ -1,30 +0,0 @@
|
|||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import unbodyApi from '../../../../services/unbody/unbody.service'
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<any>,
|
||||
) {
|
||||
const {
|
||||
query: { q = '', tags: tagsString = '', slug },
|
||||
} = req
|
||||
if (!slug) {
|
||||
return res.status(400).json({ error: 'Invalid request' })
|
||||
}
|
||||
|
||||
const tags =
|
||||
typeof tagsString === 'string'
|
||||
? tagsString
|
||||
.split(',')
|
||||
.map((tag: string) => tag.trim())
|
||||
.filter((t) => t.length > 0)
|
||||
: undefined
|
||||
|
||||
const response = await unbodyApi.searchBlocks({
|
||||
q: q as string,
|
||||
tags,
|
||||
published: true,
|
||||
articleSlug: slug as string,
|
||||
})
|
||||
res.status(200).json(response)
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
import { PostTypes } from '@/types/data.types'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import unbodyApi from '../../../../services/unbody/unbody.service'
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<any>,
|
||||
) {
|
||||
const {
|
||||
query: { q = '', tags: tagsString = '', postType },
|
||||
} = req
|
||||
if (!Object.values(PostTypes).includes(postType as PostTypes)) {
|
||||
return res.status(400).json({ error: 'Invalid postType' })
|
||||
}
|
||||
|
||||
const tags =
|
||||
typeof tagsString === 'string'
|
||||
? tagsString
|
||||
.split(',')
|
||||
.map((tag: string) => tag.trim())
|
||||
.filter((t) => t.length > 0)
|
||||
: undefined
|
||||
const response =
|
||||
postType === PostTypes.Article
|
||||
? await unbodyApi.searchArticles(q as string, tags)
|
||||
: await unbodyApi.searchBlocks({ q: q as string, tags })
|
||||
|
||||
res.status(200).json(response)
|
||||
}
|
|
@ -114,53 +114,6 @@ export const GET_ALL_TOPICS_QUERY = gql`
|
|||
}
|
||||
`
|
||||
|
||||
export const SEARCH_ARTICLES_QUERY = gql`
|
||||
query SearchArticles(
|
||||
$filter: GetObjectsGoogleDocWhereInpObj
|
||||
$nearText: Txt2VecOpenAIGetObjectsGoogleDocNearTextInpObj
|
||||
) {
|
||||
Get {
|
||||
GoogleDoc(where: $filter, nearText: $nearText) {
|
||||
sourceId
|
||||
title
|
||||
subtitle
|
||||
summary
|
||||
tags
|
||||
createdAt
|
||||
modifiedAt
|
||||
slug
|
||||
path
|
||||
pathString
|
||||
mentions
|
||||
mentionsObj @client(always: true) {
|
||||
name
|
||||
emailAddress
|
||||
}
|
||||
|
||||
blocks {
|
||||
... on ImageBlock {
|
||||
url
|
||||
alt
|
||||
order
|
||||
width
|
||||
height
|
||||
__typename
|
||||
_additional {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_additional {
|
||||
id
|
||||
score
|
||||
certainty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export const SEARCH_BLOCKS_QUERY = gql`
|
||||
query SearchBlocks(
|
||||
$limit: Int
|
||||
|
|
|
@ -8,7 +8,6 @@ import {
|
|||
GetObjectsTextBlockWhereInpObj,
|
||||
GetPostsDocument,
|
||||
GetPostsQueryVariables,
|
||||
SearchArticlesDocument,
|
||||
SearchBlocksDocument,
|
||||
Txt2VecOpenAiGetObjectsTextBlockNearTextInpObj,
|
||||
} from '../../lib/unbody/unbody.generated'
|
||||
|
@ -1097,60 +1096,6 @@ export class UnbodyService {
|
|||
return result
|
||||
}, [])
|
||||
|
||||
searchArticles = async (
|
||||
q: string = '',
|
||||
tags: string[] = [],
|
||||
published: boolean = true,
|
||||
) =>
|
||||
this.handleRequest(async () => {
|
||||
const { data } = await this.client.query({
|
||||
query: SearchArticlesDocument,
|
||||
variables: {
|
||||
...(q.trim().length > 0
|
||||
? {
|
||||
nearText: {
|
||||
concepts: [q],
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
|
||||
filter: {
|
||||
operator: 'And',
|
||||
operands: [
|
||||
this.helpers.args.wherePublished(published),
|
||||
...tags.map(
|
||||
(tag) =>
|
||||
({
|
||||
operator: 'Like',
|
||||
path: ['tags'],
|
||||
valueString: tag,
|
||||
} as GetObjectsGoogleDocWhereInpObj),
|
||||
),
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!data) throw 'No data'
|
||||
|
||||
const { data: shows } = await this.getPodcastShows({
|
||||
populateEpisodes: false,
|
||||
})
|
||||
|
||||
const result = await unbodyDataTypes.transformMany<LPE.Article.Data>(
|
||||
articleSearchResultItem,
|
||||
data.Get.GoogleDoc || [],
|
||||
undefined,
|
||||
{
|
||||
shows,
|
||||
query: q,
|
||||
tags,
|
||||
},
|
||||
)
|
||||
|
||||
return result
|
||||
}, [])
|
||||
|
||||
searchPosts = ({
|
||||
skip = 0,
|
||||
limit = 10,
|
||||
|
|
Loading…
Reference in New Issue