Skip to content

Commit

Permalink
Update typing in mikro orm options mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper committed Dec 8, 2023
1 parent 37ed8c7 commit 4699e78
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apps/server/src/modules/school/repo/mikro-orm/school.repo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FindOptions } from '@mikro-orm/core';
import { AutoPath } from '@mikro-orm/core/typings';
import { EntityManager } from '@mikro-orm/mongodb';
import { Injectable } from '@nestjs/common';
import { SchoolEntity } from '@shared/domain/entity/school.entity';
Expand Down Expand Up @@ -38,13 +39,15 @@ export class SchoolMikroOrmRepo implements SchoolRepo {
return school;
}

// TODO: This should probably be a common mapper for all repos.
private mapToMikroOrmOptions(options?: IFindOptions<SchoolProps>, populate?: string[]): FindOptions<SchoolEntity> {
const findOptions: FindOptions<SchoolEntity> = {
private mapToMikroOrmOptions<P extends string = never>(
options?: IFindOptions<SchoolProps>,
populate?: AutoPath<SchoolEntity, P>[]
): FindOptions<SchoolEntity, P> {
const findOptions: FindOptions<SchoolEntity, P> = {
offset: options?.pagination?.skip,
limit: options?.pagination?.limit,
orderBy: options?.order,
populate: populate as never[],
populate,
};

// If no order is specified, a default order is applied here, because pagination can be messed up without order.
Expand Down

0 comments on commit 4699e78

Please sign in to comment.