refactor: removed unnecessary functions from remark
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from "@nestjs/common";
|
import { Controller, Post, Patch, Delete, Param, Body } from "@nestjs/common";
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from "@nestjs/swagger";
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam } from "@nestjs/swagger";
|
||||||
import { RemarkService } from "../providers/remark.service";
|
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";
|
||||||
@@ -17,24 +17,6 @@ import { PermissionEnum } from "../../users/enums/permission.enum";
|
|||||||
export class RemarkController {
|
export class RemarkController {
|
||||||
constructor(private readonly remarkService: RemarkService) {}
|
constructor(private readonly remarkService: RemarkService) {}
|
||||||
|
|
||||||
@Get()
|
|
||||||
@ApiOperation({ summary: "Get all remarks, optionally filtered by task" })
|
|
||||||
@ApiQuery({ name: "taskId", required: false, description: "Filter remarks by task ID" })
|
|
||||||
@ApiResponse({ status: 200, description: "List of remarks", type: [TMRemark] })
|
|
||||||
findAll(@Query("taskId") taskId?: string): Promise<TMRemark[]> {
|
|
||||||
if (taskId) return this.remarkService.findByTask(taskId);
|
|
||||||
return this.remarkService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(":id")
|
|
||||||
@ApiOperation({ summary: "Get a remark by ID" })
|
|
||||||
@ApiParam({ name: "id", description: "Remark ID" })
|
|
||||||
@ApiResponse({ status: 200, description: "Remark found", type: TMRemark })
|
|
||||||
@ApiResponse({ status: 404, description: "Remark not found" })
|
|
||||||
findOne(@Param("id") id: string): Promise<TMRemark> {
|
|
||||||
return this.remarkService.findOneOrFail(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: "Create a new remark" })
|
@ApiOperation({ summary: "Create a new remark" })
|
||||||
@ApiResponse({ status: 201, description: "Remark created", type: TMRemark })
|
@ApiResponse({ status: 201, description: "Remark created", type: TMRemark })
|
||||||
|
|||||||
@@ -13,19 +13,6 @@ export class RemarkService {
|
|||||||
private readonly taskService: TaskService,
|
private readonly taskService: TaskService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
findAll(): Promise<TMRemark[]> {
|
|
||||||
return this.remarkRepository.find({ relations: { task: true } });
|
|
||||||
}
|
|
||||||
|
|
||||||
findByTask(taskId: string): Promise<TMRemark[]> {
|
|
||||||
return this.remarkRepository.find({
|
|
||||||
where: { taskId },
|
|
||||||
relations: {
|
|
||||||
task: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOneOrFail(id: string): Promise<TMRemark> {
|
async findOneOrFail(id: string): Promise<TMRemark> {
|
||||||
const remark = await this.remarkRepository.findOne({ where: { id } });
|
const remark = await this.remarkRepository.findOne({ where: { id } });
|
||||||
if (!remark) throw new NotFoundException(remarkMessage.REMARK_NOT_FOUND);
|
if (!remark) throw new NotFoundException(remarkMessage.REMARK_NOT_FOUND);
|
||||||
|
|||||||
Reference in New Issue
Block a user