refactor: making the checklistitem service to use enum messages
This commit is contained in:
@@ -947,6 +947,10 @@ export const enum remarkMessage {
|
|||||||
REMARK_NOT_FOUND = "برچسب مورد نظر پیدا نشد!"
|
REMARK_NOT_FOUND = "برچسب مورد نظر پیدا نشد!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const enum checkListItemMessage {
|
||||||
|
CHECKLISTITEM_NOT_FOUND = "آیتم چک لیست پیدا نشد!"
|
||||||
|
}
|
||||||
|
|
||||||
export const enum attachmentMessage {
|
export const enum attachmentMessage {
|
||||||
ATTACHMENT_NOT_FOUND = "ضمیمه پیدا نشد!"
|
ATTACHMENT_NOT_FOUND = "ضمیمه پیدا نشد!"
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ export class CheckListItemController {
|
|||||||
@ApiResponse({ status: 200, description: "CheckListItem found", type: TMCheckListItem })
|
@ApiResponse({ status: 200, description: "CheckListItem found", type: TMCheckListItem })
|
||||||
@ApiResponse({ status: 404, description: "CheckListItem not found" })
|
@ApiResponse({ status: 404, description: "CheckListItem not found" })
|
||||||
findOne(@Param("id") id: string): Promise<TMCheckListItem> {
|
findOne(@Param("id") id: string): Promise<TMCheckListItem> {
|
||||||
return this.checkListItemService.findOne(id);
|
return this.checkListItemService.findOneOrFail(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { CheckListItemRepository } from '../repositories/check-list-item.repository';
|
import { CheckListItemRepository } from '../repositories/check-list-item.repository';
|
||||||
import { TaskRepository } from '../repositories/task.repository';
|
|
||||||
import { TMCheckListItem } from '../entities/check-list-item.entity';
|
import { TMCheckListItem } from '../entities/check-list-item.entity';
|
||||||
import { CreateCheckListItemDto } from '../dto/check-list-item/create-check-list-item.dto';
|
import { CreateCheckListItemDto } from '../dto/check-list-item/create-check-list-item.dto';
|
||||||
import { UpdateCheckListItemDto } from '../dto/check-list-item/update-check-list-item.dto';
|
import { UpdateCheckListItemDto } from '../dto/check-list-item/update-check-list-item.dto';
|
||||||
import { CursorPaginationDto } from '../../../common/DTO/cursor-pagination.dto';
|
import { CursorPaginationDto } from '../../../common/DTO/cursor-pagination.dto';
|
||||||
import { CursorPaginatedResult } from '../../../common/interfaces/cursor-paginated-result.interface';
|
import { CursorPaginatedResult } from '../../../common/interfaces/cursor-paginated-result.interface';
|
||||||
import { buildCursorPageFormat } from '../../../common/helpers/cursor-paginated.helper';
|
import { buildCursorPageFormat } from '../../../common/helpers/cursor-paginated.helper';
|
||||||
|
import { checkListItemMessage } from '../../../common/enums/message.enum';
|
||||||
|
import { TaskService } from './task.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CheckListItemService {
|
export class CheckListItemService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly checkListItemRepository: CheckListItemRepository,
|
private readonly checkListItemRepository: CheckListItemRepository,
|
||||||
private readonly taskRepository: TaskRepository,
|
private readonly taskService: TaskService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findAll(pagination: CursorPaginationDto): Promise<CursorPaginatedResult<TMCheckListItem>> {
|
async findAll(pagination: CursorPaginationDto): Promise<CursorPaginatedResult<TMCheckListItem>> {
|
||||||
@@ -36,26 +37,24 @@ export class CheckListItemService {
|
|||||||
return buildCursorPageFormat(data, limit, cursorDate);
|
return buildCursorPageFormat(data, limit, cursorDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string): Promise<TMCheckListItem> {
|
async findOneOrFail(id: string): Promise<TMCheckListItem> {
|
||||||
const checkListItem = await this.checkListItemRepository.findOneById(id);
|
const checkListItem = await this.checkListItemRepository.findOneById(id);
|
||||||
if (!checkListItem) throw new NotFoundException(`CheckListItem #${id} not found`);
|
if (!checkListItem) throw new NotFoundException(checkListItemMessage.CHECKLISTITEM_NOT_FOUND);
|
||||||
return checkListItem;
|
return checkListItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(dto: CreateCheckListItemDto): Promise<TMCheckListItem> {
|
async create(dto: CreateCheckListItemDto): Promise<TMCheckListItem> {
|
||||||
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 checkListItem = this.checkListItemRepository.create(dto);
|
const checkListItem = this.checkListItemRepository.create(dto);
|
||||||
return this.checkListItemRepository.save(checkListItem);
|
return this.checkListItemRepository.save(checkListItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, dto: UpdateCheckListItemDto): Promise<TMCheckListItem> {
|
async update(id: string, dto: UpdateCheckListItemDto): Promise<TMCheckListItem> {
|
||||||
const checkListItem = await this.findOne(id);
|
const checkListItem = 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(checkListItem, dto);
|
Object.assign(checkListItem, dto);
|
||||||
@@ -63,7 +62,7 @@ export class CheckListItemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string): Promise<TMCheckListItem> {
|
async remove(id: string): Promise<TMCheckListItem> {
|
||||||
const checkListItem = await this.findOne(id);
|
const checkListItem = await this.findOneOrFail(id);
|
||||||
await this.checkListItemRepository.delete(id);
|
await this.checkListItemRepository.delete(id);
|
||||||
return checkListItem;
|
return checkListItem;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user