feat: added cursor-based pagination to checklistitems
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { CheckListItemRepository } from "../repositories/check-list-item.repository";
|
||||
import { TaskRepository } from "../repositories/task.repository";
|
||||
import { TMCheckListItem } from "../entities/check-list-item.entity";
|
||||
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 { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CheckListItemRepository } from '../repositories/check-list-item.repository';
|
||||
import { TaskRepository } from '../repositories/task.repository';
|
||||
import { TMCheckListItem } from '../entities/check-list-item.entity';
|
||||
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 { CursorPaginationDto } from '../../../common/DTO/cursor-pagination.dto';
|
||||
import { CursorPaginatedResult } from '../../../common/interfaces/cursor-paginated-result.interface';
|
||||
import { buildCursorPageFormat } from '../../../common/helpers/cursor-paginated.helper';
|
||||
|
||||
@Injectable()
|
||||
export class CheckListItemService {
|
||||
@@ -12,12 +15,25 @@ export class CheckListItemService {
|
||||
private readonly taskRepository: TaskRepository,
|
||||
) {}
|
||||
|
||||
findAll(): Promise<TMCheckListItem[]> {
|
||||
return this.checkListItemRepository.findAll();
|
||||
async findAll(pagination: CursorPaginationDto): Promise<CursorPaginatedResult<TMCheckListItem>> {
|
||||
const limit = pagination.limit ?? 10;
|
||||
const cursorDate = pagination.cursor ? new Date(pagination.cursor) : undefined;
|
||||
|
||||
const [data] = await this.checkListItemRepository.findAll(limit, cursorDate);
|
||||
|
||||
return buildCursorPageFormat(data, limit, cursorDate);
|
||||
}
|
||||
|
||||
findByTask(taskId: string): Promise<TMCheckListItem[]> {
|
||||
return this.checkListItemRepository.findByTask(taskId);
|
||||
async findByTask(
|
||||
taskId: string,
|
||||
pagination: CursorPaginationDto,
|
||||
): Promise<CursorPaginatedResult<TMCheckListItem>> {
|
||||
const limit = pagination.limit ?? 10;
|
||||
const cursorDate = pagination.cursor ? new Date(pagination.cursor) : undefined;
|
||||
|
||||
const [data] = await this.checkListItemRepository.findByTask(taskId, limit, cursorDate);
|
||||
|
||||
return buildCursorPageFormat(data, limit, cursorDate);
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<TMCheckListItem> {
|
||||
@@ -46,8 +62,9 @@ export class CheckListItemService {
|
||||
return this.checkListItemRepository.save(checkListItem);
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<void> {
|
||||
await this.findOne(id);
|
||||
async remove(id: string): Promise<TMCheckListItem> {
|
||||
const checkListItem = await this.findOne(id);
|
||||
await this.checkListItemRepository.delete(id);
|
||||
return checkListItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user