From a99c0db079f18bd76437c4bf23e08095b0635c41 Mon Sep 17 00:00:00 2001 From: Udit Namdev <35065474+unamdev0@users.noreply.github.com> Date: Mon, 16 Sep 2024 19:16:03 +0530 Subject: [PATCH] feat(api): Add icon and remove description field from workspace (#435) --- apps/api/src/common/workspace.ts | 2 +- apps/api/src/event/event.e2e.spec.ts | 24 ++++++------- .../migration.sql | 9 +++++ apps/api/src/prisma/schema.prisma | 2 +- .../workspace-membership.e2e.spec.ts | 8 ++--- .../dto/create.workspace/create.workspace.ts | 2 +- .../workspace/service/workspace.service.ts | 36 ++++++------------- apps/api/src/workspace/workspace.e2e.spec.ts | 24 ++++++------- .../api-client/src/types/workspace.types.d.ts | 6 ++-- packages/api-client/tests/workspace.spec.ts | 2 +- packages/schema/src/workspace.ts | 2 +- 11 files changed, 55 insertions(+), 62 deletions(-) create mode 100644 apps/api/src/prisma/migrations/20240915122629_add_icon_remove_description_from_workspace/migration.sql diff --git a/apps/api/src/common/workspace.ts b/apps/api/src/common/workspace.ts index ae298a68..767eb443 100644 --- a/apps/api/src/common/workspace.ts +++ b/apps/api/src/common/workspace.ts @@ -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, diff --git a/apps/api/src/event/event.e2e.spec.ts b/apps/api/src/event/event.e2e.spec.ts index 2bd7e705..c2baa4b7 100644 --- a/apps/api/src/event/event.e2e.spec.ts +++ b/apps/api/src/event/event.e2e.spec.ts @@ -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() @@ -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, { @@ -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, { @@ -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, { @@ -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, { @@ -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, { @@ -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({ @@ -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({ @@ -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({ @@ -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 { @@ -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 { @@ -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 { diff --git a/apps/api/src/prisma/migrations/20240915122629_add_icon_remove_description_from_workspace/migration.sql b/apps/api/src/prisma/migrations/20240915122629_add_icon_remove_description_from_workspace/migration.sql new file mode 100644 index 00000000..dd48e54f --- /dev/null +++ b/apps/api/src/prisma/migrations/20240915122629_add_icon_remove_description_from_workspace/migration.sql @@ -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; diff --git a/apps/api/src/prisma/schema.prisma b/apps/api/src/prisma/schema.prisma index db9dc1c7..5aaa434c 100644 --- a/apps/api/src/prisma/schema.prisma +++ b/apps/api/src/prisma/schema.prisma @@ -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? diff --git a/apps/api/src/workspace-membership/workspace-membership.e2e.spec.ts b/apps/api/src/workspace-membership/workspace-membership.e2e.spec.ts index 9a28da49..01954cff 100644 --- a/apps/api/src/workspace-membership/workspace-membership.e2e.spec.ts +++ b/apps/api/src/workspace-membership/workspace-membership.e2e.spec.ts @@ -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({ @@ -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 @@ -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 @@ -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 diff --git a/apps/api/src/workspace/dto/create.workspace/create.workspace.ts b/apps/api/src/workspace/dto/create.workspace/create.workspace.ts index 71f81dba..5be165a3 100644 --- a/apps/api/src/workspace/dto/create.workspace/create.workspace.ts +++ b/apps/api/src/workspace/dto/create.workspace/create.workspace.ts @@ -7,5 +7,5 @@ export class CreateWorkspace { @IsString() @IsOptional() - description?: string + icon?: string } diff --git a/apps/api/src/workspace/service/workspace.service.ts b/apps/api/src/workspace/service/workspace.service.ts index 4daea549..a13c2538 100644 --- a/apps/api/src/workspace/service/workspace.service.ts +++ b/apps/api/src/workspace/service/workspace.service.ts @@ -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 @@ -210,18 +210,10 @@ export class WorkspaceService { userId: user.id } }, - OR: [ - { - name: { - contains: search - } - }, - { - description: { - contains: search - } - } - ] + + name: { + contains: search + } } }) @@ -233,18 +225,10 @@ export class WorkspaceService { userId: user.id } }, - OR: [ - { - name: { - contains: search - } - }, - { - description: { - contains: search - } - } - ] + + name: { + contains: search + } } }) @@ -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({ diff --git a/apps/api/src/workspace/workspace.e2e.spec.ts b/apps/api/src/workspace/workspace.e2e.spec.ts index 098452cb..ce019d1b 100644 --- a/apps/api/src/workspace/workspace.e2e.spec.ts +++ b/apps/api/src/workspace/workspace.e2e.spec.ts @@ -192,7 +192,7 @@ describe('Workspace Controller Tests', () => { url: '/workspace', payload: { name: 'Workspace 1', - description: 'Workspace 1 description' + icon: '🤓' } }) @@ -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) @@ -216,7 +216,7 @@ describe('Workspace Controller Tests', () => { url: '/workspace', payload: { name: 'My Workspace', - description: 'My Workspace description' + icon: '🤓' } }) @@ -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({ @@ -242,7 +242,7 @@ describe('Workspace Controller Tests', () => { url: '/workspace', payload: { name: 'Workspace 1', - description: 'Workspace 1 description' + icon: '🤓' } }) @@ -250,7 +250,7 @@ describe('Workspace Controller Tests', () => { 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) @@ -321,7 +321,7 @@ describe('Workspace Controller Tests', () => { url: `/workspace/${workspace1.slug}`, payload: { name: 'Workspace 1 Updated', - description: 'Workspace 1 updated description' + icon: '🔥' } }) @@ -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 () => { @@ -362,7 +362,7 @@ describe('Workspace Controller Tests', () => { url: `/workspace/${workspace1.slug}`, payload: { name: 'Workspace 1 Updated', - description: 'Workspace 1 updated description' + icon: '🤓' } }) @@ -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( @@ -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) }) @@ -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({ diff --git a/packages/api-client/src/types/workspace.types.d.ts b/packages/api-client/src/types/workspace.types.d.ts index 9def521d..b9c190a1 100644 --- a/packages/api-client/src/types/workspace.types.d.ts +++ b/packages/api-client/src/types/workspace.types.d.ts @@ -4,7 +4,7 @@ interface Workspace { id: string name: string slug: string - description: string + icon: string isFreeTier: boolean createdAt: string updatedAt: string @@ -15,7 +15,7 @@ interface Workspace { export interface CreateWorkspaceRequest { name: string - description?: string + icon?: string } export interface CreateWorkspaceResponse extends Workspace {} @@ -50,7 +50,7 @@ export interface ExportDataRequest { export interface ExportDataResponse { name: string - description: string + icon: string workspaceRoles: { name: string description: string diff --git a/packages/api-client/tests/workspace.spec.ts b/packages/api-client/tests/workspace.spec.ts index a961ab77..3608fc24 100644 --- a/packages/api-client/tests/workspace.spec.ts +++ b/packages/api-client/tests/workspace.spec.ts @@ -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 diff --git a/packages/schema/src/workspace.ts b/packages/schema/src/workspace.ts index 88d2e6c5..7164eee5 100644 --- a/packages/schema/src/workspace.ts +++ b/packages/schema/src/workspace.ts @@ -2,7 +2,7 @@ import { z } from 'zod' export const CreateWorkspaceSchema = z.object({ name: z.string(), - description: z.string().optional(), + icon: z.string().optional(), isDefault: z.boolean().optional() })