Skip to content

Commit

Permalink
feat(api): Add note to secret and variable
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Feb 22, 2024
1 parent b59f16b commit e9c9ac2
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apps/api/src/event/event.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ describe('Event Controller Tests', () => {
{
name: 'My secret',
value: 'My value',
note: 'Some note',
environmentId: environment.id,
rotateAfter: '720'
},
Expand Down Expand Up @@ -305,6 +306,7 @@ describe('Event Controller Tests', () => {
{
name: 'My variable',
value: 'My value',
note: 'Some note',
environmentId: environment.id
},
project.id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Secret" ADD COLUMN "note" TEXT;

-- AlterTable
ALTER TABLE "Variable" ADD COLUMN "note" TEXT;
2 changes: 2 additions & 0 deletions apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/secret/dto/create.secret/create.secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export class CreateSecret {
@IsString()
value: string

@IsString()
@IsOptional()
note: string

@IsNumber()
@IsOptional()
environmentId: string
Expand Down
11 changes: 8 additions & 3 deletions apps/api/src/secret/secret.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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: {
Expand Down Expand Up @@ -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
)
Expand Down
5 changes: 4 additions & 1 deletion apps/api/src/secret/service/secret.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -169,6 +170,7 @@ export class SecretService {
},
data: {
name: dto.name,
note: dto.note ?? secret.note,
rotateAt: addHoursToDate(dto.rotateAfter),
lastUpdatedById: user.id,
versions: {
Expand All @@ -186,6 +188,7 @@ export class SecretService {
id: secretId
},
data: {
note: dto.note ?? secret.note,
name: dto.name ?? secret.name,
rotateAt: dto.rotateAfter ?? secret.rotateAt,
lastUpdatedById: user.id
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/variable/dto/create.variable/create.variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export class CreateVariable {
@IsString()
value: string

@IsString()
@IsOptional()
note: string

@IsNumber()
@IsOptional()
environmentId: string
Expand Down
5 changes: 4 additions & 1 deletion apps/api/src/variable/service/variable.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -176,6 +177,7 @@ export class VariableService {
},
data: {
name: dto.name,
note: dto.note,
lastUpdatedById: user.id,
versions: {
create: {
Expand All @@ -192,6 +194,7 @@ export class VariableService {
id: variableId
},
data: {
note: dto.note ?? variable.note,
name: dto.name ?? variable.name,
lastUpdatedById: user.id
}
Expand Down
10 changes: 8 additions & 2 deletions apps/api/src/variable/variable.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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)

Expand All @@ -238,6 +240,7 @@ describe('Variable Controller Tests', () => {
payload: {
name: 'Variable 2',
value: 'Variable 2 value',
note: 'Variable 2 note',
rotateAfter: '24'
},
headers: {
Expand All @@ -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)
})
Expand Down Expand Up @@ -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
Expand All @@ -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: {
Expand Down

0 comments on commit e9c9ac2

Please sign in to comment.