Skip to content

Commit

Permalink
fix(test): adding a missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodimarchi committed Dec 5, 2023
1 parent 67c8b08 commit 8f6b8ed
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/repositories/in-memory-course-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { CourseEntity } from '@modules/course/domain/entities/course/course.entity';
import { CourseRepository } from '@modules/course/domain/repositories/course.repository';
import { PaginatedEntitiesOptions } from '@shared/infra/database/interfaces/paginated-entities-options.interface.';
import { PaginatedEntities } from '@shared/infra/database/interfaces/paginated-entities.interface';
import { UUID } from 'crypto';
import { InMemoryRepository } from './in-memory-repository';

export class InMemoryCourseRepository
implements InMemoryRepository<CourseRepository, CourseEntity>
{
public items: CourseEntity[] = [];

async save(course: CourseEntity): Promise<void> {
this.items.push(course);
}

async getById(id: UUID): Promise<CourseEntity | null> {
const course = this.items.find((c) => c.id === id);

if (!course) {
return null;
}

return course;
}

async getAllPaginated(
options: PaginatedEntitiesOptions,
): Promise<PaginatedEntities<CourseEntity>> {
const take = options.pageLimit || 10;
const skip = ((options.page || 1) - 1) * take;

const entities = this.items.slice(skip, skip + take);
const totalPageCount = Math.ceil(this.items.length / take);

return {
page: options.page || 1,
pageLimit: take,
totalPageCount: totalPageCount,
entities,
};
}
}

0 comments on commit 8f6b8ed

Please sign in to comment.