From e6ca965cb0e0f2442cc3fa4bfae861e94f01fd2d Mon Sep 17 00:00:00 2001 From: MajedAlaitwniCap Date: Tue, 10 Oct 2023 14:03:25 +0200 Subject: [PATCH] sorting mapper correction --- .../persistence/person-sorting.mapper.ts | 19 ++++++++++--------- src/modules/person/persistence/person.repo.ts | 14 -------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/modules/person/persistence/person-sorting.mapper.ts b/src/modules/person/persistence/person-sorting.mapper.ts index 1d9b6b8cd..4d0e5500a 100644 --- a/src/modules/person/persistence/person-sorting.mapper.ts +++ b/src/modules/person/persistence/person-sorting.mapper.ts @@ -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>): QueryOrderMap { - const queryOrderMap: SortOrderMap = { - id: sort.id, - firstName: sort.firstName, - lastName: sort.lastName, - birthDate: sort.birthDate, + const queryOrderMap: QueryOrderMap = { + 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; } } diff --git a/src/modules/person/persistence/person.repo.ts b/src/modules/person/persistence/person.repo.ts index 413734da7..415b261de 100644 --- a/src/modules/person/persistence/person.repo.ts +++ b/src/modules/person/persistence/person.repo.ts @@ -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[] = entities.map((person: PersonEntity) => this.mapper.map(person, PersonEntity, PersonDo), ); - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const page: Page> = new Page>(entityDos, total); - // return result.map((person: PersonEntity) => this.mapper.map(person, PersonEntity, PersonDo)); return page; } }