refactor: refactored the checkListItem
This commit is contained in:
@@ -5,7 +5,11 @@ import { CreateCheckListItemDto } from "../dto/check-list-item/create-check-list
|
|||||||
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 { TMCheckListItem } from "../entities/check-list-item.entity";
|
import { TMCheckListItem } from "../entities/check-list-item.entity";
|
||||||
|
import { AuthGuards } from "../../../common/decorators/auth-guard.decorator";
|
||||||
|
import { AdminRoute } from "../../../common/decorators/admin.decorator";
|
||||||
|
|
||||||
|
@AuthGuards()
|
||||||
|
@AdminRoute()
|
||||||
@ApiTags("Task Manager - Check List Items")
|
@ApiTags("Task Manager - Check List Items")
|
||||||
@Controller("task-manager/check-list-items")
|
@Controller("task-manager/check-list-items")
|
||||||
export class CheckListItemController {
|
export class CheckListItemController {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class CheckListItemService {
|
|||||||
const limit = pagination.limit ?? 10;
|
const limit = pagination.limit ?? 10;
|
||||||
const cursorDate = pagination.cursor ? new Date(pagination.cursor) : undefined;
|
const cursorDate = pagination.cursor ? new Date(pagination.cursor) : undefined;
|
||||||
|
|
||||||
const [data] = await this.checkListItemRepository.findAll(limit, cursorDate);
|
const [data] = await this.checkListItemRepository.findAllItems(limit, cursorDate);
|
||||||
|
|
||||||
return buildCursorPageFormat(data, limit, cursorDate);
|
return buildCursorPageFormat(data, limit, cursorDate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import { Repository, MoreThan } from 'typeorm';
|
|||||||
import { TMCheckListItem } from '../entities/check-list-item.entity';
|
import { TMCheckListItem } from '../entities/check-list-item.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CheckListItemRepository {
|
export class CheckListItemRepository extends Repository<TMCheckListItem>{
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(TMCheckListItem)
|
@InjectRepository(TMCheckListItem) checkListItemRepository: Repository<TMCheckListItem>,
|
||||||
private readonly repository: Repository<TMCheckListItem>,
|
) {
|
||||||
) {}
|
super(checkListItemRepository.target, checkListItemRepository.manager, checkListItemRepository.queryRunner);
|
||||||
|
}
|
||||||
|
|
||||||
findAll(limit: number, cursor?: Date) {
|
findAllItems(limit: number, cursor?: Date) {
|
||||||
return this.repository.findAndCount({
|
return this.findAndCount({
|
||||||
where: cursor ? { createdAt: MoreThan(cursor) } : {},
|
where: cursor ? { createdAt: MoreThan(cursor) } : {},
|
||||||
order: { createdAt: 'ASC' },
|
order: { createdAt: 'ASC' },
|
||||||
take: limit + 1,
|
take: limit + 1,
|
||||||
@@ -20,7 +21,7 @@ export class CheckListItemRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findByTask(taskId: string, limit: number, cursor?: Date) {
|
findByTask(taskId: string, limit: number, cursor?: Date) {
|
||||||
return this.repository.findAndCount({
|
return this.findAndCount({
|
||||||
where: cursor
|
where: cursor
|
||||||
? { taskId, createdAt: MoreThan(cursor) }
|
? { taskId, createdAt: MoreThan(cursor) }
|
||||||
: { taskId },
|
: { taskId },
|
||||||
@@ -31,32 +32,16 @@ export class CheckListItemRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findOneById(id: string) {
|
findOneById(id: string) {
|
||||||
return this.repository.findOne({
|
return this.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: ['task'],
|
relations: ['task'],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findOneByCreatedAt(createdAt: Date) {
|
findOneByCreatedAt(createdAt: Date) {
|
||||||
return this.repository.findOne({
|
return this.findOne({
|
||||||
where: { createdAt },
|
where: { createdAt },
|
||||||
order: { createdAt: 'ASC' },
|
order: { createdAt: 'ASC' },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
create(data: Partial<TMCheckListItem>) {
|
|
||||||
return this.repository.create(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
save(checkListItem: TMCheckListItem) {
|
|
||||||
return this.repository.save(checkListItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(id: string, data: Partial<TMCheckListItem>) {
|
|
||||||
return this.repository.update(id, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(id: string) {
|
|
||||||
return this.repository.delete(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user