feat: added cursor-based pagination to checklistitems

This commit is contained in:
2026-07-04 10:14:33 +03:30
parent c22a41d29b
commit 06ec73be92
6 changed files with 142 additions and 55 deletions
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Repository, MoreThan } from 'typeorm';
import { TMCheckListItem } from '../entities/check-list-item.entity';
@Injectable()
@@ -10,15 +10,23 @@ export class CheckListItemRepository {
private readonly repository: Repository<TMCheckListItem>,
) {}
findAll() {
return this.repository.find({
findAll(limit: number, cursor?: Date) {
return this.repository.findAndCount({
where: cursor ? { createdAt: MoreThan(cursor) } : {},
order: { createdAt: 'ASC' },
take: limit + 1,
relations: ['task'],
});
}
findByTask(taskId: string) {
return this.repository.find({
where: { taskId },
findByTask(taskId: string, limit: number, cursor?: Date) {
return this.repository.findAndCount({
where: cursor
? { taskId, createdAt: MoreThan(cursor) }
: { taskId },
order: { createdAt: 'ASC' },
take: limit + 1,
relations: ['task'],
});
}
@@ -29,6 +37,13 @@ export class CheckListItemRepository {
});
}
findOneByCreatedAt(createdAt: Date) {
return this.repository.findOne({
where: { createdAt },
order: { createdAt: 'ASC' },
});
}
create(data: Partial<TMCheckListItem>) {
return this.repository.create(data);
}