Skip to content

Commit

Permalink
fix: ensure requests within search results are translated to the late…
Browse files Browse the repository at this point in the history
…st version
  • Loading branch information
jamesgeorge007 committed Mar 22, 2024
1 parent f23ef92 commit bdde8f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Expand Up @@ -37,6 +37,7 @@ export const hoppRESTImporter = (content: string[]) =>
*/
const validateCollection = (collection: unknown) => {
const collectionSchemaParsedResult = HoppCollection.safeParse(collection)

if (collectionSchemaParsedResult.type === "ok") {
const requests = collectionSchemaParsedResult.value.requests.map(
(request) => {
Expand Down Expand Up @@ -83,19 +84,24 @@ export const hoppGQLImporter = (content: string) =>
* @returns the collection if it is valid, else a translated version of the collection
*/
export const validateGQLCollection = (collection: unknown) => {
const result = HoppCollection.safeParse(collection)
const collectionSchemaParsedResult = HoppCollection.safeParse(collection)

if (result.type === "ok")
return O.some({
...result.value,
requests: result.value.requests.map((request) => {
if (collectionSchemaParsedResult.type === "ok") {
const requests = collectionSchemaParsedResult.value.requests.map(
(request) => {
const requestSchemaParsedResult = HoppRESTRequest.safeParse(request)

return requestSchemaParsedResult.type === "ok"
? requestSchemaParsedResult.value
: getDefaultGQLRequest()
}),
}
)

return O.some({
...collectionSchemaParsedResult.value,
requests,
})
}

return O.some(translateToNewGQLCollection(collection))
}
Expand Up @@ -7,7 +7,7 @@ import {
GetSingleRequestDocument,
} from "../backend/graphql"
import { TeamCollection } from "./TeamCollection"
import { HoppRESTAuth, HoppRESTHeader } from "@hoppscotch/data"
import { HoppRESTAuth, HoppRESTHeader, HoppRESTRequest } from "@hoppscotch/data"

import * as E from "fp-ts/Either"
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
Expand Down Expand Up @@ -150,6 +150,14 @@ function convertToTeamTree(
if (isAlreadyInserted) return

if (parentCollection) {
const requestSchemaParsedResult = HoppRESTRequest.safeParse(
request.request
)

if (requestSchemaParsedResult.type === "ok") {
request.request = requestSchemaParsedResult.value
}

parentCollection.requests = parentCollection.requests || []
parentCollection.requests.push({
id: request.id,
Expand Down

0 comments on commit bdde8f2

Please sign in to comment.