Skip to content

Commit

Permalink
sorting mapper correction
Browse files Browse the repository at this point in the history
  • Loading branch information
MajedAlaitwniCap committed Oct 10, 2023
1 parent a58d076 commit e6ca965
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
19 changes: 10 additions & 9 deletions src/modules/person/persistence/person-sorting.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
/* eslint-disable import/extensions */
import { QueryOrderMap } from '@mikro-orm/core';
import { SortOrderMap } from '../../../shared/interface/find-options';
import { SortOrderMap, SortOrder } from '../../../shared/interface/find-options';
import { PersonDo } from '../domain/person.do';
import { PersonEntity } from './person.entity';

export class PersonSortingMapper {
static mapDOSortOrderToQueryOrder(sort: SortOrderMap<PersonDo<boolean>>): QueryOrderMap<PersonEntity> {
const queryOrderMap: SortOrderMap<PersonEntity | undefined> = {
id: sort.id,
firstName: sort.firstName,
lastName: sort.lastName,
birthDate: sort.birthDate,
const queryOrderMap: QueryOrderMap<PersonEntity> = {
id: sort ? (sort.id ? sort.id : SortOrder.asc) : SortOrder.asc,
firstName: sort ? (sort.firstName ? sort.firstName : SortOrder.asc) : SortOrder.asc,
lastName: sort ? (sort.lastName ? sort.lastName : SortOrder.asc) : SortOrder.asc,
birthDate: sort ? (sort.birthDate ? sort.birthDate : SortOrder.asc) : SortOrder.asc,
};
Object.keys(queryOrderMap)
.filter((key) => queryOrderMap[key] === undefined)
.forEach((key) => delete queryOrderMap[key]);
// ehmaliger filter von undefined funktioniert nicht
// Object.keys(queryOrderMap)
// .filter((key) => queryOrderMap[key] === undefined)
// .forEach((key) => delete queryOrderMap[key]);
return queryOrderMap;
}
}
14 changes: 0 additions & 14 deletions src/modules/person/persistence/person.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,10 @@ export class PersonRepo {
orderBy: order,
});

// if (personDo.firstName) {
// query['firstName'] = { $ilike: personDo.firstName };
// }

// if (personDo.lastName) {
// query['lastName'] = { $ilike: personDo.lastName };
// }

// if (personDo.referrer) {
// query['referrer'] = personDo.referrer;
// }

const entityDos: PersonDo<boolean>[] = entities.map((person: PersonEntity) =>
this.mapper.map(person, PersonEntity, PersonDo),
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const page: Page<PersonDo<boolean>> = new Page<PersonDo<boolean>>(entityDos, total);
// return result.map((person: PersonEntity) => this.mapper.map(person, PersonEntity, PersonDo));
return page;
}
}

0 comments on commit e6ca965

Please sign in to comment.