Files
dsc-api/src/modules/task-manager/repositories/check-list-item.repository.ts
T

62 lines
1.5 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, MoreThan } from 'typeorm';
import { TMCheckListItem } from '../entities/check-list-item.entity';
@Injectable()
export class CheckListItemRepository {
constructor(
@InjectRepository(TMCheckListItem)
private readonly repository: Repository<TMCheckListItem>,
) {}
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, limit: number, cursor?: Date) {
return this.repository.findAndCount({
where: cursor
? { taskId, createdAt: MoreThan(cursor) }
: { taskId },
order: { createdAt: 'ASC' },
take: limit + 1,
relations: ['task'],
});
}
findOneById(id: string) {
return this.repository.findOne({
where: { id },
relations: ['task'],
});
}
findOneByCreatedAt(createdAt: Date) {
return this.repository.findOne({
where: { createdAt },
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);
}
}