diff --git a/apps/api/src/variable/service/variable.service.ts b/apps/api/src/variable/service/variable.service.ts index 50592b66..f1e6288b 100644 --- a/apps/api/src/variable/service/variable.service.ts +++ b/apps/api/src/variable/service/variable.service.ts @@ -120,7 +120,12 @@ export class VariableService { }, versions: { select: { - environmentId: true, + environment: { + select: { + id: true, + slug: true + } + }, value: true } } @@ -244,7 +249,12 @@ export class VariableService { }, select: { id: true, - environmentId: true, + environment: { + select: { + id: true, + slug: true + } + }, value: true, version: true } @@ -506,6 +516,15 @@ export class VariableService { where: { environmentId }, + select: { + value: true, + environment: { + select: { + id: true, + slug: true + } + } + }, orderBy: { version: 'desc' }, @@ -568,11 +587,20 @@ export class VariableService { id: true, name: true } + }, + versions: { + select: { + environment: { + select: { + id: true, + slug: true + } + } + } } }, skip: page * limit, take: limitMaxItemsPerPage(limit), - orderBy: { [sort]: order } @@ -586,6 +614,7 @@ export class VariableService { environment: { name: Environment['name'] id: Environment['id'] + slug: Environment['slug'] } value: VariableVersion['value'] version: VariableVersion['version'] @@ -619,6 +648,9 @@ export class VariableService { }, orderBy: { version: 'desc' + }, + include: { + environment: true } }) @@ -628,7 +660,8 @@ export class VariableService { variablesWithEnvironmentalValues.get(variable.id).values.push({ environment: { id: latestVersion.environmentId, - name: envIds.get(latestVersion.environmentId) + name: envIds.get(latestVersion.environmentId), + slug: latestVersion.environment.slug }, value: latestVersion.value, version: latestVersion.version @@ -640,7 +673,8 @@ export class VariableService { { environment: { id: latestVersion.environmentId, - name: envIds.get(latestVersion.environmentId) + name: envIds.get(latestVersion.environmentId), + slug: latestVersion.environment.slug }, value: latestVersion.value, version: latestVersion.version diff --git a/apps/api/src/variable/variable.e2e.spec.ts b/apps/api/src/variable/variable.e2e.spec.ts index a74c6d4a..b7adbd31 100644 --- a/apps/api/src/variable/variable.e2e.spec.ts +++ b/apps/api/src/variable/variable.e2e.spec.ts @@ -382,10 +382,15 @@ describe('Variable Controller Tests', () => { const variableVersion = await prisma.variableVersion.findMany({ where: { variableId: variable1.id + }, + include: { + environment: true } }) expect(variableVersion.length).toBe(1) + expect(variableVersion[0].environment.id).toBe(environment1.id) + expect(variableVersion[0].environment.slug).toBe(environment1.slug) }) it('should create a new version if the value is updated', async () => { @@ -596,6 +601,7 @@ describe('Variable Controller Tests', () => { expect(values.length).toBe(1) expect(values[0].value).toBe('Variable 1 value') expect(values[0].environment.id).toBe(environment1.id) + expect(values[0].environment.slug).toBe(environment1.slug) expect(variable.id).toBe(variable1.id) expect(variable.name).toBe('Variable 1') diff --git a/packages/api-client/src/types/variable.types.d.ts b/packages/api-client/src/types/variable.types.d.ts index a240fd92..1a34d3c9 100644 --- a/packages/api-client/src/types/variable.types.d.ts +++ b/packages/api-client/src/types/variable.types.d.ts @@ -16,6 +16,10 @@ export interface Variable { { value: string environmentId: string + environment: { + id: string + slug: string + } } ] } @@ -50,6 +54,10 @@ export interface UpdateVariableResponse { { value: string environmentId: string + environment: { + id: string + slug: string + } } ] } @@ -87,6 +95,7 @@ export interface GetAllVariablesOfProjectResponse environment: { id: string name: string + slug: string } value: string version: number diff --git a/packages/api-client/tests/variable.spec.ts b/packages/api-client/tests/variable.spec.ts index 9d25af96..3baffe22 100644 --- a/packages/api-client/tests/variable.spec.ts +++ b/packages/api-client/tests/variable.spec.ts @@ -109,7 +109,8 @@ describe('Get Variable Tests', () => { expect(variable.data.name).toBe('Variable 2') expect(variable.data.versions.length).toBe(1) expect(variable.data.versions[0].value).toBe('Variable 2 value') - expect(variable.data.versions[0].environmentId).toBe(environment.id) + expect(variable.data.versions[0].environment.id).toBe(environment.id) + expect(variable.data.versions[0].environment.slug).toBe(environment.slug) // Delete the variable const deleteVariable = await variableController.deleteVariable( @@ -164,9 +165,12 @@ describe('Get Variable Tests', () => { ) expect(updateVariable.data.updatedVersions.length).toBe(1) expect(updateVariable.data.updatedVersions[0].value).toBe('1234') - expect(updateVariable.data.updatedVersions[0].environmentId).toBe( + expect(updateVariable.data.updatedVersions[0].environment.id).toBe( environment.id ) + expect(updateVariable.data.updatedVersions[0].environment.slug).toBe( + environment.slug + ) }) // Roll back a variable @@ -222,6 +226,7 @@ describe('Get Variable Tests', () => { expect(value).toHaveProperty('environment') expect(value.environment).toHaveProperty('id') expect(value.environment).toHaveProperty('name') + expect(value.environment).toHaveProperty('slug') expect(value).toHaveProperty('value') expect(value).toHaveProperty('version') })