Skip to content

Commit

Permalink
feat(api): Add icon and remove description field from workspace (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
unamdev0 authored Sep 16, 2024
1 parent 0c9e50a commit a99c0db
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 62 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/common/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createWorkspace = async (
id: workspaceId,
slug: await generateEntitySlug(dto.name, 'WORKSPACE', prisma),
name: dto.name,
description: dto.description,
icon: dto.icon,
isFreeTier: true,
ownerId: user.id,
isDefault,
Expand Down
24 changes: 12 additions & 12 deletions apps/api/src/event/event.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('Event Controller Tests', () => {
it('should be able to fetch a workspace event', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

expect(workspace).toBeDefined()
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('Event Controller Tests', () => {
it('should be able to fetch a project event', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

const project = (await projectService.createProject(user, workspace.slug, {
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('Event Controller Tests', () => {
it('should be able to fetch an environment event', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

const project = await projectService.createProject(user, workspace.slug, {
Expand Down Expand Up @@ -261,7 +261,7 @@ describe('Event Controller Tests', () => {
it('should be able to fetch a secret event', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

const project = await projectService.createProject(user, workspace.slug, {
Expand Down Expand Up @@ -340,7 +340,7 @@ describe('Event Controller Tests', () => {
it('should be able to fetch a variable event', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

const project = await projectService.createProject(user, workspace.slug, {
Expand Down Expand Up @@ -419,7 +419,7 @@ describe('Event Controller Tests', () => {
it('should be able to fetch a workspace role event', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

const project = await projectService.createProject(user, workspace.slug, {
Expand Down Expand Up @@ -485,7 +485,7 @@ describe('Event Controller Tests', () => {
it('should be able to fetch all events', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

const response = await app.inject({
Expand Down Expand Up @@ -518,7 +518,7 @@ describe('Event Controller Tests', () => {
it('should throw an error with wrong severity value', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

const response = await app.inject({
Expand All @@ -535,7 +535,7 @@ describe('Event Controller Tests', () => {
it('should throw an error with wrong source value', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

const response = await app.inject({
Expand All @@ -552,7 +552,7 @@ describe('Event Controller Tests', () => {
it('should throw an error if user is not provided in event creation for user-triggered event', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

try {
Expand All @@ -577,7 +577,7 @@ describe('Event Controller Tests', () => {
it('should throw an exception for invalid event source', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

try {
Expand All @@ -602,7 +602,7 @@ describe('Event Controller Tests', () => {
it('should throw an exception for invalid event type', async () => {
const workspace = await workspaceService.createWorkspace(user, {
name: 'My workspace',
description: 'Some description'
icon: '🤓'
})

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:
- You are about to drop the column `description` on the `Workspace` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Workspace" DROP COLUMN "description",
ADD COLUMN "icon" TEXT;
2 changes: 1 addition & 1 deletion apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,12 @@ model Workspace {
id String @id @default(cuid())
name String
slug String @unique
description String?
isFreeTier Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ownerId String
isDefault Boolean @default(false)
icon String?
lastUpdatedBy User? @relation(fields: [lastUpdatedById], references: [id], onUpdate: Cascade, onDelete: SetNull)
lastUpdatedById String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe('Workspace Membership Controller Tests', () => {
it('should not be able to transfer ownership to a non member', async () => {
const newWorkspace = await workspaceService.createWorkspace(user1, {
name: 'Workspace 2',
description: 'Workspace 2 description'
icon: '🤓'
})

const response = await app.inject({
Expand All @@ -241,7 +241,7 @@ describe('Workspace Membership Controller Tests', () => {
it('should not be able to transfer ownership to a member who did not accept the invitation', async () => {
const newWorkspace = await workspaceService.createWorkspace(user1, {
name: 'Workspace 2',
description: 'Workspace 2 description'
icon: '🤓'
})

// Create membership
Expand All @@ -265,7 +265,7 @@ describe('Workspace Membership Controller Tests', () => {
it('should be able to transfer the ownership of the workspace', async () => {
const newWorkspace = await workspaceService.createWorkspace(user1, {
name: 'Workspace 2',
description: 'Workspace 2 description'
icon: '🤓'
})

// Create membership
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('Workspace Membership Controller Tests', () => {
it('should not be able to transfer ownership if is not admin', async () => {
const newWorkspace = await workspaceService.createWorkspace(user1, {
name: 'Workspace 2',
description: 'Workspace 2 description'
icon: '🤓'
})

// Create membership
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export class CreateWorkspace {

@IsString()
@IsOptional()
description?: string
icon?: string
}
36 changes: 10 additions & 26 deletions apps/api/src/workspace/service/workspace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class WorkspaceService {
slug: dto.name
? await generateEntitySlug(dto.name, 'WORKSPACE', this.prisma)
: undefined,
description: dto.description,
icon: dto.icon,
lastUpdatedBy: {
connect: {
id: user.id
Expand Down Expand Up @@ -210,18 +210,10 @@ export class WorkspaceService {
userId: user.id
}
},
OR: [
{
name: {
contains: search
}
},
{
description: {
contains: search
}
}
]

name: {
contains: search
}
}
})

Expand All @@ -233,18 +225,10 @@ export class WorkspaceService {
userId: user.id
}
},
OR: [
{
name: {
contains: search
}
},
{
description: {
contains: search
}
}
]

name: {
contains: search
}
}
})

Expand Down Expand Up @@ -281,7 +265,7 @@ export class WorkspaceService {
const data: any = {}

data.name = workspace.name
data.description = workspace.description
data.icon = workspace.icon

// Get all the roles of the workspace
data.workspaceRoles = await this.prisma.workspaceRole.findMany({
Expand Down
24 changes: 12 additions & 12 deletions apps/api/src/workspace/workspace.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('Workspace Controller Tests', () => {
url: '/workspace',
payload: {
name: 'Workspace 1',
description: 'Workspace 1 description'
icon: '🤓'
}
})

Expand All @@ -201,7 +201,7 @@ describe('Workspace Controller Tests', () => {

expect(body.name).toBe('Workspace 1')
expect(body.slug).toBeDefined()
expect(body.description).toBe('Workspace 1 description')
expect(body.icon).toBe('🤓')
expect(body.ownerId).toBe(user1.id)
expect(body.isFreeTier).toBe(true)
expect(body.isDefault).toBe(false)
Expand All @@ -216,7 +216,7 @@ describe('Workspace Controller Tests', () => {
url: '/workspace',
payload: {
name: 'My Workspace',
description: 'My Workspace description'
icon: '🤓'
}
})

Expand All @@ -231,7 +231,7 @@ describe('Workspace Controller Tests', () => {
it('should let other user to create workspace with same name', async () => {
await workspaceService.createWorkspace(user1, {
name: 'Workspace 1',
description: 'Workspace 1 description'
icon: '🤓'
})

const response = await app.inject({
Expand All @@ -242,15 +242,15 @@ describe('Workspace Controller Tests', () => {
url: '/workspace',
payload: {
name: 'Workspace 1',
description: 'Workspace 1 description'
icon: '🤓'
}
})

expect(response.statusCode).toBe(201)
workspace2 = response.json()

expect(workspace2.name).toBe('Workspace 1')
expect(workspace2.description).toBe('Workspace 1 description')
expect(workspace2.icon).toBe('🤓')
expect(workspace2.ownerId).toBe(user2.id)
expect(workspace2.isFreeTier).toBe(true)
expect(workspace2.isDefault).toBe(false)
Expand Down Expand Up @@ -321,7 +321,7 @@ describe('Workspace Controller Tests', () => {
url: `/workspace/${workspace1.slug}`,
payload: {
name: 'Workspace 1 Updated',
description: 'Workspace 1 updated description'
icon: '🔥'
}
})

Expand All @@ -330,7 +330,7 @@ describe('Workspace Controller Tests', () => {

expect(body.name).toBe('Workspace 1 Updated')
expect(body.slug).not.toBe(workspace1.slug)
expect(body.description).toBe('Workspace 1 updated description')
expect(body.icon).toBe('🔥')
})

it('should not be able to change the name to an existing workspace or same name', async () => {
Expand Down Expand Up @@ -362,7 +362,7 @@ describe('Workspace Controller Tests', () => {
url: `/workspace/${workspace1.slug}`,
payload: {
name: 'Workspace 1 Updated',
description: 'Workspace 1 updated description'
icon: '🤓'
}
})

Expand All @@ -371,7 +371,7 @@ describe('Workspace Controller Tests', () => {

it('should have created a WORKSPACE_UPDATED event', async () => {
await workspaceService.updateWorkspace(user1, workspace1.slug, {
description: 'Workspace 1 Description'
icon: '🤓'
})

const response = await fetchEvents(
Expand Down Expand Up @@ -526,7 +526,7 @@ describe('Workspace Controller Tests', () => {
const body = response.json()

expect(body.name).toEqual(workspace1.name)
expect(body.description).toEqual(workspace1.description)
expect(body.icon).toEqual(workspace1.icon)
expect(body.workspaceRoles).toBeInstanceOf(Array)
expect(body.projects).toBeInstanceOf(Array)
})
Expand All @@ -536,7 +536,7 @@ describe('Workspace Controller Tests', () => {
it('should be able to delete the workspace', async () => {
const newWorkspace = await workspaceService.createWorkspace(user1, {
name: 'Workspace 2',
description: 'Workspace 2 description'
icon: '🤓'
})

const response = await app.inject({
Expand Down
6 changes: 3 additions & 3 deletions packages/api-client/src/types/workspace.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface Workspace {
id: string
name: string
slug: string
description: string
icon: string
isFreeTier: boolean
createdAt: string
updatedAt: string
Expand All @@ -15,7 +15,7 @@ interface Workspace {

export interface CreateWorkspaceRequest {
name: string
description?: string
icon?: string
}

export interface CreateWorkspaceResponse extends Workspace {}
Expand Down Expand Up @@ -50,7 +50,7 @@ export interface ExportDataRequest {

export interface ExportDataResponse {
name: string
description: string
icon: string
workspaceRoles: {
name: string
description: string
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/tests/workspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Workspaces Controller Tests', () => {
await workspaceController.createWorkspace(
{
name: 'New Workspace',
description: 'This is a new workspace'
icon: '🤓'
},
{
'x-e2e-user-email': email
Expand Down
Loading

0 comments on commit a99c0db

Please sign in to comment.