Skip to content

Commit f655035

Browse files
authored
fix: team env not migrating in edge cases (hoppscotch#5160)
1 parent ff8a8f5 commit f655035

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/hoppscotch-common/src/helpers/teams/TeamEnvironmentAdapter.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
TeamEnvironmentUpdatedDocument,
1111
} from "../backend/graphql"
1212
import { TeamEnvironment } from "./TeamEnvironment"
13-
import { Environment, EnvironmentSchemaVersion } from "@hoppscotch/data"
13+
import {
14+
Environment,
15+
EnvironmentSchemaVersion,
16+
translateToNewEnvironmentVariables,
17+
} from "@hoppscotch/data"
1418

1519
type EntityType = "environment"
1620
type EntityID = `${EntityType}-${string}`
@@ -114,10 +118,15 @@ export default class TeamEnvironmentAdapter {
114118
if (result.right.team) {
115119
results.push(
116120
...result.right.team.teamEnvironments.map((x) => {
121+
// Keep the environment structure consistent with the new schema
117122
const environment = <Environment>{
123+
v: EnvironmentSchemaVersion,
118124
id: x.id,
119125
name: x.name,
120-
variables: JSON.parse(x.variables),
126+
variables: JSON.parse(x.variables).map(
127+
(variable: Environment["variables"][number]) =>
128+
translateToNewEnvironmentVariables(variable)
129+
),
121130
}
122131

123132
const parsedEnvironment = Environment.safeParse(environment)
@@ -128,10 +137,7 @@ export default class TeamEnvironmentAdapter {
128137
environment:
129138
parsedEnvironment.type === "ok"
130139
? parsedEnvironment.value
131-
: {
132-
...environment,
133-
v: EnvironmentSchemaVersion,
134-
},
140+
: environment,
135141
}
136142
})
137143
)

0 commit comments

Comments
 (0)