Skip to content

Commit

Permalink
refactor(org): use semver for version comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
fgravin committed Dec 2, 2023
1 parent 17b3c52 commit 7bf80eb
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { combineLatest, Observable, of, switchMap, takeLast } from 'rxjs'
import { filter, map, shareReplay, startWith, tap } from 'rxjs/operators'
import { LangService } from '@geonetwork-ui/util/i18n'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import { coerce, satisfies, valid } from 'semver'

const IMAGE_URL = '/geonetwork/images/harvesting/'

Expand Down Expand Up @@ -144,6 +145,7 @@ export class OrganizationsFromMetadataService
}

private getAggregationSearchRequest(gnVersion: string) {
const semVersion = valid(coerce(gnVersion))
return this.esService.getSearchRequestBody({
contact: {
nested: {
Expand All @@ -152,9 +154,10 @@ export class OrganizationsFromMetadataService
aggs: {
org: {
terms: {
field: gnVersion.startsWith('4.2.2')
? 'contactForResource.organisation'
: 'contactForResource.organisationObject.default.keyword',
field:
semVersion === '4.2.2'
? 'contactForResource.organisation'
: 'contactForResource.organisationObject.default.keyword',
exclude: '',
size: 5000,
order: { _key: 'asc' },
Expand All @@ -164,12 +167,9 @@ export class OrganizationsFromMetadataService
terms: {
size: 50,
exclude: '',
field:
gnVersion.startsWith('4.2.2') ||
gnVersion.startsWith('4.2.3') ||
gnVersion.startsWith('4.2.4')
? 'contactForResource.email.keyword'
: 'contactForResource.email',
field: satisfies(semVersion, '4.2.2 - 4.2.4')
? 'contactForResource.email.keyword'
: 'contactForResource.email',
},
},
logoUrl: {
Expand All @@ -187,9 +187,10 @@ export class OrganizationsFromMetadataService
terms: {
size: 5000,
exclude: '',
field: gnVersion.startsWith('4.2.2')
? 'OrgForResource'
: 'OrgForResourceObject.default',
field:
semVersion === '4.2.2'
? 'OrgForResource'
: 'OrgForResourceObject.default',
order: {
_key: 'asc',
},
Expand Down

0 comments on commit 7bf80eb

Please sign in to comment.