refactor: removing the workspace type entirely

This commit is contained in:
2026-07-04 11:47:36 +03:30
parent 8d962ea6ee
commit e57dd84ebc
13 changed files with 22 additions and 229 deletions
@@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class Taskmanager1783150480192 implements MigrationInterface {
name = 'Taskmanager1783150480192'
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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`);
}
}
@@ -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<TMWorkspaceType[]> {
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<TMWorkspaceType> {
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<TMWorkspaceType> {
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<TMWorkspaceType> {
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<TMWorkspaceType> {
return this.workspaceTypeService.remove(id);
}
}
@@ -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;
}
@@ -1,4 +0,0 @@
import { PartialType } from '@nestjs/swagger';
import { CreateWorkspaceTypeDto } from './create-workspace-type.dto';
export class UpdateWorkspaceTypeDto extends PartialType(CreateWorkspaceTypeDto) {}
@@ -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()
@@ -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[];
}
@@ -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"],
})
@@ -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<TMWorkspaceType[]> {
return this.workspaceTypeRepository.findAll();
}
async findOne(id: string): Promise<TMWorkspaceType> {
const workspaceType = await this.workspaceTypeRepository.findOneById(id);
if (!workspaceType) throw new NotFoundException(`WorkspaceType #${id} not found`);
return workspaceType;
}
async create(dto: CreateWorkspaceTypeDto): Promise<TMWorkspaceType> {
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<TMWorkspaceType> {
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<TMWorkspaceType> {
const workspaceType = await this.findOne(id);
await this.workspaceTypeRepository.delete(id);
return workspaceType;
}
}
@@ -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<User>,
) {}
@@ -28,10 +26,7 @@ export class WorkspaceService {
}
async create(dto: CreateWorkspaceDto): Promise<TMWorkspace> {
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<TMWorkspace> {
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);
@@ -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<TMWorkspaceType>,
) {}
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<TMWorkspaceType>) {
return this.repository.create(data);
}
save(workspaceType: TMWorkspaceType) {
return this.repository.save(workspaceType);
}
update(id: string, data: Partial<TMWorkspaceType>) {
return this.repository.update(id, data);
}
delete(id: string) {
return this.repository.delete(id);
}
}
@@ -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"],
});
}
@@ -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,