adding entities for taskmanager

This commit is contained in:
2026-06-29 16:43:17 +03:30
parent 53090153fb
commit e728303d53
18 changed files with 507 additions and 44 deletions
@@ -0,0 +1,25 @@
import { IsString, IsOptional, IsBoolean, IsNotEmpty, IsUUID, MaxLength } from "class-validator";
export class CreateWorkspaceDto {
@IsString()
@IsNotEmpty()
@MaxLength(100)
name: string;
@IsString()
@IsOptional()
description?: string;
@IsString()
@IsNotEmpty()
@MaxLength(20)
color: string;
@IsBoolean()
@IsOptional()
isActive?: boolean;
@IsUUID()
@IsNotEmpty()
workspaceTypeId: string;
}
@@ -0,0 +1,4 @@
import { PartialType } from "@nestjs/mapped-types";
import { CreateWorkspaceDto } from "./create-workspace.dto";
export class UpdateWorkspaceDto extends PartialType(CreateWorkspaceDto) {}
@@ -0,0 +1,33 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
} from 'typeorm';
import { BaseEntity } from '../../../common/entities/base.entity';
import { TMTask } from './task.entity';
import { TMAttachmentType } from '../enums/attachment-type.enum';
@Entity('tm_attachments')
export class TMAttachment extends BaseEntity {
@Column({ type: 'varchar', length: 150 })
title: string;
@Column({ type: 'enum', enum: TMAttachmentType })
type: TMAttachmentType;
@Column({ type: 'text' })
file: string;
// --- Relations ---
@ManyToOne(() => TMTask, (task) => task.attachments, {
nullable: false,
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'taskId' })
task: TMTask;
@Column({ type: 'uuid' })
taskId: string;
}
@@ -0,0 +1,24 @@
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
import { BaseEntity } from "../../../common/entities/base.entity";
import { TMTask } from "./task.entity";
@Entity("tm_check_list_items")
export class TMCheckListItem extends BaseEntity {
@Column({ type: "varchar", length: 150 })
title: string;
@Column({ type: "boolean", default: false })
isDone: boolean;
// --- Relations ---
@ManyToOne(() => TMTask, (task) => task.checkListItems, {
nullable: false,
onDelete: "CASCADE",
})
@JoinColumn({ name: "taskId" })
task: TMTask;
@Column({ type: "uuid" })
taskId: string;
}
@@ -0,0 +1,36 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from "typeorm";
import { BaseEntity } from "../../../common/entities/base.entity";
import { TMWorkspace } from "./workspace.entity";
import { TMTaskPhase } from "./task-phase.entity";
@Entity("tm_projects")
export class TMProject extends BaseEntity {
@Column({ type: "varchar", length: 150 })
name: string;
@Column({ type: "varchar", length: 150, nullable: true })
ownerName: string;
@Column({ type: "text", nullable: true })
description: string;
@Column({ type: "timestamptz", nullable: true })
startDate: Date;
// --- Relations ---
@ManyToOne(() => TMWorkspace, (workspace) => workspace.projects, {
nullable: false,
onDelete: "RESTRICT",
})
@JoinColumn({ name: "workspaceId" })
workspace: TMWorkspace;
@Column({ type: "uuid" })
workspaceId: string;
@OneToMany(() => TMTaskPhase, (taskPhase) => taskPhase.project, {
cascade: ["insert", "update"],
})
taskPhases: TMTaskPhase[];
}
@@ -0,0 +1,24 @@
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
import { BaseEntity } from "../../../common/entities/base.entity";
import { TMTask } from "./task.entity";
@Entity("tm_remarks")
export class TMRemark extends BaseEntity {
@Column({ type: "varchar", length: 150 })
title: string;
@Column({ type: "varchar", length: 20, nullable: true })
color: string;
// --- Relations ---
@ManyToOne(() => TMTask, (task) => task.remarks, {
nullable: false,
onDelete: "CASCADE",
})
@JoinColumn({ name: "taskId" })
task: TMTask;
@Column({ type: "uuid" })
taskId: string;
}
@@ -0,0 +1,33 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from "typeorm";
import { BaseEntity } from "../../../common/entities/base.entity";
import { TMProject } from "./project.entity";
import { TMTask } from "./task.entity";
@Entity("tm_task_phases")
export class TMTaskPhase extends BaseEntity {
@Column({ type: "varchar", length: 100 })
name: string;
@Column({ type: "int", default: 0 })
order: number;
@Column({ type: "varchar", length: 20, nullable: true })
color: string;
// --- Relations ---
@ManyToOne(() => TMProject, (project) => project.taskPhases, {
nullable: false,
onDelete: "CASCADE",
})
@JoinColumn({ name: "projectId" })
project: TMProject;
@Column({ type: "uuid" })
projectId: string;
@OneToMany(() => TMTask, (task) => task.taskPhase, {
cascade: ["insert", "update"],
})
tasks: TMTask[];
}
@@ -0,0 +1,60 @@
import { Column, Entity, JoinColumn, ManyToOne, ManyToMany, OneToMany, JoinTable } from "typeorm";
import { BaseEntity } from "../../../common/entities/base.entity";
import { TMTaskPhase } from "./task-phase.entity";
import { TMRemark } from "./remark.entity";
import { TMAttachment } from "./attachment.entity";
import { TMCheckListItem } from "./check-list-item.entity";
import { User } from "../../users/entities/user.entity";
@Entity("tm_tasks")
export class TMTask extends BaseEntity {
@Column({ type: "varchar", length: 150 })
title: string;
@Column({ type: "text", nullable: true })
description: string;
@Column({ type: "varchar", length: 20, nullable: true })
color: string;
@Column({ type: "timestamptz", nullable: true })
startDate: Date;
@Column({ type: "timestamptz", nullable: true })
endDate: Date;
// --- Relations ---
@ManyToOne(() => TMTaskPhase, (taskPhase) => taskPhase.tasks, {
nullable: false,
onDelete: "RESTRICT",
})
@JoinColumn({ name: "taskPhaseId" })
taskPhase: TMTaskPhase;
@Column({ type: "uuid" })
taskPhaseId: string;
@OneToMany(() => TMRemark, (remark) => remark.task, {
cascade: ["insert", "update"],
})
remarks: TMRemark[];
@OneToMany(() => TMAttachment, (attachment) => attachment.task, {
cascade: ["insert", "update"],
})
attachments: TMAttachment[];
@OneToMany(() => TMCheckListItem, (checkListItem) => checkListItem.task, {
cascade: ["insert", "update"],
})
checkListItems: TMCheckListItem[];
@ManyToMany(() => User, (user) => user.tasks)
@JoinTable({
name: "tm_task_users",
joinColumn: { name: "taskId", referencedColumnName: "id" },
inverseJoinColumn: { name: "userId", referencedColumnName: "id" },
})
users: User[];
}
@@ -0,0 +1,20 @@
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[];
}
@@ -0,0 +1,42 @@
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, 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";
@Entity("tm_workspaces")
export class TMWorkspace extends BaseEntity {
@Column({ type: "varchar", length: 100 })
name: string;
@Column({ type: "text", nullable: true })
description: string;
@Column({ type: "varchar", length: 20 })
color: string;
@Column({ type: "boolean", default: true })
isActive: boolean;
// --- 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"],
})
projects: TMProject[];
@ManyToMany(() => User, (user) => user.workspaces)
@JoinTable({
name: "tm_workspace_users",
joinColumn: { name: "workspaceId", referencedColumnName: "id" },
inverseJoinColumn: { name: "userId", referencedColumnName: "id" },
})
users: User[];
}
@@ -0,0 +1,6 @@
export enum TMAttachmentType {
FILE = "file",
LINK = "link",
IMAGE = "image",
VIDEO = "video",
}
@@ -0,0 +1,41 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { CreateWorkspaceDto } from "../dto/workspace/create-workspace.dto";
import { WorkspaceRepository } from "../repositories/workspace.repository";
import { UpdateWorkspaceDto } from "../dto/workspace/update-workspace.dto";
@Injectable()
export class WorkspaceService {
constructor(
private readonly workspaceRepository: WorkspaceRepository,
) {}
findAll() {
return this.workspaceRepository.findAll();
}
async findOne(id: string) {
const workspace = await this.workspaceRepository.findOneById(id);
if (!workspace) {
throw new NotFoundException(`Workspace #${id} not found`);
}
return workspace;
}
async create(dto: CreateWorkspaceDto) {
const workspace = this.workspaceRepository.create(dto);
return this.workspaceRepository.save(workspace);
}
async update(id: string, dto: UpdateWorkspaceDto) {
await this.findOne(id);
await this.workspaceRepository.update(id, dto);
return this.findOne(id);
}
async remove(id: string) {
await this.findOne(id);
await this.workspaceRepository.delete(id);
}
}
@@ -0,0 +1,41 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { TMWorkspace } from "../entities/workspace.entity";
@Injectable()
export class WorkspaceRepository {
constructor(
@InjectRepository(TMWorkspace)
private readonly repository: Repository<TMWorkspace>,
) {}
findAll() {
return this.repository.find({
relations: ["workspaceType", "projects", "users"],
});
}
findOneById(id: string) {
return this.repository.findOne({
where: { id },
relations: ["workspaceType", "projects", "users"],
});
}
create(data: Partial<TMWorkspace>) {
return this.repository.create(data);
}
save(workspace: TMWorkspace) {
return this.repository.save(workspace);
}
update(id: string, data: Partial<TMWorkspace>) {
return this.repository.update(id, data);
}
delete(id: string) {
return this.repository.delete(id);
}
}
@@ -0,0 +1,38 @@
import { Controller, Get, Post, Patch, Delete, Param, Body } from '@nestjs/common';
import { TMWorkspace } from './entities/workspace.entity';
import { WorkspaceService } from './providers/workspace.service';
import { CreateWorkspaceDto } from './dto/workspace/create-workspace.dto';
import { UpdateWorkspaceDto } from './dto/workspace/update-workspace.dto';
@Controller('task-manager')
export class TaskManagerController {
constructor(
private readonly workspaceService: WorkspaceService,
) {}
// --- Workspace ---
@Get('workspaces')
findAllWorkspaces(): Promise<TMWorkspace[]> {
return this.workspaceService.findAll();
}
@Get('workspaces/:id')
findOneWorkspace(@Param('id') id: string): Promise<TMWorkspace> {
return this.workspaceService.findOne(id);
}
@Post('workspaces')
createWorkspace(@Body() body: CreateWorkspaceDto): Promise<TMWorkspace> {
return this.workspaceService.create(body);
}
@Patch('workspaces/:id')
updateWorkspace(@Param('id') id: string, @Body() body: UpdateWorkspaceDto): Promise<TMWorkspace> {
return this.workspaceService.update(id, body);
}
@Delete('workspaces/:id')
removeWorkspace(@Param('id') id: string): Promise<void> {
return this.workspaceService.remove(id);
}
}
@@ -0,0 +1,51 @@
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';
import { TMTask } from './entities/task.entity';
import { TMRemark } from './entities/remark.entity';
import { TMAttachment } from './entities/attachment.entity';
import { TMCheckListItem } from './entities/check-list-item.entity';
import { WorkspaceRepository } from './repositories/workspace.repository';
import { TaskManagerController } from './task-manager.controller';
import { WorkspaceService } from './providers/workspace.service';
// import { WorkspaceTypeService } from './providers/workspace-type.service';
// import { WorkspaceService } from './providers/workspace.service';
// import { ProjectService } from './providers/project.service';
// import { TaskPhaseService } from './providers/task-phase.service';
// import { TaskService } from './providers/task.service';
// import { TaskManagerController } from './task-manager.controller';
@Module({
imports: [
TypeOrmModule.forFeature([
TMWorkspaceType,
TMWorkspace,
TMProject,
TMTaskPhase,
TMTask,
TMRemark,
TMAttachment,
TMCheckListItem,
]),
],
controllers: [TaskManagerController],
providers: [
WorkspaceRepository,
WorkspaceService,
// WorkspaceTypeService,
// ProjectService,
// TaskPhaseService,
// TaskService,
],
exports: [
WorkspaceService,
WorkspaceRepository
],
})
export class TaskManagerModule {}
+13 -5
View File
@@ -32,6 +32,8 @@ import { Wallet } from "../../wallets/entities/wallet.entity";
import { FinancialType } from "../enums/financial-type.enum";
import { Reseller } from "../../reseller/entities/reseller.entity";
import { UserBankAccount } from "../../reseller/entities/user-bank-account.entity";
import { TMWorkspace } from "../../task-manager/entities/workspace.entity";
import { TMTask } from "../../task-manager/entities/task.entity";
@Entity()
export class User extends BaseEntity {
@@ -167,14 +169,20 @@ export class User extends BaseEntity {
//---------------------------------------
@ManyToOne(() => Reseller, (reseller) => reseller.agents, { nullable: true })
reseller?: Reseller
reseller?: Reseller;
@OneToOne(() => Reseller, reseller => reseller.owner, { nullable: true })
ownedReseller?: Reseller
@OneToOne(() => Reseller, (reseller) => reseller.owner, { nullable: true })
ownedReseller?: Reseller;
//------------------------
@OneToOne(() => UserBankAccount, (account) => account.user, { nullable: true })
bankAckount: UserBankAccount
bankAckount: UserBankAccount;
// -----------------------
@ManyToMany(() => TMWorkspace, (workspace) => workspace.users)
workspaces: TMWorkspace[];
@ManyToMany(() => TMTask, (task) => task.users)
tasks: TMTask[];
}
+2
View File
@@ -28,6 +28,7 @@ import { AdminsService } from "./providers/admins.service";
import { CustomersService } from "./providers/customers.service";
import { RefreshTokensRepository } from "./repositories/refresh-token.repository";
import { ReferralsModule } from "../referrals/referrals.module";
import { TaskManagerModule } from "../task-manager/task-manager.module";
@Module({
@@ -38,6 +39,7 @@ import { ReferralsModule } from "../referrals/referrals.module";
AddressModule,
ReferralsModule,
AccessLogsModule,
TaskManagerModule
],
providers: [
UsersService,