refactor: refactored remark entirely
This commit is contained in:
@@ -941,4 +941,8 @@ export const enum TaskMessage {
|
|||||||
TASK_NOT_FOUND = "تسک مورد نظر پیدا نشد!",
|
TASK_NOT_FOUND = "تسک مورد نظر پیدا نشد!",
|
||||||
USERS_ASSIGNED_TO_TASK_NOT_PROJECT_MEMBER = "حداقل یکی از کاربران تعیین شده عضو پروژه نیستند!",
|
USERS_ASSIGNED_TO_TASK_NOT_PROJECT_MEMBER = "حداقل یکی از کاربران تعیین شده عضو پروژه نیستند!",
|
||||||
USER_NOT_TASK_MEMBER = "شما عضو این تسک نیستید!"
|
USER_NOT_TASK_MEMBER = "شما عضو این تسک نیستید!"
|
||||||
|
}
|
||||||
|
|
||||||
|
export const enum remarkMessage {
|
||||||
|
REMARK_NOT_FOUND = "برچسب مورد نظر پیدا نشد!"
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,14 @@ import { RemarkService } from "../providers/remark.service";
|
|||||||
import { CreateRemarkDto } from "../dto/remark/create-remark.dto";
|
import { CreateRemarkDto } from "../dto/remark/create-remark.dto";
|
||||||
import { UpdateRemarkDto } from "../dto/remark/update-remark.dto";
|
import { UpdateRemarkDto } from "../dto/remark/update-remark.dto";
|
||||||
import { TMRemark } from "../entities/remark.entity";
|
import { TMRemark } from "../entities/remark.entity";
|
||||||
|
import { AuthGuards } from "../../../common/decorators/auth-guard.decorator";
|
||||||
|
import { AdminRoute } from "../../../common/decorators/admin.decorator";
|
||||||
|
import { PermissionsDec } from "../../../common/decorators/permission.decorator";
|
||||||
|
import { PermissionEnum } from "../../users/enums/permission.enum";
|
||||||
|
|
||||||
|
@AuthGuards()
|
||||||
|
@AdminRoute()
|
||||||
|
@PermissionsDec(PermissionEnum.REMARK)
|
||||||
@ApiTags("Task Manager - Remarks")
|
@ApiTags("Task Manager - Remarks")
|
||||||
@Controller("task-manager/remarks")
|
@Controller("task-manager/remarks")
|
||||||
export class RemarkController {
|
export class RemarkController {
|
||||||
@@ -25,7 +32,7 @@ export class RemarkController {
|
|||||||
@ApiResponse({ status: 200, description: "Remark found", type: TMRemark })
|
@ApiResponse({ status: 200, description: "Remark found", type: TMRemark })
|
||||||
@ApiResponse({ status: 404, description: "Remark not found" })
|
@ApiResponse({ status: 404, description: "Remark not found" })
|
||||||
findOne(@Param("id") id: string): Promise<TMRemark> {
|
findOne(@Param("id") id: string): Promise<TMRemark> {
|
||||||
return this.remarkService.findOne(id);
|
return this.remarkService.findOneOrFail(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
|||||||
@@ -1,45 +1,49 @@
|
|||||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||||
import { RemarkRepository } from "../repositories/remark.repository";
|
import { RemarkRepository } from "../repositories/remark.repository";
|
||||||
import { TaskRepository } from "../repositories/task.repository";
|
|
||||||
import { TMRemark } from "../entities/remark.entity";
|
import { TMRemark } from "../entities/remark.entity";
|
||||||
import { CreateRemarkDto } from "../dto/remark/create-remark.dto";
|
import { CreateRemarkDto } from "../dto/remark/create-remark.dto";
|
||||||
import { UpdateRemarkDto } from "../dto/remark/update-remark.dto";
|
import { UpdateRemarkDto } from "../dto/remark/update-remark.dto";
|
||||||
|
import { remarkMessage } from "../../../common/enums/message.enum";
|
||||||
|
import { TaskService } from './task.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RemarkService {
|
export class RemarkService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly remarkRepository: RemarkRepository,
|
private readonly remarkRepository: RemarkRepository,
|
||||||
private readonly taskRepository: TaskRepository,
|
private readonly taskService: TaskService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
findAll(): Promise<TMRemark[]> {
|
findAll(): Promise<TMRemark[]> {
|
||||||
return this.remarkRepository.findAll();
|
return this.remarkRepository.find({ relations: { task: true } });
|
||||||
}
|
}
|
||||||
|
|
||||||
findByTask(taskId: string): Promise<TMRemark[]> {
|
findByTask(taskId: string): Promise<TMRemark[]> {
|
||||||
return this.remarkRepository.findByTask(taskId);
|
return this.remarkRepository.find({
|
||||||
|
where: { taskId },
|
||||||
|
relations: {
|
||||||
|
task: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string): Promise<TMRemark> {
|
async findOneOrFail(id: string): Promise<TMRemark> {
|
||||||
const remark = await this.remarkRepository.findOneById(id);
|
const remark = await this.remarkRepository.findOne({ where: { id } });
|
||||||
if (!remark) throw new NotFoundException(`Remark #${id} not found`);
|
if (!remark) throw new NotFoundException(remarkMessage.REMARK_NOT_FOUND);
|
||||||
return remark;
|
return remark;
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(dto: CreateRemarkDto): Promise<TMRemark> {
|
async create(dto: CreateRemarkDto): Promise<TMRemark> {
|
||||||
const task = await this.taskRepository.findOneById(dto.taskId);
|
await this.taskService.findOneOrFail(dto.taskId);
|
||||||
if (!task) throw new NotFoundException(`Task #${dto.taskId} not found`);
|
|
||||||
|
|
||||||
const remark = this.remarkRepository.create(dto);
|
const remark = this.remarkRepository.create(dto);
|
||||||
return this.remarkRepository.save(remark);
|
return this.remarkRepository.save(remark);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, dto: UpdateRemarkDto): Promise<TMRemark> {
|
async update(id: string, dto: UpdateRemarkDto): Promise<TMRemark> {
|
||||||
const remark = await this.findOne(id);
|
const remark = await this.findOneOrFail(id);
|
||||||
|
|
||||||
if (dto.taskId) {
|
if (dto.taskId) {
|
||||||
const task = await this.taskRepository.findOneById(dto.taskId);
|
await this.taskService.findOneOrFail(dto.taskId);
|
||||||
if (!task) throw new NotFoundException(`Task #${dto.taskId} not found`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(remark, dto);
|
Object.assign(remark, dto);
|
||||||
@@ -47,7 +51,7 @@ export class RemarkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string): Promise<void> {
|
async remove(id: string): Promise<void> {
|
||||||
await this.findOne(id);
|
await this.findOneOrFail(id);
|
||||||
await this.remarkRepository.delete(id);
|
await this.remarkRepository.delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,44 +4,10 @@ import { Repository } from "typeorm";
|
|||||||
import { TMRemark } from "../entities/remark.entity";
|
import { TMRemark } from "../entities/remark.entity";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RemarkRepository {
|
export class RemarkRepository extends Repository<TMRemark>{
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(TMRemark)
|
@InjectRepository(TMRemark) remarkRepository: Repository<TMRemark>,
|
||||||
private readonly repository: Repository<TMRemark>,
|
) {
|
||||||
) {}
|
super(remarkRepository.target, remarkRepository.manager, remarkRepository.queryRunner);
|
||||||
|
|
||||||
findAll() {
|
|
||||||
return this.repository.find({
|
|
||||||
relations: ["task"],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
findByTask(taskId: string) {
|
|
||||||
return this.repository.find({
|
|
||||||
where: { taskId },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
findOneById(id: string) {
|
|
||||||
return this.repository.findOne({
|
|
||||||
where: { id },
|
|
||||||
relations: ["task"],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
create(data: Partial<TMRemark>) {
|
|
||||||
return this.repository.create(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
save(remark: TMRemark) {
|
|
||||||
return this.repository.save(remark);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(id: string, data: Partial<TMRemark>) {
|
|
||||||
return this.repository.update(id, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(id: string) {
|
|
||||||
return this.repository.delete(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,5 +28,6 @@ export enum PermissionEnum {
|
|||||||
WORKSPACE="workspace",
|
WORKSPACE="workspace",
|
||||||
PROJECT="project",
|
PROJECT="project",
|
||||||
TASK_PHASE="task_phase",
|
TASK_PHASE="task_phase",
|
||||||
TASK="task"
|
TASK="task",
|
||||||
|
REMARK="remark"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user