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 { CursorPaginationDto } from "../../../common/DTO/cursor-pagination.dto";
|
||||
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")
|
||||
@Controller("task-manager/check-list-items")
|
||||
export class CheckListItemController {
|
||||
|
||||
@@ -19,7 +19,7 @@ export class CheckListItemService {
|
||||
const limit = pagination.limit ?? 10;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ import { Repository, MoreThan } from 'typeorm';
|
||||
import { TMCheckListItem } from '../entities/check-list-item.entity';
|
||||
|
||||
@Injectable()
|
||||
export class CheckListItemRepository {
|
||||
export class CheckListItemRepository extends Repository<TMCheckListItem>{
|
||||
constructor(
|
||||
@InjectRepository(TMCheckListItem)
|
||||
private readonly repository: Repository<TMCheckListItem>,
|
||||
) {}
|
||||
@InjectRepository(TMCheckListItem) checkListItemRepository: Repository<TMCheckListItem>,
|
||||
) {
|
||||
super(checkListItemRepository.target, checkListItemRepository.manager, checkListItemRepository.queryRunner);
|
||||
}
|
||||
|
||||
findAll(limit: number, cursor?: Date) {
|
||||
return this.repository.findAndCount({
|
||||
findAllItems(limit: number, cursor?: Date) {
|
||||
return this.findAndCount({
|
||||
where: cursor ? { createdAt: MoreThan(cursor) } : {},
|
||||
order: { createdAt: 'ASC' },
|
||||
take: limit + 1,
|
||||
@@ -20,7 +21,7 @@ export class CheckListItemRepository {
|
||||
}
|
||||
|
||||
findByTask(taskId: string, limit: number, cursor?: Date) {
|
||||
return this.repository.findAndCount({
|
||||
return this.findAndCount({
|
||||
where: cursor
|
||||
? { taskId, createdAt: MoreThan(cursor) }
|
||||
: { taskId },
|
||||
@@ -31,32 +32,16 @@ export class CheckListItemRepository {
|
||||
}
|
||||
|
||||
findOneById(id: string) {
|
||||
return this.repository.findOne({
|
||||
return this.findOne({
|
||||
where: { id },
|
||||
relations: ['task'],
|
||||
});
|
||||
}
|
||||
|
||||
findOneByCreatedAt(createdAt: Date) {
|
||||
return this.repository.findOne({
|
||||
return this.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user