fix: add auth and headers for old collection

This commit is contained in:
nivedin
2023-12-09 14:10:16 +05:30
committed by Andrew Bastin
parent 16bbfec736
commit b6f3b24b9e

View File

@@ -106,8 +106,13 @@ function exportedCollectionToHoppCollection(
): HoppCollection<HoppRESTRequest | HoppGQLRequest> { ): HoppCollection<HoppRESTRequest | HoppGQLRequest> {
if (collectionType == "REST") { if (collectionType == "REST") {
const restCollection = collection as ExportedUserCollectionREST const restCollection = collection as ExportedUserCollectionREST
const data = restCollection.data ? JSON.parse(restCollection.data) : null const data =
restCollection.data && restCollection.data != "null"
? JSON.parse(restCollection.data)
: {
auth: { authType: "inherit", authActive: false },
headers: [],
}
return { return {
id: restCollection.id, id: restCollection.id,
v: 1, v: 1,
@@ -142,12 +147,18 @@ function exportedCollectionToHoppCollection(
testScript, testScript,
}) })
), ),
auth: data.auth ?? { authType: "inherit", authActive: false }, auth: data.auth,
headers: data.headers ?? [], headers: data.headers,
} }
} else { } else {
const gqlCollection = collection as ExportedUserCollectionGQL const gqlCollection = collection as ExportedUserCollectionGQL
const data = gqlCollection.data ? JSON.parse(gqlCollection.data) : null const data =
gqlCollection.data && gqlCollection.data !== "null"
? JSON.parse(gqlCollection.data)
: {
auth: { authType: "inherit", authActive: false },
headers: [],
}
return { return {
id: gqlCollection.id, id: gqlCollection.id,
@@ -298,9 +309,15 @@ function setupUserCollectionCreatedSubscription() {
}) })
} else { } else {
// root collections won't have parentCollectionID // root collections won't have parentCollectionID
const data = res.right.userCollectionCreated.data const data =
? JSON.parse(res.right.userCollectionCreated.data) res.right.userCollectionCreated.data &&
: null res.right.userCollectionCreated.data != "null"
? JSON.parse(res.right.userCollectionCreated.data)
: {
auth: { authType: "inherit", authActive: false },
headers: [],
}
runDispatchWithOutSyncing(() => { runDispatchWithOutSyncing(() => {
collectionType == "GQL" collectionType == "GQL"
? addGraphqlCollection({ ? addGraphqlCollection({
@@ -308,19 +325,16 @@ function setupUserCollectionCreatedSubscription() {
folders: [], folders: [],
requests: [], requests: [],
v: 1, v: 1,
auth: data?.auth ?? { authType: "inherit", authActive: false }, auth: data.auth,
headers: data?.headers ?? [], headers: data.headers,
}) })
: addRESTCollection({ : addRESTCollection({
name: res.right.userCollectionCreated.title, name: res.right.userCollectionCreated.title,
folders: [], folders: [],
requests: [], requests: [],
v: 1, v: 1,
auth: data?.auth ?? { auth: data.auth,
authType: "inherit", headers: data?.headers,
authActive: false,
},
headers: data?.headers ?? [],
}) })
const localIndex = collectionStore.value.state.length - 1 const localIndex = collectionStore.value.state.length - 1