refactor: remove obsolete code

This commit is contained in:
Hossein Mehrabi 2023-09-11 07:36:59 +03:30
parent acef648c33
commit ee77be1380
No known key found for this signature in database
GPG Key ID: 45C04964191AFAA1
5 changed files with 673 additions and 583 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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

View File

@ -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,