diff --git a/apps/api/src/common/get-default-project-environemnt.ts b/apps/api/src/common/get-default-project-environment.ts similarity index 100% rename from apps/api/src/common/get-default-project-environemnt.ts rename to apps/api/src/common/get-default-project-environment.ts diff --git a/apps/api/src/event/event.e2e.spec.ts b/apps/api/src/event/event.e2e.spec.ts index 6ca67d5b..5eb98282 100644 --- a/apps/api/src/event/event.e2e.spec.ts +++ b/apps/api/src/event/event.e2e.spec.ts @@ -271,6 +271,7 @@ describe('Event Controller Tests', () => { { name: 'My secret', value: 'My value', + note: 'Some note', environmentId: environment.id, rotateAfter: '720' }, @@ -305,6 +306,7 @@ describe('Event Controller Tests', () => { { name: 'My variable', value: 'My value', + note: 'Some note', environmentId: environment.id }, project.id diff --git a/apps/api/src/prisma/migrations/20240222062319_add_note_to_secret_and_variable/migration.sql b/apps/api/src/prisma/migrations/20240222062319_add_note_to_secret_and_variable/migration.sql new file mode 100644 index 00000000..dd22c7dc --- /dev/null +++ b/apps/api/src/prisma/migrations/20240222062319_add_note_to_secret_and_variable/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "Secret" ADD COLUMN "note" TEXT; + +-- AlterTable +ALTER TABLE "Variable" ADD COLUMN "note" TEXT; diff --git a/apps/api/src/prisma/schema.prisma b/apps/api/src/prisma/schema.prisma index d8029427..8a01c0c5 100644 --- a/apps/api/src/prisma/schema.prisma +++ b/apps/api/src/prisma/schema.prisma @@ -319,6 +319,7 @@ model Secret { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt rotateAt DateTime? + note String? lastUpdatedBy User? @relation(fields: [lastUpdatedById], references: [id], onUpdate: Cascade, onDelete: SetNull) lastUpdatedById String? @@ -355,6 +356,7 @@ model Variable { versions VariableVersion[] // Stores the versions of the variable createdAt DateTime @default(now()) updatedAt DateTime @updatedAt + note String? lastUpdatedBy User? @relation(fields: [lastUpdatedById], references: [id], onUpdate: Cascade, onDelete: SetNull) lastUpdatedById String? diff --git a/apps/api/src/secret/dto/create.secret/create.secret.ts b/apps/api/src/secret/dto/create.secret/create.secret.ts index 117ea91b..3c8065a8 100644 --- a/apps/api/src/secret/dto/create.secret/create.secret.ts +++ b/apps/api/src/secret/dto/create.secret/create.secret.ts @@ -1,4 +1,4 @@ -import { IsNumber, IsOptional, IsString } from 'class-validator' +import { IsNumber, IsOptional, IsString, Length } from 'class-validator' export class CreateSecret { @IsString() @@ -7,6 +7,11 @@ export class CreateSecret { @IsString() value: string + @IsString() + @IsOptional() + @Length(0, 100) + note: string + @IsNumber() @IsOptional() environmentId: string diff --git a/apps/api/src/secret/secret.e2e.spec.ts b/apps/api/src/secret/secret.e2e.spec.ts index b3f9ec9e..ac204518 100644 --- a/apps/api/src/secret/secret.e2e.spec.ts +++ b/apps/api/src/secret/secret.e2e.spec.ts @@ -199,6 +199,7 @@ describe('Secret Controller Tests', () => { payload: { environmentId: environment2.id, name: 'Secret 1', + note: 'Secret 1 note', value: 'Secret 1 value', rotateAfter: '24' }, @@ -213,6 +214,7 @@ describe('Secret Controller Tests', () => { expect(body).toBeDefined() expect(body.name).toBe('Secret 1') + expect(body.note).toBe('Secret 1 note') expect(body.environmentId).toBe(environment2.id) expect(body.projectId).toBe(project1.id) @@ -417,12 +419,13 @@ describe('Secret Controller Tests', () => { ) }) - it('should be able to update the environment name without creating a new version', async () => { + it('should be able to update the secret name and note without creating a new version', async () => { const response = await app.inject({ method: 'PUT', url: `/secret/${secret1.id}`, payload: { - name: 'Updated Secret 1' + name: 'Updated Secret 1', + note: 'Updated Secret 1 note' }, headers: { 'x-e2e-user-email': user1.email @@ -431,6 +434,7 @@ describe('Secret Controller Tests', () => { expect(response.statusCode).toBe(200) expect(response.json().name).toEqual('Updated Secret 1') + expect(response.json().note).toEqual('Updated Secret 1 note') const secretVersion = await prisma.secretVersion.findMany({ where: { @@ -764,7 +768,8 @@ describe('Secret Controller Tests', () => { environmentId: environment1.id, name: 'Secret 20', value: 'Secret 20 value', - rotateAfter: '24' + rotateAfter: '24', + note: 'Secret 20 note' }, project2.id ) diff --git a/apps/api/src/secret/service/secret.service.ts b/apps/api/src/secret/service/secret.service.ts index 834562b3..808ecf10 100644 --- a/apps/api/src/secret/service/secret.service.ts +++ b/apps/api/src/secret/service/secret.service.ts @@ -26,7 +26,7 @@ import getEnvironmentWithAuthority from '../../common/get-environment-with-autho import getSecretWithAuthority from '../../common/get-secret-with-authority' import { SecretWithVersion } from '../secret.types' import createEvent from '../../common/create-event' -import getDefaultEnvironmentOfProject from '../../common/get-default-project-environemnt' +import getDefaultEnvironmentOfProject from '../../common/get-default-project-environment' @Injectable() export class SecretService { @@ -76,6 +76,7 @@ export class SecretService { const secret = await this.prisma.secret.create({ data: { name: dto.name, + note: dto.note, rotateAt: addHoursToDate(dto.rotateAfter), versions: { create: { @@ -169,6 +170,7 @@ export class SecretService { }, data: { name: dto.name, + note: dto.note, rotateAt: addHoursToDate(dto.rotateAfter), lastUpdatedById: user.id, versions: { @@ -186,8 +188,11 @@ export class SecretService { id: secretId }, data: { - name: dto.name ?? secret.name, - rotateAt: dto.rotateAfter ?? secret.rotateAt, + note: dto.note, + name: dto.name, + rotateAt: dto.rotateAfter + ? addHoursToDate(dto.rotateAfter) + : undefined, lastUpdatedById: user.id } }) diff --git a/apps/api/src/variable/dto/create.variable/create.variable.ts b/apps/api/src/variable/dto/create.variable/create.variable.ts index 3703b2c7..07f49b4b 100644 --- a/apps/api/src/variable/dto/create.variable/create.variable.ts +++ b/apps/api/src/variable/dto/create.variable/create.variable.ts @@ -1,4 +1,4 @@ -import { IsNumber, IsOptional, IsString } from 'class-validator' +import { IsNumber, IsOptional, IsString, Length } from 'class-validator' export class CreateVariable { @IsString() @@ -7,6 +7,11 @@ export class CreateVariable { @IsString() value: string + @IsString() + @IsOptional() + @Length(0, 100) + note: string + @IsNumber() @IsOptional() environmentId: string diff --git a/apps/api/src/variable/service/variable.service.ts b/apps/api/src/variable/service/variable.service.ts index 547c2f5f..d8511224 100644 --- a/apps/api/src/variable/service/variable.service.ts +++ b/apps/api/src/variable/service/variable.service.ts @@ -19,7 +19,7 @@ import { import { CreateVariable } from '../dto/create.variable/create.variable' import getProjectWithAuthority from '../../common/get-project-with-authority' import getEnvironmentWithAuthority from '../../common/get-environment-with-authority' -import getDefaultEnvironmentOfProject from '../../common/get-default-project-environemnt' +import getDefaultEnvironmentOfProject from '../../common/get-default-project-environment' import createEvent from '../../common/create-event' import { UpdateVariable } from '../dto/update.variable/update.variable' import getVariableWithAuthority from '../../common/get-variable-with-authority' @@ -76,6 +76,7 @@ export class VariableService { const variable = await this.prisma.variable.create({ data: { name: dto.name, + note: dto.note, versions: { create: { value: dto.value, @@ -176,6 +177,7 @@ export class VariableService { }, data: { name: dto.name, + note: dto.note, lastUpdatedById: user.id, versions: { create: { @@ -192,7 +194,8 @@ export class VariableService { id: variableId }, data: { - name: dto.name ?? variable.name, + note: dto.note, + name: dto.name, lastUpdatedById: user.id } }) diff --git a/apps/api/src/variable/variable.e2e.spec.ts b/apps/api/src/variable/variable.e2e.spec.ts index a88d9447..23ff63e6 100644 --- a/apps/api/src/variable/variable.e2e.spec.ts +++ b/apps/api/src/variable/variable.e2e.spec.ts @@ -200,6 +200,7 @@ describe('Variable Controller Tests', () => { environmentId: environment2.id, name: 'Variable 1', value: 'Variable 1 value', + note: 'Variable 1 note', rotateAfter: '24' }, headers: { @@ -213,6 +214,7 @@ describe('Variable Controller Tests', () => { expect(body).toBeDefined() expect(body.name).toBe('Variable 1') + expect(body.note).toBe('Variable 1 note') expect(body.environmentId).toBe(environment2.id) expect(body.projectId).toBe(project1.id) @@ -238,6 +240,7 @@ describe('Variable Controller Tests', () => { payload: { name: 'Variable 2', value: 'Variable 2 value', + note: 'Variable 2 note', rotateAfter: '24' }, headers: { @@ -251,6 +254,7 @@ describe('Variable Controller Tests', () => { expect(body).toBeDefined() expect(body.name).toBe('Variable 2') + expect(body.note).toBe('Variable 2 note') expect(body.environmentId).toBe(environment1.id) expect(body.projectId).toBe(project1.id) }) @@ -417,12 +421,13 @@ describe('Variable Controller Tests', () => { ) }) - it('should be able to update the environment name without creating a new version', async () => { + it('should be able to update the variable name and note without creating a new version', async () => { const response = await app.inject({ method: 'PUT', url: `/variable/${variable1.id}`, payload: { - name: 'Updated Variable 1' + name: 'Updated Variable 1', + note: 'Updated Variable 1 note' }, headers: { 'x-e2e-user-email': user1.email @@ -431,6 +436,7 @@ describe('Variable Controller Tests', () => { expect(response.statusCode).toBe(200) expect(response.json().name).toEqual('Updated Variable 1') + expect(response.json().note).toEqual('Updated Variable 1 note') const variableVersion = await prisma.variableVersion.findMany({ where: {