From e57dd84ebcf0d1861243ef167e3f7e04dc1c3de0 Mon Sep 17 00:00:00 2001 From: realrafi Date: Sat, 4 Jul 2026 11:47:36 +0330 Subject: [PATCH] refactor: removing the workspace type entirely --- .../migrations/1783150384434-taskmanager.ts | 0 .../migrations/1783150480192-taskmanager.ts | 16 ++++++ .../controllers/workspace-type.controller.ts | 55 ------------------- .../create-workspace-type.dto.ts | 25 --------- .../update-workspace-type.dto.ts | 4 -- .../dto/workspace/create-workspace.dto.ts | 5 -- .../entities/workspace-type.entity.ts | 20 ------- .../task-manager/entities/workspace.entity.ts | 10 +--- .../providers/workspace-type.service.ts | 47 ---------------- .../providers/workspace.service.ts | 14 +---- .../repositories/workspace-type.repository.ts | 42 -------------- .../repositories/workspace.repository.ts | 4 +- .../task-manager/task-manager.module.ts | 9 +-- 13 files changed, 22 insertions(+), 229 deletions(-) create mode 100644 database/migrations/1783150384434-taskmanager.ts create mode 100644 database/migrations/1783150480192-taskmanager.ts delete mode 100644 src/modules/task-manager/controllers/workspace-type.controller.ts delete mode 100644 src/modules/task-manager/dto/workspace-type/create-workspace-type.dto.ts delete mode 100644 src/modules/task-manager/dto/workspace-type/update-workspace-type.dto.ts delete mode 100644 src/modules/task-manager/entities/workspace-type.entity.ts delete mode 100644 src/modules/task-manager/providers/workspace-type.service.ts delete mode 100644 src/modules/task-manager/repositories/workspace-type.repository.ts diff --git a/database/migrations/1783150384434-taskmanager.ts b/database/migrations/1783150384434-taskmanager.ts new file mode 100644 index 0000000..e69de29 diff --git a/database/migrations/1783150480192-taskmanager.ts b/database/migrations/1783150480192-taskmanager.ts new file mode 100644 index 0000000..5627d12 --- /dev/null +++ b/database/migrations/1783150480192-taskmanager.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Taskmanager1783150480192 implements MigrationInterface { + name = 'Taskmanager1783150480192' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "tm_workspaces" DROP CONSTRAINT "FK_253e36f065cfc1eca58abaefb22"`); + await queryRunner.query(`ALTER TABLE "tm_workspaces" DROP COLUMN "workspaceTypeId"`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "tm_workspaces" ADD "workspaceTypeId" uuid NOT NULL`); + await queryRunner.query(`ALTER TABLE "tm_workspaces" ADD CONSTRAINT "FK_253e36f065cfc1eca58abaefb22" FOREIGN KEY ("workspaceTypeId") REFERENCES "tm_workspace_types"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +} diff --git a/src/modules/task-manager/controllers/workspace-type.controller.ts b/src/modules/task-manager/controllers/workspace-type.controller.ts deleted file mode 100644 index 8b7e9bf..0000000 --- a/src/modules/task-manager/controllers/workspace-type.controller.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Controller, Get, Post, Patch, Delete, Param, Body } from "@nestjs/common"; -import { ApiTags, ApiOperation, ApiResponse, ApiParam } from "@nestjs/swagger"; -import { WorkspaceTypeService } from "../providers/workspace-type.service"; -import { CreateWorkspaceTypeDto } from "../dto/workspace-type/create-workspace-type.dto"; -import { UpdateWorkspaceTypeDto } from "../dto/workspace-type/update-workspace-type.dto"; -import { TMWorkspaceType } from "../entities/workspace-type.entity"; - -@ApiTags("Task Manager") -@Controller("task-manager/workspace-types") -export class WorkspaceTypeController { - constructor(private readonly workspaceTypeService: WorkspaceTypeService) {} - - @Get() - @ApiOperation({ summary: "Get all workspace types" }) - @ApiResponse({ status: 200, description: "List of workspace types", type: [TMWorkspaceType] }) - findAll(): Promise { - return this.workspaceTypeService.findAll(); - } - - @Get(":id") - @ApiOperation({ summary: "Get a workspace type by ID" }) - @ApiParam({ name: "id", description: "WorkspaceType ID" }) - @ApiResponse({ status: 200, description: "WorkspaceType found", type: TMWorkspaceType }) - @ApiResponse({ status: 404, description: "WorkspaceType not found" }) - findOne(@Param("id") id: string): Promise { - return this.workspaceTypeService.findOne(id); - } - - @Post() - @ApiOperation({ summary: "Create a new workspace type" }) - @ApiResponse({ status: 201, description: "WorkspaceType created", type: TMWorkspaceType }) - @ApiResponse({ status: 409, description: "WorkspaceType with this name already exists" }) - create(@Body() body: CreateWorkspaceTypeDto): Promise { - return this.workspaceTypeService.create(body); - } - - @Patch(":id") - @ApiOperation({ summary: "Update a workspace type" }) - @ApiParam({ name: "id", description: "WorkspaceType ID" }) - @ApiResponse({ status: 200, description: "WorkspaceType updated", type: TMWorkspaceType }) - @ApiResponse({ status: 404, description: "WorkspaceType not found" }) - @ApiResponse({ status: 409, description: "WorkspaceType with this name already exists" }) - update(@Param("id") id: string, @Body() body: UpdateWorkspaceTypeDto): Promise { - return this.workspaceTypeService.update(id, body); - } - - @Delete(":id") - @ApiOperation({ summary: "Delete a workspace type" }) - @ApiParam({ name: "id", description: "WorkspaceType ID" }) - @ApiResponse({ status: 200, description: "WorkspaceType deleted" }) - @ApiResponse({ status: 404, description: "WorkspaceType not found" }) - remove(@Param("id") id: string): Promise { - return this.workspaceTypeService.remove(id); - } -} diff --git a/src/modules/task-manager/dto/workspace-type/create-workspace-type.dto.ts b/src/modules/task-manager/dto/workspace-type/create-workspace-type.dto.ts deleted file mode 100644 index d0d28c4..0000000 --- a/src/modules/task-manager/dto/workspace-type/create-workspace-type.dto.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsOptional, IsInt, IsNotEmpty, MaxLength, Min } from "class-validator"; - -export class CreateWorkspaceTypeDto { - @ApiProperty({ description: "Name of the workspace type", example: "Engineering" }) - @IsString() - @IsNotEmpty() - @MaxLength(100) - name: string; - - @ApiProperty({ - description: "Description of the workspace type", - required: false, - example: "Workspace type for engineering related work", - }) - @IsString() - @IsOptional() - description?: string; - - @ApiProperty({ description: "Display order of the workspace type", example: 1 }) - @IsInt() - @IsNotEmpty() - @Min(0) - order: number; -} diff --git a/src/modules/task-manager/dto/workspace-type/update-workspace-type.dto.ts b/src/modules/task-manager/dto/workspace-type/update-workspace-type.dto.ts deleted file mode 100644 index cc4a3ea..0000000 --- a/src/modules/task-manager/dto/workspace-type/update-workspace-type.dto.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { PartialType } from '@nestjs/swagger'; -import { CreateWorkspaceTypeDto } from './create-workspace-type.dto'; - -export class UpdateWorkspaceTypeDto extends PartialType(CreateWorkspaceTypeDto) {} \ No newline at end of file diff --git a/src/modules/task-manager/dto/workspace/create-workspace.dto.ts b/src/modules/task-manager/dto/workspace/create-workspace.dto.ts index 0efdb4b..99c8bf5 100644 --- a/src/modules/task-manager/dto/workspace/create-workspace.dto.ts +++ b/src/modules/task-manager/dto/workspace/create-workspace.dto.ts @@ -8,11 +8,6 @@ export class CreateWorkspaceDto { @MaxLength(100) name: string; - @ApiProperty({ description: "ID of the workspace type", example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890" }) - @IsUUID() - @IsNotEmpty() - workspaceTypeId: string; - @ApiProperty({ description: "Description of the workspace", required: false, example: "Workspace for the engineering team" }) @IsString() @IsOptional() diff --git a/src/modules/task-manager/entities/workspace-type.entity.ts b/src/modules/task-manager/entities/workspace-type.entity.ts deleted file mode 100644 index b840242..0000000 --- a/src/modules/task-manager/entities/workspace-type.entity.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Column, Entity, OneToMany } from "typeorm"; -import { BaseEntity } from "../../../common/entities/base.entity"; -import { TMWorkspace } from "./workspace.entity"; - -@Entity("tm_workspace_types") -export class TMWorkspaceType extends BaseEntity { - @Column({ type: "varchar", length: 100, unique: true }) - name: string; - - @Column({ type: "text", nullable: true }) - description: string; - - @Column({ type: "int", default: 0 }) - order: number; - - // --- Relations --- - - @OneToMany(() => TMWorkspace, (workspace) => workspace.workspaceType) - workspaces: TMWorkspace[]; -} diff --git a/src/modules/task-manager/entities/workspace.entity.ts b/src/modules/task-manager/entities/workspace.entity.ts index c63366d..417c1fd 100644 --- a/src/modules/task-manager/entities/workspace.entity.ts +++ b/src/modules/task-manager/entities/workspace.entity.ts @@ -1,6 +1,5 @@ -import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany } from "typeorm"; +import { Column, Entity, JoinTable, ManyToMany, OneToMany } from "typeorm"; import { BaseEntity } from "../../../common/entities/base.entity"; -import { TMWorkspaceType } from "./workspace-type.entity"; import { TMProject } from "./project.entity"; import { User } from "../../users/entities/user.entity"; @@ -20,13 +19,6 @@ export class TMWorkspace extends BaseEntity { // --- Relations --- - @ManyToOne(() => TMWorkspaceType, { nullable: false, eager: true }) - @JoinColumn({ name: "workspaceTypeId" }) - workspaceType: TMWorkspaceType; - - @Column({ type: "uuid" }) - workspaceTypeId: string; - @OneToMany(() => TMProject, (project) => project.workspace, { cascade: ["insert", "update"], }) diff --git a/src/modules/task-manager/providers/workspace-type.service.ts b/src/modules/task-manager/providers/workspace-type.service.ts deleted file mode 100644 index 1e0f0ed..0000000 --- a/src/modules/task-manager/providers/workspace-type.service.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Injectable, NotFoundException, ConflictException } from "@nestjs/common"; -import { WorkspaceTypeRepository } from "../repositories/workspace-type.repository"; -import { TMWorkspaceType } from "../entities/workspace-type.entity"; -import { CreateWorkspaceTypeDto } from "../dto/workspace-type/create-workspace-type.dto"; -import { UpdateWorkspaceTypeDto } from "../dto/workspace-type/update-workspace-type.dto"; - -@Injectable() -export class WorkspaceTypeService { - constructor(private readonly workspaceTypeRepository: WorkspaceTypeRepository) {} - - findAll(): Promise { - return this.workspaceTypeRepository.findAll(); - } - - async findOne(id: string): Promise { - const workspaceType = await this.workspaceTypeRepository.findOneById(id); - if (!workspaceType) throw new NotFoundException(`WorkspaceType #${id} not found`); - return workspaceType; - } - - async create(dto: CreateWorkspaceTypeDto): Promise { - const existing = await this.workspaceTypeRepository.findOneByName(dto.name); - if (existing) throw new ConflictException(`WorkspaceType with name "${dto.name}" already exists`); - - const workspaceType = this.workspaceTypeRepository.create(dto); - return this.workspaceTypeRepository.save(workspaceType); - } - - async update(id: string, dto: UpdateWorkspaceTypeDto): Promise { - await this.findOne(id); - - if (dto.name) { - const existing = await this.workspaceTypeRepository.findOneByName(dto.name); - if (existing && existing.id !== id) throw new ConflictException(`WorkspaceType with name "${dto.name}" already exists`); - } - - await this.workspaceTypeRepository.update(id, dto); - return this.findOne(id); - } - - async remove(id: string): Promise { - const workspaceType = await this.findOne(id); - await this.workspaceTypeRepository.delete(id); - - return workspaceType; - } -} diff --git a/src/modules/task-manager/providers/workspace.service.ts b/src/modules/task-manager/providers/workspace.service.ts index 06e68f4..5e90079 100644 --- a/src/modules/task-manager/providers/workspace.service.ts +++ b/src/modules/task-manager/providers/workspace.service.ts @@ -6,13 +6,11 @@ import { TMWorkspace } from "../entities/workspace.entity"; import { CreateWorkspaceDto } from "../dto/workspace/create-workspace.dto"; import { UpdateWorkspaceDto } from "../dto/workspace/update-workspace.dto"; import { User } from "../../users/entities/user.entity"; -import { WorkspaceTypeRepository } from "../repositories/workspace-type.repository"; @Injectable() export class WorkspaceService { constructor( private readonly workspaceRepository: WorkspaceRepository, - private readonly workspaceTypeRepository: WorkspaceTypeRepository, @InjectRepository(User) private readonly userRepository: Repository, ) {} @@ -28,10 +26,7 @@ export class WorkspaceService { } async create(dto: CreateWorkspaceDto): Promise { - const { userIds, workspaceTypeId, ...rest } = dto; - - const workspaceType = await this.workspaceTypeRepository.findOneById(workspaceTypeId); - if (!workspaceType) throw new NotFoundException(`WorkSpaceType #${workspaceTypeId} not found!`); + const { userIds, ...rest } = dto; const workspace = this.workspaceRepository.create(rest); @@ -44,12 +39,7 @@ export class WorkspaceService { async update(id: string, dto: UpdateWorkspaceDto): Promise { const workspace = await this.findOneOrFail(id); - const { userIds, workspaceTypeId, ...rest } = dto; - - if (workspaceTypeId) { - const workspaceType = await this.workspaceTypeRepository.findOneById(workspaceTypeId); - if (!workspaceType) throw new NotFoundException(`WorkSpaceType #${workspaceTypeId} not found!`); - } + const { userIds, ...rest } = dto; Object.assign(workspace, rest); diff --git a/src/modules/task-manager/repositories/workspace-type.repository.ts b/src/modules/task-manager/repositories/workspace-type.repository.ts deleted file mode 100644 index bfd0c85..0000000 --- a/src/modules/task-manager/repositories/workspace-type.repository.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Injectable } from "@nestjs/common"; -import { InjectRepository } from "@nestjs/typeorm"; -import { Repository } from "typeorm"; -import { TMWorkspaceType } from "../entities/workspace-type.entity"; - -@Injectable() -export class WorkspaceTypeRepository { - constructor( - @InjectRepository(TMWorkspaceType) - private readonly repository: Repository, - ) {} - - findAll() { - return this.repository.find({ - order: { order: "ASC" }, - }); - } - - findOneById(id: string) { - return this.repository.findOne({ where: { id } }); - } - - findOneByName(name: string) { - return this.repository.findOne({ where: { name } }); - } - - create(data: Partial) { - return this.repository.create(data); - } - - save(workspaceType: TMWorkspaceType) { - return this.repository.save(workspaceType); - } - - update(id: string, data: Partial) { - return this.repository.update(id, data); - } - - delete(id: string) { - return this.repository.delete(id); - } -} diff --git a/src/modules/task-manager/repositories/workspace.repository.ts b/src/modules/task-manager/repositories/workspace.repository.ts index fd38d40..175678a 100644 --- a/src/modules/task-manager/repositories/workspace.repository.ts +++ b/src/modules/task-manager/repositories/workspace.repository.ts @@ -12,14 +12,14 @@ export class WorkspaceRepository { findAll() { return this.repository.find({ - relations: ["workspaceType", "projects", "users"], + relations: ["projects", "users"], }); } findOneById(id: string) { return this.repository.findOne({ where: { id }, - relations: ["workspaceType", "projects", "users"], + relations: ["projects", "users"], }); } diff --git a/src/modules/task-manager/task-manager.module.ts b/src/modules/task-manager/task-manager.module.ts index e6de5b0..43bbb5b 100644 --- a/src/modules/task-manager/task-manager.module.ts +++ b/src/modules/task-manager/task-manager.module.ts @@ -1,7 +1,6 @@ import { Module } from "@nestjs/common"; import { TypeOrmModule } from "@nestjs/typeorm"; -import { TMWorkspaceType } from "./entities/workspace-type.entity"; import { TMWorkspace } from "./entities/workspace.entity"; import { TMProject } from "./entities/project.entity"; import { TMTaskPhase } from "./entities/task-phase.entity"; @@ -13,9 +12,6 @@ import { WorkspaceRepository } from "./repositories/workspace.repository"; import { WorkspaceController } from "./controllers/workspace.controller"; import { WorkspaceService } from "./providers/workspace.service"; import { User } from "../users/entities/user.entity"; -import { WorkspaceTypeService } from "./providers/workspace-type.service"; -import { WorkspaceTypeRepository } from "./repositories/workspace-type.repository"; -import { WorkspaceTypeController } from "./controllers/workspace-type.controller"; import { ProjectController } from "./controllers/project.controller"; import { ProjectRepository } from "./repositories/project.repository"; import { ProjectService } from "./providers/project.service"; @@ -37,11 +33,10 @@ import { AttachmentService } from "./providers/attachment.service"; @Module({ imports: [ - TypeOrmModule.forFeature([TMWorkspaceType, TMWorkspace, TMProject, TMTaskPhase, TMTask, TMRemark, TMAttachment, TMCheckListItem, User]), + TypeOrmModule.forFeature([TMWorkspace, TMProject, TMTaskPhase, TMTask, TMRemark, TMAttachment, TMCheckListItem, User]), ], controllers: [ WorkspaceController, - WorkspaceTypeController, ProjectController, TaskPhaseController, TaskController, @@ -52,8 +47,6 @@ import { AttachmentService } from "./providers/attachment.service"; providers: [ WorkspaceRepository, WorkspaceService, - WorkspaceTypeRepository, - WorkspaceTypeService, ProjectRepository, ProjectService, TaskPhaseRepository,